If the cache of the receiver is full and the sender is still sending data frantically, the receiver can only throw away the received data packets. A large number of packet loss greatly wastes network resources. Therefore, traffic control is required.

First, flow control

Flow control: let the sender send rate is not too fast, so that the receiver can receive processing in time.

Principle: The sending rate of the sender is controlled by confirming the window field in the packet. The size of the sending window of the sender cannot exceed the size of the window given by the receiver. When the sender receives that the size of the receive window is 0, the sender stops sending data.

There is a special case where the receiver initially sends a segment of the 0 window to the sender. Later, the receiver has some storage space, and the segment of the message sent to the sender with a non-zero window is lost. In this case, the sending window of the sender is always 0, and the two parties reach an impasse.

The solution is: When the sender receives the 0 window notification, the sender stops sending packets. At the same time, a timer is started, and a test message is sent to ask the receiver the latest window size at intervals. If the received window size is still 0, the sender refreshes the timer again.

Abbreviations:

  • MSS (Max Segment Size) : The maximum size of the data part of each segment is determined when the connection is established, and the MSS value is 1460 bytes according to the backward calculation of the data link layer. However, the size of each value is uncertain and needs to be determined together when both parties communicate (the minimum value is taken).Calculation method: Transmission layer 1500 bytes of data = network layer (first 20 bytes + data 1480 bytes = Transmission layer (first 20 bytes + data 1460 bytes (MSS))
  • The CWND (congestion window) : Congestion window (sender)
  • RWND (receive window) : Receiving window (receiver)
  • SWND (send window) : send window, the maximum value is the minimum of congestion window and receive window (swnd = min(cwnd, rwnd)), whenrwnd < cwnd, is the maximum value of the sending window of the receiver’s receiving capacity limit, whenrwnd > cwndIs the maximum value of the network congestion limit send window.

2. Congestion control

Congestion control: Prevents too much data from being injected into the network and prevents overload of routers or links on the network.

Congestion control is a global process that involves all hosts, routers, and other factors that degrade network performance. By contrast, flow control is the control of point-to-point communication.

Load refers to the total amount of bandwidth that passes through the router. Throughput is the theoretical peak of bandwidth. The ideal case for link throughput in the figure above is when the throughput peaks when the charge exceeds the bandwidth. But the reality is that as the load gets heavier (the network becomes congested), throughput does not reach the bandwidth value and then declines (the network becomes congested), and the network becomes stuck (deadlock) after a certain amount of load is reached.

Think about traffic. In theory, an eight-lane road can accommodate 1,000 cars at a time, but in practice 700 cars will be congested. During the morning or evening rush hour, the traffic on the road starts to move slowly, and as more cars build up, it can bring traffic to a standstill.

2.1. Control methods

2.1.1. Slow Start/Slow start (slow start)

The receiver tells the sender MSS=100, RWND =3000, and the sender sets the send window (congestion window) to CWND =100 according to MSS. After each round of successful reception, CWND grows exponentially (2^n, maximum RWND), which is a slow start.

When the host starts sending data, if a large number of data bytes are immediately injected into the network, it may cause congestion because it is not clear how overloaded the network is. Therefore, the better method is to first detect, that is, gradually increase the sending window from small to large, that is, gradually increase the value of congestion window from small to large. Usually, the congestion window CWND is set to a maximum MSS value at the beginning of sending a packet segment. After each acknowledgement of a new message segment is received, the congestion window is increased by at most one MSS value. Gradually increasing the congestion window CWND of the sender in this way can make the packet injection rate more reasonable.

In order to prevent network congestion caused by excessive CWND growth of congestion window, a slow start threshold ssthRESH state variable should also be set:

  • whenCWND < ssthresh, the above slow start algorithm is used.
  • whenCWND > ssthresh, stop using the slow start algorithm and use the congestion avoidance algorithm.
  • whenCWND = ssthresh, both slow start algorithm and congestion control avoidance algorithm can be used.

2.1.2. Congestion Avoidance (congestion avoidance)

Ssthresh (Slow Start Threshold) : indicates the slow start threshold. After the CWND reaches the threshold, it increases in a linear manner. When network congestion occurs frequently, the SSTHRESH value drops rapidly.

Congestion avoidance (increase in addition) : The congestion window slowly increases to prevent premature network congestion.

Multiplication reduced: As soon as network congestion occurs, ssthRESH is halved, and at the same time, the slow start algorithm is performed (CWND reverts to the initial value).

Let the congestion window CWND grow slowly, that is, every round trip time RTT increases the sender’s congestion window CWND by 1 instead of doubling it. The congestion window CWND grows slowly in a linear way, which is much slower than the congestion window growth rate of the slow-start algorithm.

  • When the TCP connection is initialized, set the congestion window CWND to 1. As mentioned earlier, for ease of understanding, the window units in the figure use the number of message segments (SMSS) instead of bytes. The initial value of the slow start threshold is set to 16 segments, that isCWND = 16.
  • The initial value of the congestion window CWND is 1 when executing the slow-start algorithm. Each time the sender receives an acknowledgement ACK for a new packet segment, the value of the congestion window is changed by 1, and the next round of transmission (the abscissa in the figure is the transmission round) begins. Therefore, congestion window CWND increases exponentially with transmission rounds. When the congestion window CWND grows to the slow start threshold SSTHRESH (i.eCWND=16, the congestion control algorithm is implemented instead, and the congestion window increases linearly.
  • Assume that the value of the congestion window increases to 24, and the network times out (which is most likely the network is congested). The ssthRESH value is updated to 12 (that is, half of the congestion window value of 24 when timeout occurs), the congestion window is reset to 1, and the slow start algorithm is executed. whenCWND=ssthresh=12, the congestion avoidance algorithm is implemented, the congestion window grows linearly, and the size of MSS is increased by one round trip time.

Note: “Congestion avoidance” does not mean that congestion can be completely avoided. It is impossible to completely avoid network congestion with these measures. “Congestion avoidance” means that in the congestion avoidance stage, the congestion window is controlled to increase according to a linear law, so that the network is less prone to congestion.

How do you know network congestion? By monitoring packet loss, you can know whether network congestion occurs.

2.1.3. Fast retransmission (fast retransmit)

Receiver: send repeated acknowledgement as soon as it receives a packet out of order, so that the sender knows in time that a packet has not arrived, rather than waiting for their own data to be sent before confirmation.

The sender: If it receives three consecutive repeated acknowledgements (four identical acknowledgements in total), it immediately retransmits the unreceived segment of the packet without waiting for the retransmission timer to expire.

After the confirmation segment sent by M3 algorithm is lost, the sender continues to transmit M4, M5 and M6 datagrams, and the receiver confirms that the datagrams are sent back. The fast retransmission algorithm also stipulates that the sender should immediately retransmit the unreceived message segment M3 as long as it receives three consecutive repeated acknowledgements, instead of waiting for the expiration of the retransmission timer set by M3. Because the sender retransmits the unacknowledged segment as soon as possible, fast retransmission can improve the overall network throughput by about 20%.

2.1.4. Quick Recovery (fast recovery)

The process has the following two points:

  • When the sender receives three consecutive repeated acknowledgements, the multiplication reduction algorithm is performed to halve the slow start threshold SSTHRESH. This is to prevent network congestion. Please note: the slow start algorithm is not executed next.
  • Since the sender now believes that the network is most likely not congested, the difference from slow start is that instead of executing the slow start algorithm (i.e. the congestion window CWND is now not set to 1), instead, the CWND value is set to the value after the slow start threshold SSTHRESH has been reduced by half, and then the congestion avoidance algorithm (” add up “) is started. Causes the congestion window to grow slowly and linearly.

The diagram below shows fast retransmission and fast recovery, labeled “TCP Reno version.”

Some algorithms set the congestion window value for the initial retransmission to SSthRESH + 3 * MSS. The reason for this is that since the sender received three duplicate acknowledgements, three packets have left the network. These three packets no longer consume network resources but remain in the receiver’s cache. So instead of stacking up the groups, there are three fewer groups in the network. Therefore, the congestion window can be appropriately expanded.

When using the fast recovery algorithm, the slow start algorithm is used only when the TCP connection is established and the network times out.

The performance of TCP is improved obviously by adopting this congestion control method.

When the sender receives three consecutive repeated acknowledgements, the “multiplication reduction” algorithm is performed to halve ssthRESH, which is to prevent network congestion.

Because the sender now think that the Internet may well not congestion occurs, therefore, with the slow start the difference is now does not perform slow start algorithm, namely the CWND now don’t return to the initial value, but set CWND value for ssthresh halved after numerical, and then begin to execute congestion avoidance algorithm (” additive increase “), the linear in the congestion window slowly increase.

2.2. Summarize

  • The receiver sets the receiving window RWND according to its own receiving capability, writes the window value into the window field in the TCP header, and sends it to the sender. Therefore, the receiving window is also called the notification window. Therefore, from the perspective of traffic control by the receiver to the sender, the sending window of the sender must not exceed the receiving window RWND provided by the other party.
  • The upper limit of the sender windowswnd = Min(rwnd, cwnd)
  • whenrwnd < cwndIs the maximum value of the sender window of the receiving capability limit of the receiver.
  • whencwnd < rwndIs the maximum value of the network congestion limit sender window.

For more articles in this series, please pay attention to wechat official account [1024 Planet].