禁用TCP延迟的ACK [英] Disable TCP Delayed ACKs
问题描述
我有一个应用程序,该应用程序通过TCP接收相对稀疏的流量,而没有应用程序级别的响应.我相信TCP堆栈正在发送延迟的ACK(基于对网络数据包捕获的浏览).为单个套接字禁用网络堆栈中的延迟ACK的推荐方法是什么?我已经看过TCP_QUICKACK
,但看来堆栈还是会改变我的脚下.
I have an application that receives relatively sparse traffic over TCP with no application-level responses. I believe the TCP stack is sending delayed ACKs (based on glancing at a network packet capture). What is the recommended way to disable delayed-ACK in the network stack for a single socket? I've looked at TCP_QUICKACK
, but it seems that the stack will change it under my feet anyways.
这是在Linux 2.6内核上运行的,我不担心可移植性.
This is running on a Linux 2.6 kernel, and I am not worried about portability.
推荐答案
在执行的每个recv
之后都可以setsockopt(sockfd, IPPROTO_TCP, TCP_QUICKACK, (int[]){1}, sizeof(int))
.看来TCP_QUICKACK
仅在有数据发送或接收时才被复位;如果您不发送任何数据,那么只有在接收到数据后,它才会被重置,在这种情况下,您只需重新设置即可.
You could setsockopt(sockfd, IPPROTO_TCP, TCP_QUICKACK, (int[]){1}, sizeof(int))
after every recv
you perform. It appears that TCP_QUICKACK
is only reset when there is data being sent or received; if you're not sending any data, then it will only get reset when you receive data, in which case you can simply set it again.
您可以在/proc/net/tcp
的第14 字段中进行检查;如果不是1,则应立即发送ACK ...如果我正确读取了TCP代码. (我也不是专家.)
You can check this in the 14th field of /proc/net/tcp
; if it is not 1, ACKs should be sent immediately... if I'm reading the TCP code correctly. (I'm not an expert at this either.)
这篇关于禁用TCP延迟的ACK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!