什么是TCP延迟确认的解决方法吗? [英] What is the workaround for TCP delayed acknowledgment?

查看:2726
本文介绍了什么是TCP延迟确认的解决方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已附带使用TCP协议来确保在服务器 - 客户端网络拓扑可靠的通信线上(基于​​网格的)视频游戏。我的游戏作品还算不错,但比预期的延迟患有高(在体裁类似TCP游戏似乎在保持延迟到最小做一个更好的工作)。

I have shipped an online (grid-based) videogame that uses the TCP protocol to ensure reliable communication in a server-client network topology. My game works fairly well, but suffers from higher than expected latency (similar TCP games in the genre seem to do a better job at keeping latency to a minimal).

在调查,我发现等待时间仅为出乎意料的高,为客户运行的的Microsoft Windows 的(相对的的Mac OS X 的客户端)。此外,我发现,如果Windows客户端设置<一个href=\"http://lifeand$c$c.net/2009/05/reduce-game-network-latency-in-windows-7-or-vista/\"><$c$c>TcpAckFrequency=1在并重新启动他们的机器注册表,他们的等待时间恢复正常。

While investigating, I discovered that the latency is only unexpectedly high for clients running Microsoft Windows (as opposed to Mac OS X clients). Furthermore, I discovered that if a Windows client sets TcpAckFrequency=1 in the registry and restarts their machine, their latency becomes normal.

这样看来,我的网络设计没有考虑到延迟确认:

It would appear that my network design did not take into account delayed acknowledgement:

这是不考虑的延迟确认,Nagle算法,和Winsock缓冲的相互作用可以显着影响性能设计。
  ( http://support.microsoft.com/kb/214397

A design that does not take into account the interaction of delayed acknowledgment, the Nagle algorithm, and Winsock buffering can drastically effect performance. (http://support.microsoft.com/kb/214397)

不过,我发现它几乎不可能考虑到我的游戏账号延迟确认(或任何游戏)。根据MSDN,微软TCP堆栈使用以下条件来决定何时上接收的数据包发送一个ACK:

However, I'm finding it nearly impossible to take into account delayed acknowledgement in my game (or any game). According to MSDN, the Microsoft TCP stack uses the following criteria to decide when to send one ACK on received data packets:


      
  • 如果延迟定时器期满(200ms的)之前接收所述第二数据包中,ACK被发送。

  •   
  • 如果有被接收之前的第二数据包与延迟定时器超时在相同的方向上的ACK要发送的数据,
      该ACK是搭载与数据段,并立即发送。

  •   
  • 当延时定时器超时(200毫秒),则发送ACK。

  •   

http://support.microsoft.com/kb/214397

读这篇文章,一会presume在Microsoft的TCP堆栈延迟确认的解决方法如下:

Reading this, one would presume that the workaround for delayed acknowledgement on Microsoft's TCP stack is as follows:


  1. 禁用Nagle算法(TCP_NODELAY)。

  2. 禁用套接字的发送缓冲区( SO_SNDBUF = 0),这样就呼叫发送可预期发送一个数据包。

  3. 当调用发送,如果没有进一步的数据预计将立即发送,请拨打发送跟单再次数据 - 字节将由接收机丢弃。

  1. Disable the Nagle algorithm (TCP_NODELAY).
  2. Disable the socket's send buffer (SO_SNDBUF=0), so that a call to send can be expected to send a packet.
  3. When calling send, if no further data is expected to be sent immediately, call send again with a single-byte of data that will be discarded by the receiver.

通过这种方式,第二数据包将被由接收器在大约相同的时间作为previous数据分组接收。其结果是,在 ACK 应该得到(模拟什么的TcpAckFrequency = 1 确实在从接收到发送方立即发送注册表)。

With this approach, the second data packet will be received by the receiver at around the same time as the previous data packet. As a result, the ACK should get sent immediately from the receiver to the sender (emulating what TcpAckFrequency=1 does in the registry).

然而,来自我的测试,这仅约一半的注册表编辑做什么改进等待时间。我缺少什么?

However, from my testing, this improved latency only by about a half of what the registry edit does. What am I missing?



问:为什么不使用UDP

答:我选择了TCP,因为每个数据包我送的需求到达(并且是按顺序);有没有这arn't值得如果丢失(或成为无序的)重传的数据包。只有当数据包可以被丢弃/无序,能UDP比TCP更快!

A: I chose TCP because every packet I send needs to arrive (and be in order); there are no packets that arn't worth retransmitting if they get lost (or become unordered). Only when packets can be discarded/unordered, can UDP be faster than TCP!

推荐答案

由于Windows Vista中,TCP_NODELAY选项必须在调用设置连接,或(在服务器上)在调用。如果设置 TCP_NODELAY 呼叫后连接,也不会的实际的禁用Nagle算法,但 GetSocketOption 将状态内格尔已被禁用!这一切都似乎是无证,而且违背了许多教程/关于这个问题的文章教

Since Windows Vista, TCP_NODELAY option must be set prior to calling connect, or (on the server) prior to calling listen. If you set TCP_NODELAY after calling connect, it will not actually disable Nagle algorithm, yet GetSocketOption will state that Nagle has been disabled! This all appears to be undocumented, and contradicts what many tutorials/articles on the subject teach.

使用内格尔实际上禁用TCP延迟确认不再导致延迟。

With Nagle actually disabled, TCP delayed acknowledgements no longer cause latency.

这篇关于什么是TCP延迟确认的解决方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆