查看gRPC Java文档-ManagedChannelBuilder,有两种方法可以管理连接。 似乎idleTimeout()是默认/首选配置。但是,当我尝试搜索比较时,大多数帖子都在谈论keepAlive选项。
我很好奇这两种选择的普遍做法以及利弊?
Set the duration without ongoing RPCs before going to idle mode.
In idle mode the channel shuts down all connections, the NameResolver and the LoadBalancer. A new RPC would take the channel out of idle mode. A channel starts in idle mode. Defaults to 30 minutes.
This is an advisory option. Do not rely on any specific behavior related to this option.
Sets whether keepalive will be performed when there are no outstanding RPC on a connection. Defaults to false.
Clients must receive permission from the service owner before enabling this option. Keepalives on unused connections can easilly accidentally consume a considerable amount of bandwidth and CPU. idleTimeout() should generally be used instead of this option.
答案 0 :(得分:1)
使用keepalive可以在进行RPC时注意到连接失败。使用idleTimeout释放资源并防止空闲的TCP连接在未使用通道时断开。
idleTimeout比keepAliveWithoutCalls更可取,因为它可以减少系统的总体负载。当您愿意花费客户端,服务器和网络资源以减少很少使用的RPC的延迟时,可以使用keepAliveWithoutCalls。