当前位置:网站首页>TCP 连接中的keep-alive
TCP 连接中的keep-alive
2022-06-10 01:04:00 【为了维护世界和平_】
目录
keep-alive
在一个长连接内,在一段期间,如果没有任何相关的活动,TCP保活机制开始作用。每隔一段时间,发送一个报文,如果连续几个报文都没有得到响应,则认为当前TCP连接已经失效。
内核中的变量
net.ipv4.tcp_keepalive_time
net.ipv4.tcp_keepalive_intvl
net.ipv4.tcp_keepalve_probes
Document/networking/ip-sysctl.txt
tcp_keepalive_time - INTEGER
How often TCP sends out keepalive messages when keepalive is enabled.
Default: 2hours.tcp_keepalive_intvl - INTEGER
How frequently the probes are send out. Multiplied by
tcp_keepalive_probes it is time to kill not responding connection,
after probes started. Default value: 75sec i.e. connection
will be aborted after ~11 minutes of retries.tcp_keepalive_probes - INTEGER
How many keepalive probes TCP sends out, until it decides that the
connection is broken. Default value: 9.
默认设置是2 小时、75 秒和 9 次探测。
说明
- 客户端和服务端正常工作,探测报文发送给对端,对端正常响应,则TCP保活变量被重置。
- 对端程序崩溃并重启,当TCP保活探测发送给对方,对端可以响应。但由于没有该链接的有效信息,会产生RST报文,TCP连接被重置。
- 对端程序崩溃,报文不可到达,多次探测后,TCP会报告该TCP链接已经死亡。
- 内核探测时间,最少需要经过 2 小时 75 秒; 时间太长,内核中的参数是可以设置的,但应用层需要感知是否是活动连接,需要在应用层增加传输协议。
保活机制
可以在两侧开启,也可以在一侧开启。
服务器端要探活client来保证自己不会维护无效连接,客户端来探活保持自己是不是可以持续申请资源。
好处
1、如果开启服务器端到客户端的检测,可以在客户端非正常断连的情况下清除在服务器端保留的“脏数据”;
- 2、开启客户端到服务器端的检测,可以在服务器无响应的情况下,重新发起连接。
应用层保活
应用层需要知道连接状态,在断开时做一些处理。在服务端与客户端设计心跳包,如客户端在没有进行数据交互的时候向服务端发送心跳包,服务器收到后进行反馈,如果多次没有反馈,客户端则终止连接。
参考
https://course.0voice.com/v1/course/intro?courseId=2&agentId=0
边栏推荐
- Win11退回Win10没有返回选项怎么办?
- 图片批量下载 +图片马赛克:多张图片组成端午安康
- Locust:微服务性能测试利器
- 沪漂大专程序员,一边跟刘畊宏健身,一边拿22k的offer
- 孙宇晨等收购Poloniex,公链交易所双轮驱动波场生态
- LEAK: ByteBuf.release() was not called before it‘s garbage-collected
- Sword finger offer II 011 0 and 1 subarrays with the same number
- MAUI + MVVM + SIEMENS 跨平台应用实战
- Reprint the Alibaba open source project egg JS technical documents cause "copyright disputes". How to use the loose MIT license?
- 比你想象中更强大的 reduce 以及对敲码的思考
猜你喜欢

孙宇晨等收购Poloniex,公链交易所双轮驱动波场生态

How can win11 directly return to the desktop?

视频汇聚平台EasyCVR级联EasyCVR出现通道频繁掉线是什么原因?

国内现货白银有哪些好技术:常见指标的简单用法

Have you learned about arrays and slices in golang in go question bank · 1?

MongoDB 开源“可查询加密”系统 Queryable Encryption

Application scheme of residual pressure monitoring system in a high-rise residential building

Picture batch download + picture mosaic: multiple pictures constitute the Dragon Boat Festival Ankang!

FPGA-VGA显示

Hcip first job
随机推荐
Mysql——》事务
Host computer development -- how fast is MODBUS
Win11退回Win10没有返回选项怎么办?
【ICLR 2022】Towards Continual Knowledge Learning of Language Models
Dependent auto assembly
MySQL transaction
Sword finger offer II 012 The sum of left and right subarrays is equal
MongoDB 开源“可查询加密”系统 Queryable Encryption
PCI BAR寄存器详解(二 实例讲解)
Force deduction solution summary 497 random points in non overlapping rectangles
Where should middle-aged test development engineers go? The unknown is tomorrow, break the label
洛谷P2657 [SCOI2009]windy数 题解 数位DP
Source code analysis of Tencent libco collaboration open source library (I) -- download libco compilation and installation and try to run the sample code
PCI bar register explanation (I)
Solution to the problem of the greatest common divisor and the least common multiple of Luogu p1029
MySQL - isolation level of transactions
Curriculum Learning and Graph Neural Networks (or Graph Structure Learning)
datagrip的两个问题
Cocoscreator old, live and new - synthetic large zongzi
What if win11 returns win10 without a return option?