TCP flow control and congestion control, how they work in the scenario

TCP flow control

The so-called flow control is to prevent the sender from sending too fast so that the receiver can accept it in time. The sliding window mechanism can be used to easily control the flow of the sender on the TCP connection. The window unit of TCP is bytes, not segments. The sender's sending window cannot exceed the value of the receiving window given by the receiver.

As shown in the figure, flow control using variable window sizes is illustrated. Suppose host A sends data to host B. The window value determined by both parties is 400. Assume that each message segment is 100 bytes long, and the initial value of the sequence number is seq=1. The uppercase ACK above the arrow in the figure means that the header is considered to be ACK, and the lowercase ack means Confirm the value of the field.

The receiver's host B performs flow control three times. The first time the window is set to rwind=300, the second time it is reduced to rwind=100 and finally it is reduced to rwind=0, that is, the sender is not allowed to send any more data. This state that causes the sender to pause sending will continue until Host B resends a new window value.

Suppose that shortly after B sends a zero-window message segment to A, B's receive buffer has some storage space. So B sent a message segment with rwind=400 to A, but this message segment was lost during transmission. A has been waiting to receive the non-zero window notification sent by B, and B has been waiting for the data sent by A. This creates a deadlock. In order to solve this deadlock situation, TCP has a continuous timer for each connection. As long as one party of the TCP connection receives the zero window notification from the other party, it starts the continuous timer. If the time set by the continuous timer expires, it sends a zero window detection message segment (carrying only 1 byte of data), and the other party The current window value is given when confirming this detection segment.

Selection of timing for sending TCP segments

There are mainly the following options for TCP leopard short sending timing.

  1. TCP maintains a variable, which is equal to the maximum segment length MSS. As long as the data stored in the cache reaches MSS bytes, it is assembled into a TCP segment and sent out.
  2. The sender's application specifies the request to send the segment, which is the push operation supported by TCP.
  3. When a timer expires on the sender's side, the currently existing cached data is loaded into the message segment and sent out.

TCP congestion control

1. Principle of congestion control

At a certain period of time, if the demand for a certain resource in the network exceeds the available part that the resource can provide, the performance of the network will change. This situation is called congestion.

Network congestion is often caused by many factors. Simply increasing the speed of the node processor or expanding the storage space of the node cache cannot solve the congestion problem. For example: when the cache capacity of a node is expanded to a very large size, all packets arriving at the node can be queued in the node's cache queue without any restrictions. Since the capacity of the output link and the speed of the processor have not increased, the waiting time for most of the packets in this queue will be greatly increased. As a result, the upper layer software has to retransmit them.

Therefore, the problem often refers to the mismatch between various parts of the entire system. Only when the various parts are balanced can the problem be solved.

2. The difference between congestion control and flow control

The so-called congestion control is to prevent too much data from being injected into the network, so that the routers or links in the network will not be overloaded. There is a prerequisite for congestion control, which is that the network can bear the existing network load.

Flow control often refers to the control of point-to-point traffic, which is an end-to-end problem. What flow control has to do is to control the rate at which the sending end sends data so that the receiving end has time to accept it.

3.Congestion control design

Congestion control is difficult to design because it is a dynamic problem. In many cases, even the formal congestion control mechanism itself becomes the cause of network performance deterioration or even deadlock. From the perspective of control theory, congestion control can be divided into two methods: open-loop control and closed-loop control. Open-loop control means that all factors related to the occurrence of congestion are taken into consideration in advance when designing the network, and once the system is running, it cannot be corrected midway.

Closed-loop control is based on the concept of feedback loop and includes the following measures:

  1. Monitor network systems to detect when and where congestion occurs
  2. Send information about congestion occurrences to where action can be taken
  3. Adjust network system actions to resolve problems as they arise.

4.Congestion control method

The Internet recommended standard RFC2581 defines four algorithms for congestion control, namely slow start (Slow-start), congestion avoidance (Congestion Avoidance), fast retransmission (Fast Restrangsmit) and fast recovery (Fast Recovery). We assume

  1. Data is transmitted in one direction, while only confirmation is transmitted in the other direction.
  2. The receiver always has a large enough buffer space, because the size of the sending window is determined by the congestion level of the network.

Slow start and congestion avoidance

The determination of the rate at which message segments are sent must not only be based on the receiving capability of the receiving end, but also take into account the overall situation of not causing network congestion, which is determined by two status quantities: the receiving window and the congestion window. The receiver window (Reciver Window), also known as the Advertised Window, is the latest window value promised by the receiver based on the current receive buffer size, and is a flow control from the receiver. The congestion window cwnd (Congestion Window) is a window value set by the sending end based on its estimated network congestion level. It is a flow control from the sending end.

Slow start principle:

  1. When the host starts sending data, if all the data bytes of a larger sending window are immediately injected into the network, it may cause network congestion because it does not know the network situation.
  2. A better method is to test it out, that is, gradually increase the congestion control window value of the sender from a small arrival time.
  3. Usually, when you just start sending a message segment, you can first set the congestion window cwnd to the value of the MSS of the largest message segment. After each confirmation of a new segment is received, the congestion window is increased by up to one MSS value. When rwind is large enough, in order to prevent the growth of the congestion window cwind from causing network congestion, another variable is needed - slow Start threshold ssthresh

The specific process of congestion control is:

  1. TCP connection initialization, setting congestion window to 1
  2. Execute the slow start algorithm, and cwind will grow exponentially. When cwind == ssthress, the congestion avoidance algorithm will be executed, and cwnd will grow linearly.
  3. When network congestion occurs, update the ssthresh value to half of the ssthresh value before congestion, reset cwnd to 1, and follow step (2).

Fast retransmission and fast recovery

A TCP connection sometimes remains idle for a long time due to waiting for the retransmission timer to expire. Slow start and congestion avoidance cannot solve this kind of problem well. Therefore, the congestion control method of fast retransmission and fast recovery is proposed.

The fast retransmission algorithm does not cancel the retransmission mechanism, but retransmits the lost segment earlier in some cases (if the sender receives three repeated confirmation ACKs, it concludes that the packet is lost and retransmits it immediately Lost segments without waiting for the retransmission timer to expire). The slow start algorithm is only used when TCP is established

The fast recovery algorithm has the following two key points:

  1. When the sender receives three consecutive duplicate acknowledgments, it performs the "multiplicative reduction" algorithm and halve the slow start threshold. This is to prevent network congestion.
  2. Since the sender now believes that the network is probably not congested, it does not execute the slow start algorithm now. Instead, it sets the cwnd value to the value after the slow start threshold is halved, and then starts to execute the congestion avoidance algorithm, which is a linear increase of the congestion window. .

Meow Interview Assistant: A one-stop solution to interview questions. You can search the WeChat applet [Meow Interview Assistant]  or follow [Meow Interview Assistant] -> Interview Assistant to  answer questions for free. If you have any good interview knowledge or skills, I look forward to sharing them with you!

Guess you like

Origin blog.csdn.net/jjclove/article/details/127394118