连接到运行IPv4的服务器时延迟很长

时间:2020-04-23 08:40:20

标签: node.js grpc grpc-node

我正在从NodeJS连接到通过IPv4运行的gRPC服务器。我使用格式#syslog config destination security_oms { udp("127.0.0.1" port(25226)); }; and then create security events configuration file #oms config #/etc/opt/microsoft/omsagent/<workspace id>/conf/omsagent.d/ <source> type syslog port 25226 bind 127.0.0.1 protocol_type tcp tag oms.security format /(?<time>(?:\w+ +){2,3}(?:\d+:){2}\d+|\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.[\w\-\:\+]{3,12}):?\s*(?:(?<host>[^: ]+) ?:?)?\s*(?<ident>.*CEF.+?(?=0\|)|%ASA[0-9\-]{8,10})\s*:?(?<message>0\|.*|.*)/ <parse> message_format auto </parse> </source> <filter oms.security.**> type filter_syslog_security </filter> (而不是 --- title: "page" author: "me" date: "26/02/2020" output: html_document: toc: yes toc_depth: 3 toc_float: collapsed: yes smooth_scroll: yes word_document: default --- <style type="text/css"> body{ /* Normal */ font-size: 14px; } td { /* Table */ font-size: 12px; } h1.title { font-size: 38px; color: DarkRed; } h1 { /* Header 1 */ font-size: 28px; color: DarkBlue; } h2 { /* Header 2 */ font-size: 22px; color: DarkBlue; } h3 { /* Header 3 */ font-size: 18px; font-family: "Times New Roman", Times, serif; color: DarkBlue; } code.r{ /* Code block */ font-size: 12px; } pre { /* Code block - determines code spacing between lines */ font-size: 12px; } </style> <style type="text/css"> #TOC { margin: 25px 0px 20px 0px; } @media (max-width: 768px) { #TOC { position: relative; width: 100%; } } .toc-content { padding-left: 30px; padding-right: 40px; } div.main-container { max-width: 1200px; } div.tocify { width: 20%; max-width: 260px; max-height: 85%; } @media (min-width: 768px) and (max-width: 991px) { div.tocify { width: 25%; } } @media (max-width: 767px) { div.tocify { width: 100%; max-width: none; } } .tocify ul, .tocify li { line-height: 20px; } .tocify-subheader .tocify-item { font-size: 1.00em; padding-left: 25px; text-indent: 0; } .tocify .list-group-item { border-radius: 0px; } </style> ```{r setup, include=FALSE} knitr::opts_chunk$set( echo = TRUE, message = FALSE, warning = FALSE, comment = "##", tidy = TRUE ) ``` ```{css,echo=FALSE} button.btn.collapsed { display:block; } button.btn:not(.collapsed):before { } .hljs-comment { color: #000000; } ``` )的地址创建gRPC客户端。服务器和客户端之间的通信使用SSL加密,因此在创建客户端时无法用ipv4address替换FQDN。在解析端点地址期间,我收到4个地址(因为我有2个网络接口):

<FQDN>:<port>

解析器尝试解析首选IPv6的终结点地址:

<ipv4address>:<port>

如您所见,每次绑定的尝试都会导致1秒钟的延迟,在我的环境中,这会导致2秒钟的延迟,然后再创建客户通道。

是否可以配置解析器以使其偏爱IPv4地址,或者以某种方式减少此超时?

1 个答案:

答案 0 :(得分:0)

gRPC小组Michael Lumishhere提出了一种解决方案:

与这两个库一起使用的另一个选项是使用循环负载平衡策略。这将立即开始连接到每个后端地址,并周期性地向与其连接的所有后端地址发送请求。您可以通过设置"grpc.service_config"客户端构造参数来启用该功能。它的值是service config对象的字符串化JSON表示形式。看起来像这样:

const serviceConfig = {
    "loadBalancingConfig": [ { "round_robin": {} } ]
};
const options = {
    'grpc.service_config': JSON.stringify(serviceConfig),
    // plus any other options you are using
}
const client = new ClientClass(target, credentials, options);
相关问题