You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by GitBox <gi...@apache.org> on 2022/08/20 18:06:10 UTC

[GitHub] [incubator-brpc] zyearn commented on issue #1895: Support TCP heartbeat to support the case that brpc client unaware of servers' down

zyearn commented on issue #1895:
URL: https://github.com/apache/incubator-brpc/issues/1895#issuecomment-1221378212

   > 可以通过给客户端socket设置SO_KEEPALIVE参数来实现。开启keepalive操作系统会来探活然后关闭已经断开的socket。
   > 
   > ```c++
   >     if (setsockopt(client_fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) < 0) {
   >        ...
   >     }
   > ```
   > 
   > 对代码侵入性比较小。另外可以把把TCP_KEEPIDLE、TCP_KEEPINTVL、TCP_KEEPCNT三个socket选项的值提供给Channel设置。 让用户自定义探活动时间
   > 
   > ```c++
   >     if (setsockopt(client_fd, IPPROTO_TCP, TCP_KEEPIDLE, &val1, sizeof(val1)) < 0) {
   >         ... 
   >     }
   >     if (setsockopt(cliend_fd, IPPROTO_TCP, TCP_KEEPINTVL, &val2, sizeof(val2)) < 0) {
   >         ...
   >     }
   >     if (setsockopt(, IPPROTO_TCP, TCP_KEEPCNT, &val3, sizeof(val3)) < 0) {
   >         ...
   >     }
   > ```
   > 
   > 不设置的时候会走系统中对应的配置:
   > 
   > ```shell
   > cat /proc/sys/net/ipv4/tcp_keepalive_time
   > 7200
   > 
   > cat /proc/sys/net/ipv4/tcp_keepalive_intvl
   > 75
   > 
   > cat /proc/sys/net/ipv4/tcp_keepalive_probes
   > 9
   > ```
   > 
   > 2个小时以后会被操作系统关闭。
   
   嗯是这个思路。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org