关于Winsock Kernel Buffer和Nagle算法的疑问
在阅读这篇文章时,我有一个疑问。
据我了解,在传输小数据时,默认情况下会启用 Nagle 算法,该算法会合并小数据包。 这会导致在传输之前缓存一些数据。 我相信 Winsock Kernel Buffer 是缓存发生的地方。 如果我错了请纠正我。
这是否意味着如果使用 SO_SNDBUF 选项将 Winsock 内核缓冲区设置为零,Nagle 算法是否会被禁用?
如果不是那么WINSOCK将小数据缓存在哪里?
While reading this article, I got a doubt.
I understood that while trasferring small data, Nagle algorithm is enabled by default which coalesces small packets. This results in caching some data before transmission. I believe that Winsock Kernel Buffer is the place where caching happens. Correct me if I am wrong.
Does it mean that if the Winsock Kernel Buffer is set to zero with SO_SNDBUF option, will the Nagle algorithm be disabled?
If not then where does WINSOCK cache the small data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您引用的知识库文章以这种方式给出了您的答案......
并且,设置 TCP_NODELAY 或 SO_SNDBUF=0 将禁用 Nagle 算法,如下所示,
阅读下面的评论,我意识到您可能会感到困惑,因为设置 TCP_NODELAY 或设置 SO_SNDBUF=0 似乎都在做同样的事情。 如果是这种情况,请注意 Nagle 仅适用于 TCP 流(将数据分段为数据包),而 SO_SNDBUF 也适用于 UDP 套接字。
将 SO_SNDBUF 设置为零显式停止所有输出缓冲,并尝试立即调度套接字上的每个“写入”(至少在正常套接字实现中)。
设置 TCP_NODELAY 将显式停止 TCP 套接字上的 Nagle 算法,尽管发送缓冲区可能可用并用于延迟调度(在向应用程序确认发送成功后)。
The KB article you refer gives your answers in this way...
and, setting TCP_NODELAY or SO_SNDBUF=0 will disable Nagle algorithm as below,
Reading your comment below, I realize you might be confused because setting TCP_NODELAY or setting SO_SNDBUF=0 both seem to be doing the same thing. If that is the case, please note that Nagle is applicable only over TCP streams (which segments data into packets), whereas SO_SNDBUF is a also applicable to UDP sockets.
Setting SO_SNDBUF to zero explicitly stops all output buffering and an immediate dispatch is attempted for each 'write' on the socket (at least in normal socket implementations).
Setting TCP_NODELAY will explicitly stop Nagle algorithm on TCP sockets though the send buffer may be available and used for delayed dispatch (after send success is acknowledged to the application).
SO_SNDBUF 设置为 0 不会强制立即在线发送。
SO_SNDBUF set to 0 does NOT force an immediate send on the wire.
将 SO_SNDBUF 设置为零将不会隐式禁用 nagle; WSK 维护的 nagle 状态与缓冲区所在的位置无关。 您有责任保持您发布的缓冲区有效,直到传输消耗它。
Setting SO_SNDBUF to zero will not implicitly disable nagle; the nagle state maintained by the WSK is independent of where the buffer is located. It's your responsibility to keep the buffers you post valid till the transport consumes it.