delayed ack和nagles算法都能减少tcp传输过程中的小数据包的问题
tcpip卷二25章中提到tcp为每个连接建立7个定时器:
1.connection established
2.restransmission
3.delayed ack(https://en.wikipedia.org/wiki/TCP_delayed_acknowledgment)
4.persist
5.keepalive
6.fin_wait_2
7.time_wait
下面是wikipedia对nagle’s算法描述的url,
https://en.wikipedia.org/wiki/Nagle%27s_algorithm
最主要的应该就是这段代码:
if there is new data to send if the window size >= MSS and available data is >= MSS send complete MSS segment now else if there is unconfirmed data still in the pipe enqueue data in the buffer until an acknowledge is received else send data immediately end if end if end if
MSS(maximum segment size)
(今天才知道这是两个概念,之前以为是一个意思呢O(∩_∩)O~),
如果实际中就是小数据包很多而且实时要求很高的话,可以设置socket的tcp_nodelay选项来关闭nagles算法(nginx中就有此设置).(这里还有两个参数tcp_cork和tcp_quickack和本文有关系有时间可以研究一下这两个参数。)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix