什么是TCP Window

TCP Window可能是需要理解的数据传输过程里最重要的部分了, 尤其是对于数据中心而言, 因为备份工作是每天都要进行的. 在今天的数据中心中, 高带宽的高可用性和高速连接使得提供应用程序服务器和备份服务器之间的几个G吞吐量变得更容易了. 随着WAN(wide area network)连接增大, 更快, 更高效, 终端用户比从前能访问到更大的吞吐量.

随着所有这些尖端科技的可用, 很多人不了解为什么应用程序还是看起来那么缓慢. 甚至用10G的备份连接还是要花费很多小时. 数据迁移应用程序的延迟的众多原因之一是TCP Window. 有些用用程序还在使用陈旧的TCP Stack, 它们是为了八十年代的网络而写的, 当时2400bps的拨号连接看起来还是快速的哩. 有些今天的应用程序忽略掉了TCP Window在数据转移过程中的影响, 网络工程师在排查备份缓慢和应用程序延迟的时候也许会跳过传输层. 在这篇文章里, 我们会清晰的定义TCP Window, 看看它是如何影响性能的, 并且展示如何使用Wireshark监控它.

什么是TCP Window?

在讨论TCP Window的时候, 我们几乎总是指的是TCP Receive Window. 简单来说, TCP Receive Window是在TCP连接两端都有的缓冲区, 用于暂时保存到来的数据. 在这个缓冲区中的数据会被发送到应用程序中, 为新到来的数据腾出空间. 如果这个缓冲满了, 那么数据的接收方会警告发送方在缓冲去清空之前已经不能在收取更多的数据了. 这其中涉及到一些细节, 但那都是很基本的东西. 一般, 设备会在TCP Header信息中通知对方当前它的TCPWindows的大小.

image 

在上面的截屏里, 这个包的发送方告诉连接的另一端: 他的TCP Receive Buffer是65535个字节. 这是标准TCP Window Size的最大值. TCP中有选项可以是这个数值更大, 但是现在我们就认为这个是最大值吧.

TCP连接的任意一段都有自己的TCP Receive Window. 所以在任何时候, 这两个window的大小都可能会不一样. 比如说一个Web Server通常发送数据给用户, 而不是从用户那里获得数据. 基于这个原因, Web Server不需要像普通用户需要那么大的TCP Window. 所以Web Server会告知它的receive window是8192字节, 而客户端的window却是65535字节.

TCP Window如何影响性能?

在一个文件传输的时候, 数据从一台机器流向另一台. 数据接收方需要阻止它的TCP Window降为0, 意味着window填满了. 如果一个TCP Window变为0了, 或者接近0了, 这就会警告数据发送方没有更多空间来接受更多数据了.文件传输会停止, 直到收到一个update说buffer已经清空了.

在原文的例子文件中, 有一个TCP Window不断下降, 最后终止文件传输的封包.

image 

如果这种情况发生了, 并且应用程序已经使用了window的最大尺寸, 而且还不够, 那么从分析的角度来说没什么可以做的. 建议对应用程序的代码进行修改.

TCP Window是基于连接的, 即如果两台机器间的其他的TCP连接正在进行中, 那么一个连接的中断window不会停止其他连接. 所以在多线程的应用程序里, 数据还是可以在一个连接正在恢复的时候在其他连接上进行传输.

下面一段就不翻译了, 有兴趣或有需要的朋友可以自己看看.

========================================

Using Wireshark, how can I monitor the TCP Window?

During large file transfers, keep an eye on the TCP Window being advertised in the TCP ACK packets of the receiver. There are a few ways to do this with Wireshark. By default, the TCP window of thepacket sender is displayed in the info summary view for each ACK packet.

Another way to show this is by using the I/O Graphs looking for the TCP Window Size to drop. To do this, use the tcp.analysis.window_update filter. Try it with the sample trace file using these settings.

image

This graph shows the full size TCP Window dropping to nothing several times. While the window is down near zero, data is halted while the sender waits for the receive buffer to clear. Watch for these dips during large data transfers. The I/O graph makes them easier to see than combing through packet by packet!

参考资料

=================

Practical TCP Series – The TCP Window (by Chris Greer)

http://www.lovemytool.com/blog/2010/07/practical-tcp-series-the-tcp-window-by-chris-greer.html

http://www.cnblogs.com/awpatp/archive/2013/02/17/2914152.html

猜你喜欢

转载自blog.csdn.net/boy_hxm/article/details/38558881