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的大小.
在上面的截屏里, 這個包的發送方告訴連接的另一端: 他的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不斷下降, 最后終止文件傳輸的封包.
如果這種情況發生了, 並且應用程序已經使用了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 the packet 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.
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