redis.conf详解之tcp-keepalive

redis.conf详解之tcp-keepalive

2023年7月23日发(作者:)

详解之tcp-keepalive⽤法单位秒tcp-keepalive 300

⽤途在linux系统中,客户端发送的最后⼀个数据包与redis发送的第⼀个保活探测报⽂之间的时间间隔。单位是秒。

注意事项-keepalive只在linux⽣效,在其他系统不⽣效(⽐如mac),只按照其他系统内核⾃⾝的设置。ive在linux系统中只控制tcp_keepalive_time选项。

linux保活定时器相关参数cat /proc/sys/net/ipv4/tcp_keepalive_time

cat /proc/sys/net/ipv4/tcp_keepalive_intvl KeepAlive探测包的发送间隔,默认值为75scat /proc/sys/net/ipv4/tcp_keepalive_probes 收不到响应,共计发⼏次。

mac系统测试结论:与是否设置tcp-keepalive毫⽆关系设置mac内核参数le为3秒sudo sysctl -w le=3000redis获取tcp-keepalive配置(300s),并不在发送任何请求。127.0.0.1:6379> config get tcp-keepalive1) "tcp-keepalive"2) "300"观察tcp情况,发现每隔3~4秒探测⼀次(客户端未关闭,所以每次都得到响应),tcp-keepalive未⽣效。$ sudo tcpdump -i lo0 port 637918:07:24.933364 IP localhost.6379 > localhost.63787: Flags [.], ack 1, win 6378, length 018:07:24.933382 IP localhost.63787 > localhost.6379: Flags [.], ack 1, win 6378, length 018:07:24.933427 IP localhost.63787 > localhost.6379: Flags [.], ack 1, win 6378, options [nop,nop,TS val 2931790987 ecr 2245109217], length 018:07:24.933436 IP localhost.6379 > localhost.63787: Flags [.], ack 1, win 6378, options [nop,nop,TS val 2245112230 ecr 2931787974], length 018:07:28.040568 IP localhost.6379 > localhost.63787: Flags [.], ack 1, win 6378, length 018:07:28.040577 IP localhost.63787 > localhost.6379: Flags [.], ack 1, win 6378, length 018:07:28.040592 IP localhost.63787 > localhost.6379: Flags [.], ack 1, win 6378, options [nop,nop,TS val 2931794047 ecr 2245112230], length 018:07:28.040596 IP localhost.6379 > localhost.63787: Flags [.], ack 1, win 6378, options [nop,nop,TS val 2245115290 ecr 2931790987], length 018:07:31.105544 IP localhost.6379 > localhost.63787: Flags [.], ack 1, win 6378, length 018:07:31.105571 IP localhost.63787 > localhost.6379: Flags [.], ack 1, win 6378, length 018:07:31.105592 IP localhost.63787 > localhost.6379: Flags [.], ack 1, win 6378, options [nop,nop,TS val 2931797050 ecr 2245115290], length 018:07:31.105603 IP localhost.6379 > localhost.63787: Flags [.], ack 1, win 6378, options [nop,nop,TS val 2245118293 ecr 2931794047], length 0

linux系统测试结论:redis的tcp-keepalive覆盖了linux的tcp_keepalive_time(默认是2⼩时)redis获取tcp-keepalive配置(6s),并不在发送任何请求。127.0.0.1:6379> config get tcp-keepalive1) "tcp-keepalive"2) "6"观察tcp情况,发现每隔6秒探测⼀次(客户端未关闭,所以每次都得到响应),$ sudo tcpdump -i lo0 port 6379tcp-keepalive⽣效了!13:50:42.731182 IP localhost.41692 > : Flags [P.], seq 18:63, ack 11469, win 512, options [nop,nop,TS val 4084903638 ecr 4084900541], length 45: RESP "co13:50:42.731243 IP > localhost.41692: Flags [.], ack 63, win 512, options [nop,nop,TS val 4084903638 ecr 4084903638], length 013:50:42.731471 IP > localhost.41692: Flags [P.], seq 11469:11500, ack 63, win 512, options [nop,nop,TS val 4084903638 ecr 4084903638], length 31: RESP13:50:42.731538 IP localhost.41692 > : Flags [.], ack 11500, win 512, options [nop,nop,TS val 4084903638 ecr 4084903638], length 013:50:48.759844 IP > localhost.41692: Flags [.], ack 63, win 512, options [nop,nop,TS val 4084909667 ecr 4084903638], length 013:50:48.759896 IP localhost.41692 > : Flags [.], ack 11500, win 512, options [nop,nop,TS val 4084909667 ecr 4084903638], length 013:50:54.742957 IP > localhost.41692: Flags [.], ack 63, win 512, options [nop,nop,TS val 4084915684 ecr 4084909667], length 013:50:54.743012 IP localhost.41692 > : Flags [.], ack 11500, win 512, options [nop,nop,TS val 4084915684 ecr 4084903638], length 013:50:57.748679 IP localhost.41692 > : Flags [.], ack 11500, win 512, options [nop,nop,TS val 4084918690 ecr 4084903638], length 013:50:57.748720 IP > localhost.41692: Flags [.], ack 63, win 512, options [nop,nop,TS val 4084918690 ecr 4084915684], length 0

原⽣注释# TCP keepalive.## If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence# of communication. This is useful for two reasons:## 1) Detect dead peers.# 2) Force network equipment in the middle to consider the connection to be# alive.## On Linux, the specified value (in seconds) is the period used to send ACKs.# Note that to close the connection the double of the time is needed.# On other kernels the period depends on the kernel configuration.## A reasonable value for this option is 300 seconds, which is the new# Redis default starting with Redis 3.2.1.#tcp-keepalive 300

发布者:admin,转转请注明出处:http://www.yc00.com/news/1690105831a306268.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信