本文介绍了TCP Nagle刷新发生了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此Socket FAQ文章,Nagle的算法是众多算法之一这可能会导致一堆数据位于TCP缓冲区中而无法正常运行. Nagle算法的延迟可能长达200毫秒.

According to this Socket FAQ article, Nagle's algorithm is one of many algorithms that can cause a bunch of data to sit in the TCP buffer and not hit the wire. The delay from the Nagle algorithm can be up to 200ms.

由于某种原因,可以完全关闭Nagle的算法,但是仅刷新一次.这真让我感到困惑.为什么没有办法说仅此一次,不要等待任何其他数据.就好像Nagle的200ms到了一样."

For some reason, Nagle's algorithm can be turned off completely, but not flushed just once. This is really puzzling to me. Why is there no way to say that "just this one time, don't wait for any more data. Just act as if Nagle's 200ms are up."

那不是完全合理的做法,并且可以在完全不使用Nagle,一直使用Nagle以及从头实现自己的协议之间取得良好的平衡吗?

Wouldn't that make perfect sense, and strike a good balance between no Nagle at all, Nagle all the time, and implementing one's own protocol from scratch?

推荐答案

好问题.我猜没有人真的需要它,或者他们绕过了它.如果我没记错的话,启用TCP_NODELAY会立即推送数据.然后,您可以将其禁用.

Good question. I guess nobody ever really needed it or they got around it. If I remember correctly, enabling TCP_NODELAY pushes the data immediately. Then you can just disable it.

当然,这需要两个系统调用"flush"的高昂代价.您可以做什么 :在Unix实现中,send(2)有一个flags参数.您可以实现自己的标志,例如:MSG_JUSTPUSHIT(好吧,也许是另一个名称),并在tcp_output中考虑它.

Of course, this comes at the high cost of two system calls for a "flush". What you could do: send(2), on Unix implementations has a flags argument. You could implement your own flag, something like: MSG_JUSTPUSHIT (okay, maybe another name) and consider it in tcp_output.

这篇关于TCP Nagle刷新发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 07:00