The bandwidth in the computer network, the cache and the processing machine in the Exchange node are all the resources of the network. At some point in time, the performance of the network becomes worse if the demand for a resource in the network exceeds the available parts that the resource can provide. This situation is called congestion.
Congestion control is to prevent too much data from being injected into the network, so that routers or links in the network are not overloaded. Congestion Control is a global process, and flow control is different, traffic control pointing to point traffic control.
2. Slow start and congestion avoidance
The sender maintains a state variable called the congestion window CWnd (congestion Windows) . The size of the congestion window depends on the degree of congestion of the network and is dynamically changing. The sender makes its sending window equal to the Congestion window, and the sending window may be smaller than the congestion window, taking into account the receiver's ability to receive.
The idea of a slow start algorithm is not to send a large amount of data at the beginning, first to detect the network congestion, that is, from small to large gradually increase the size of the congestion window.
Here is an example of the congestion window size using the number of message segments to illustrate the slow start algorithm, in which the real-time congestion window size is measured in bytes. Such as:
Of course, a single acknowledgment is received, but when this confirms multiple datagrams, the corresponding values are added. Therefore, the congestion window doubles after a single transmission round. This is the multiplication growth, and the subsequent congestion avoidance algorithm increases the addition growth comparison.
A slow-start threshold ssthresh state variable is also required to prevent the increase in CWnd from causing network congestion. The usage of Ssthresh is as follows:
When Cwnd<ssthresh, the slow start algorithm is used.
When Cwnd>ssthresh, the congestion avoidance algorithm is used instead.
When Cwnd=ssthresh, slow starts with congestion avoidance algorithm arbitrary.
Congestion avoidance algorithms allow congestion windows to grow slowly, that is, each time a round trip is taken, the congestion window of the sender is added 1, not doubled. This congestion window grows slowly in linear order.
Either in the slow-start phase or in the congestion avoidance phase , as long as the sender determines that the network is congested (which is based on the fact that no acknowledgement is received, although there is no acknowledgement that the packet is missing for another reason, it is handled as congestion because it cannot be determined), Set the slow start threshold to half the size of the sending window when congestion occurs. Then set the congestion window to 1 and execute the slow start algorithm. Such as:
Again, this is just for the sake of discussion. Instead of changing the size of the congested window to the number of datagrams, it should actually be bytes.
3. Fast retransmission and fast recovery
Fast retransmission requires the receiving party to issue a duplicate acknowledgement immediately after receiving an out-of-sequence message segment (in order for the sender to know earlier that a message segment has not arrived) and not wait for the sender to confirm when sending the data itself. The fast retransmission algorithm stipulates that the sender should immediately retransmit a message segment that has not yet been received, without having to wait for the set retransmission timer time to expire, as long as it receives three duplicate confirmations in a row. Such as:
Fast re-transmission with the use of fast recovery algorithm, there are the following two points:
① when the sender receives three duplicate confirmations consecutively, the "multiplication reduction" algorithm is executed, and the ssthresh threshold is halved. However, the slow-start algorithm is not executed next.
② Considering that if the network is congested, it will not receive several duplicate confirmations, so the sender now thinks the network may not be congested. Therefore, the slow start algorithm is not executed at this time, but the CWnd is set to the size of Ssthresh and then the congestion avoidance algorithm is executed. Such as:
4. Random Early detection red
The above congestion avoidance algorithm is not associated with the network layer, in fact, the network layer strategy of congestion avoidance algorithm is the biggest impact of the router's discard strategy. In simple cases, routers usually process incoming groupings in the first-in, FIFO strategy. When the router's cache is not grouped, it discards the incoming packet, which is called the trailing discard policy. This results in packet loss and the sender considers the network to be congested. What is more serious is that there are many TCP connections in the network, and the segment of the packets in these connections is usually the multiplexed routing path. In the event of a trailing drop of the router, many TCP connections can be affected, and the result is that many TCP connections enter a slow-start state at the same time. This is referred to as global synchronization in the terminology. Global synchronization causes a sudden drop in network traffic, and after the network returns to normal, its traffic suddenly increases a lot.
To avoid global synchronization in the network, routers use random early detection (red:randomearly detection). The algorithm points to the following:
The queue of the router maintains two parameters, that is, the queue is the longest gate limit min and Max, whenever a packet arrives, Red calculates the average queue length. Then treats the coming groupings in a separate situation:
The average queue length of ① is less than the minimum threshold--queues the newly arrived packets into a queue.
② average queue Length between the minimum and maximum threshold-the packet is discarded according to a probability.
③ average queue Length is greater than maximum threshold-discards newly arrived groupings.
Randomly discarding packets with probability p allows congestion control to be performed only on individual TCP connections, thus avoiding global congestion control.
The key to red is to select three parameter minimum threshold, gate limit, drop probability and calculate average queue length. The average queue length uses the weighted average method to calculate the average queue length, which is the same as the round trip Time (RTT) calculation strategy.
Congestion control of TCP