Home >Common Problem >What is the main difference between flow control and congestion control?
The main difference: flow control solves the problem of rate mismatch between the sender and the receiver; congestion control solves the problem of avoiding network resource exhaustion. Flow control is implemented through sliding windows; congestion control is implemented through congestion windows.
The operating environment of this tutorial: Windows 7 system, Dell G3 computer.
Related recommendations: "Programming Teaching"
The difference between flow control and congestion control
TCP flow control and congestion control seem to be two relatively similar concepts, which are easy to cause confusion. But in fact, their desired goals and methods are completely different.
Flow control solves the problem of rate mismatch between the sender and the receiver. If the sender sends too fast, the receiver will not have time to receive and process it. The mechanism used is a sliding window mechanism, which controls the number of packets that are sent but not Acked.
Congestion control solves the problem of preventing network resources from being exhausted. By taking self-disciplined avoidance measures, everyone can avoid the exhaustion of limited network resources. When packet loss occurs, the sending rate is controlled to reduce network load.
Flow control
The window size remains unchanged during a specific connection communication process. The sliding window is a mechanism. The size of the sliding window represents the size of the data that can be sent at the sending end, and the size of the data that can be received at the receiving end. They change dynamically.
Congestion control
During the congestion avoidance phase, the process of linear increase after exceeding the limit size, and the process of changing the congestion window to 1 and halving the limit size after discovering packet loss.
Extended information
Flow control is end-to-end control. For example, A sends data to B through the network. Data A sends too fast and B cannot receive it (B buffer window is too small or the processing is too slow). The control at this time is flow control, and the principle is achieved by changing the size of the sliding window.
Congestion control is when the network between A and B is blocked, resulting in too slow transmission or packet loss, and there is no time for transmission. Preventing too much data from being injected into the network prevents routers or links in the network from being overloaded. Congestion control is a global process that involves all hosts, routers, and all factors related to reducing network performance.
Flow control mechanism:
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, the initial value of the sequence number is seq=1, uppercase ACK indicates that the header is considered to be ACK, and lowercase ack indicates the value of the confirmation field.
The receiver’s host B has performed 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 receiving 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.
Congestion control mechanism:
Slow start and congestion avoidance
The determination of the rate of sending message segments must be based on the receiving capability of the receiving end and the overall consideration of not causing network congestion. This is determined by the two status quantities of 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 the larger sending window are immediately injected into network, then because the network situation is not clear, it may cause network congestion
2) A better way is to test it, that is, gradually increase the congestion control window value of the sender from a small arrival
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—the slow start threshold. ssthresh
The specific process of congestion control is:
1) TCP connection initialization, set the congestion window to 1
2) Slow execution Start the algorithm, cwind grows exponentially, until cwind == ssthress starts executing the congestion avoidance algorithm, cwnd grows linearly
3) When congestion occurs in the network, 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 becomes idle for a long time due to waiting for the retransmission timer to expire. Slow start and congestion avoidance cannot solve this problem well. problem, therefore a congestion control method with fast retransmission and fast recovery is proposed.
The fast retransmission algorithm does not cancel the retransmission mechanism, but retransmits the lost message segment earlier in some cases (if the sender receives three repeated confirmation ACKs, it is concluded that If a packet is lost, the lost segment will be retransmitted immediately 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 confirmations, it executes 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 executing the congestion avoidance algorithm. , causing the congestion window to linearly increase.
Summary:
The first two algorithms are used before congestion occurs, and the latter two algorithms are used after congestion occurs (that is, three repeated confirmations).
If you want to read more related articles, please visit PHP Chinese website! !
The above is the detailed content of What is the main difference between flow control and congestion control?. For more information, please follow other related articles on the PHP Chinese website!