2009年11月18日 星期三

TCP Windows Size 解答

說明TCP Windows Size 的用途與注意事項
1.TCP Windows Size 目的是 Sender 與 Receiver 最好能把Data 一次處理完,
以避免因為網路設備彼此速度不同,而造成Data Lost 的問題。

2. TCP Windows Size 要多大呢?
window size = bandwidth * delay
假設網路是 100 Mbits/s, round trip time (RTT)是 5 ms,所以 Windows Size 應為
( 100 * 10^6) *( 5 * 10^-3) = 500 * 10^3 bits (65 kilobytes)

3.最後 Client 與 Server 的buffer 要設一樣:
/* An example of client code that sets the TCP window size */

int window_size = 128 * 1024; /* 128 kilobytes */

sock = socket(AF_INET, SOCK_STREAM, 0);

/* These setsockopt()s must happen before the connect() */
setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
(char *) &window_size, sizeof(window_size));
setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
(char *) &window_size, sizeof(window_size));
connect(sock, (struct sockaddr *) &address, sizeof(address));


/* An example of server code that sets the TCP window size */
int window_size = 128 * 1024; /* 128 kilobytes */
sock = socket(AF_INET, SOCK_STREAM, 0);

/* These setsockopt()s must happen before the accept() */
setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
(char *) &window_size, sizeof(window_size));
setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
(char *) &window_size, sizeof(window_size));

listen(sock, 5);
accept(sock, NULL, NULL);
4.備註:
a.Nonstop 系統
TCP programming :setsockopt 參數(SO_SNDBUF/SO_RCVBUF)
Default 8192 bytes

5.參考:
a.A User's Guide to TCP Windows
b.Enabling High Performance Data Transfers
c.Windows 2000 TCP Performance Tuning Tips

6.
a.Max Transmission Unit (MTU) - TCP header(20 byte)- IP header (20 bytes) =Max Segment Size(MSS)
b.

沒有留言: