Original address: http://blog.sina.com.cn/s/blog_c5c2d6690102wpxl.html
There are many parameters in the TCP protocol that affect the actual traffic flow, and here the main analysis of the effect of the window.
? TCP Window Purpose
To achieve optimal connection rates, using a TCP window to control the flow rate (flow control), sliding windows is a major mechanism. This window allows the source side to transmit data fragments at a given connection without waiting for the target to return an ACK, one sentence description: The size of the window determines the amount of data that is transferred without the need for a peer response (acknowledgement). Official definition: "The amount of octets that can be transmitted without receiving a acknowledgement from the other side ".
TCP window mechanism
?? The TCP header has a window size field, which in fact refers to the receiving side of the windows, that is, the receiving window, to inform the sending side of the amount of data they can receive, thus achieving a shunt control purposes. In fact, TCP in the entire transmission process, but also in the measurement of the current network state, the purpose is to maintain a healthy and stable transmission process, such as congestion control. Therefore, the data is transmitted under the control of some mechanisms, that is, the window mechanism. The sending side of the sending window is based on the receiving side of the receiving window to calculate, that is, we often say that TCP is connected to send, data transmission needs to confirm the end of the data sent into the following four categories to see
Window swipe to send data
(1) has been sent and confirmed to the end (sent/acked)---------------out of the buffer outside the window
(2) has been sent but not received the confirmation data (sent/unacked)-------Send in the buffer within the window?
(3) data that is allowed to be sent but not yet resistant? (unsent/inside)-----------send in the buffer within the window?
(4) Not sent temporarily not allowed (Unsent/outside)-------------------sent out of the buffer window?
The TCP window is the way to gradually slide, send the new data, the swipe is to send the data has received an ACK, confirm to the end received, in order to continue to slide the window to send new data. You can see that the window size has a significant impact on throughput, while the ACK response is closely related to system latency. It is necessary to note that if the sending side of the window over the assembly caused the receiver to close the window, processing not to the contrary, if the window settings are small, the result is not enough bandwidth, so carefully adjust the window for different latency and bandwidth requirements of the system is very important .
TCP Window Size
The earliest TCP protocol involves the use of large-scale network transmission time, in fact, there is no more than 56kb/s? Connection speed. Therefore, only 16bit is reserved in the TCP header to identify the window size, and the maximum allowable cache size is no more than 64KB. To break this limit, RFC1323 specifies the TCP window size selection, which is negotiated at the start of the TCP connection at the time of the three-step handshake (SYN, Syn-ack,ack), which negotiates a window size scaling factor, After that, the window size value is the result of the interactive data, so the final windows are the product of the two.
Window size value:64 or 0000 0000 0100 0000 (BITS)
? Window size Scaling factor:256 or 2 ^ 8 (as advertised by the 1st packet)
The actual window size is 16,384 (64 * 256)
The window size here means that until 16,384 bytes are sent, the ACK is stopped waiting for the other party. As the two sides reply to continue, the window size can be modified to narrow or widen the Windows size value parameter, but note:Window size Scaling Factor product factor ? must remain unchanged. The offset specified in the RFC1323 (shift count) is 14, which means that the largest window can reach Gbit, very large.
Wireshark Grab Bag Instance
This mechanism is not always open by default and system-related, it seems that Linux is turned on by default, Windows off by default.
? Parameter settings for TCP windows
TCP Windows play a role in controlling traffic, which is a two-terminal coordination process in practice, and also involves a slow start of TCP (Rapid increase/multiplicative decrease), congestion avoidance, congestion windows, and congestion control. It can be remembered that the send rate is by min (Congestion window, receive window), and the Receive window is spoken below.
TCP Window optimization settings?
TCP? Since the window is so important, how to set it, a simple principle is twice times the BDP. The BDP here means Bandwidth-delay product, which is the product of bandwidth and latency, and bandwidth is the worst connection bandwidth for the network.
Buffer size = 2 * Bandwidth * delay?
There is also an easy way to use ping to calculate the loopback delay (RTT) of a network and then express it as:
Buffer size = Bandwidth * RTT?
? Why is it twice times? Because it is possible to think, if the sliding window is Bandwidth*delay, when the last byte of data is sent at the end of the first time to send back an ACK to continue sending, you need to wait for a one-way delay time, so when it is twice times, just can wait for the ACK time to continue to send data, The data is sent exactly when the ACK is received, which improves efficiency.
For example: Bandwidth is 20Mbps, by pinging we calculate the one-way delay is 20ms, then you can calculate: 20000000bps*8*0.02 = 52,428bytes?, so our optimal window with 104,856 bytes = 2 x 52,428, so that when the sender sends 104,856 bytes data, it waits for an ACK response, and when it is sent halfway, the peer receives and returns an ACK (ideally), waits for the ACK to return, and sends the remaining half out. , so the sender does not have to wait for an ACK to return.
Did you find it? The window here is already significantly larger than 64KB, so the mechanism has improved, on a level.
TCP Window Flow control?
? Now let's see how the traffic is controlled. TCP When transferring data and Windows size relationship Close, itself window used to control traffic, when transmitting data, the sender of data over the receiver will be dropped packets, traffic control, traffic control requires the data transmission both sides in each interaction to declare the respective receive window "rwnd" size, Used to indicate how much data you can save, this is mainly for the recipient, the popular word is to let the sender know that the receiver can eat a few bowls of rice, if the window attenuation to zero, that is, the sender can not be sent again, then the full, must digest digestion, if the heave leakage, it is lost package.
Flow control
Slow Start ? Although traffic control can prevent the sender from overloading the receiver, it is not possible to avoid overloading the network, because the receiving window "rwnd" only reflects the situation of the individual server, but does not reflect the overall network situation.
In order to avoid network overload, slow start introduces the concept of congestion window "cwnd" , which is used to indicate the maximum number of unacknowledged data that the sender allows to transmit before receiving confirmation. "cwnd" with " rwnd"compared to the difference is: it is only the sender of an internal parameter, without notice to the receiver, its initial value is often relatively small, and then with the packet was confirmed by the receiver, the window multiplied, a bit similar to boxing game, the beginning of not understanding the enemy, often is the second fist temptation, slowly in the heart, began to gradually increase the strength 。
Congestion window Enlargement
In the slow start process, with the increase in "cwnd", network overload may occur, its external performance is to lose packets, once such problems occur, the size of the "cwnd" will quickly decay, so that the network can ease.
Congestion window and packet loss
Description: The actual transmitted unacknowledged data size in the network depends on the small values in "rwnd" and "cwnd".
congestion avoidance? from the introduction of the slow start, we can see that the sender passed the " cwnd"size control, to avoid network overload, in the process, packet loss is not so much a network problem, rather, it is a feedback mechanism, through which we can perceive the network congestion, and then adjust the data transmission strategy, in fact, there is a slow start threshold value" The concept of ssthresh", if"cwnd"is less than"ssthresh", is expressed in the slow start phase, if"cwnd"is greater than"ssthresh", then in the congestion avoidance phase, this time" cwnd"is no longer the same as the slow start phase of a full-scale, but tend to linear growth, in order to avoid network congestion, this stage has a number of algorithm implementations, usually keep the default, here is not explained.
? How to adjust "rwnd" to a reasonable value many times the TCP transmission rate is abnormally low, it is likely that the receiving window "rwnd" too small, especially for the network with a large delay, actually receive window " The reasonable value of the rwnd"depends on the size of the BDP, which is the product of bandwidth and latency. Assuming that the bandwidth is 100Mbps and the latency is 100ms, the calculation process is as follows:
BDP = 100Mbps * 100ms = (100/8) * (100/1000) = 1.25MB?
In this issue, if you want to maximize swallow metrics, the size of the receive window "rwnd" should not be less than 1.25MB.
How to adjust "cwnd" to a reasonable value in general, the initial value of "cwnd" depends on the size of the MSS, calculated as follows:
MIN (4 * MSS, MAX (2 * MSS, 4380))
The MSS size of the Ethernet standard is usually 1460, so the initial value of the "cwnd" is 3MSS. When we browse the video or download the software, the effect of "cwnd" initial value is not obvious, this is because the amount of data transmitted is larger, longer, in contrast, even if the slow start phase "cwnd" initial value is small, it will be in a relatively short period of time to accelerate to full window, basically negligible. Use Ixchariot to complete the setup once?
Set CWnd
However, when we browse the page, the situation is different, because the transmission of data volume is smaller, time is relatively short, in contrast, if the slow start phase "cwnd" initial value is small, then it is likely not to accelerate to full window, the communication is over. This is like bolt in the hundred meter game, if the start is slow, even if his acceleration quickly, may not get good results, because he did not wait for him to fully run, the finish line has arrived
Conclusion?
The article is a lot of reference to the following blog content, such as the last section is almost entirely from the first blog, the detailed content of the link, learning Summary, record.
https://huoding.com/2013/11/21/299
https://my.oschina.net/greki/blog/264061?
? http://www.cnblogs.com/woaiyy/p/3554182.html
Window size and throughput in the TCP protocol