What is TCP congestion control algorithm?

Recently spent some time in learning TCP / IP protocol, the primary reason is because of my long-standing knowledge of TCP / IP three-way handshake would be limited to four times the break, so I hope a closer look. In addition, TCP / IP and Linux system-level design can be used on many middleware system architecture, such as TCP congestion control algorithms can also be used on middleware response time to the current limit. A deeper level, such as basic knowledge of the principles and techniques TCP / IP protocol, are to undergo the test of time, the crystallization of the wisdom of their predecessors, can give you a lot of inspiration and help.

This article will appear in some abbreviations, because of space problems, not each explain, if you do not understand its meaning, please go to their own search to understand, seek to make a person's knowledge.

TCP protocol has two more important control algorithm is a flow control, congestion control is another.

TCP protocol flow control is performed by a sliding window, which is a control transmission rate of the sender so that the recipient had time to receive and process. Congestion Control of the overall network, which is to prevent excessive packets are sent to the network, to avoid excessive network load, network congestion occurs.

Congestion algorithm needs to grasp the state machine and the four algorithms . Congestion control state machine has five states, namely: "Open, Disorder, CWR, Recovery and Loss status" . Four algorithm ** "slow start, congestion avoidance, and fast recovery algorithm when congestion occurs." **.

Congestion Control State Machine

And, like TCP congestion control algorithm has its state machine. When the sender receives an ACK, Linux TCP state machine is determined by its subsequent conduct, it should reduce the congestion window size cwnd, cwnd or remain unchanged, or continue to increase cwnd. If not handled properly, it could lead to loss or timeout.

1, Open state

Open state is the default state of congestion control state machine. In this state, when the ACK arrives, the sender according to the congestion window cwnd (Congestion Window) is less than or greater than the slow start threshold ssthresh (slow start threshold), according to slow start or congestion avoidance algorithm for adjusting the congestion window.

2, Disorder status

When the sender detects the DACK (duplicate acknowledgment), or the SACK (selective acknowledgment), the state machine transitions to state Disorder. In this state, the sender follows the flight (in-flight) packet conservation principle that a new packet is sent only after an old packet off the network, that is, after the old sender receives the ACK packet, it will then send a The new package.

3, CWR state

Sender receives a congestion notification display, and will not immediately decrease the congestion window CWnd, but each received a two ACK segment is reduced, until the window size is halved so far. When the cwnd and the network is reduced when there is no retransmission packet, this condition is called the CWR (Congestion Window Reduced, congestion window reduced) state. CWR state or may be converted into Loss Recovery state.

4, Recovery state

When the sender receives enough (recommended three) of DACK (duplicate acknowledgment) after entering the state. In this state, the congestion window for each received two ACK cnwd a reduced segment (segment), until cwnd ssthresh equal to ssthresh, cwnd is just entering Recover state when half the size. Recovery sender to keep the status until all the data segments are sent when entering the Recovery state have successfully confirmed, then restore the sender to the Open state, retransmission timeout may be interrupted Recovery state, enter Loss status.

5, Loss status

When a the RTO (retransmission timeout) expires, the sender enters Loss state. All data tags being sent is lost, the congestion window cwnd to one segment (segment), the sender again slow start algorithm to increase the congestion window cwnd.

Loss Recovery state and the difference is: Loss Under state, the congestion window is set to the sender after a segment increases, down Recovery state, the congestion window can only be reduced. After Loss state can not be interrupted by other state, therefore, the data sender only when all start being transmitted Loss of success have been confirmed to Open retreated state.

Four algorithms

Congestion control algorithms are mainly four:

1) slow start;

2) congestion avoidance;

3) congestion occurs;

4) fast recovery.

This is not one out of the four algorithms are engaged in, this Development IV algorithm has experienced a lot of time, and today are still optimization.

Slow start algorithm - Slow Start

The so-called slow start, which is just a TCP connection is established, little by little speed, to test the capacity of the network, so as not to disrupt the order directly to the network channel.

Slow start algorithm :

  1. Connecting the start built congestion window cwnd size initialized to 1, indicating that the MSS can transmit a data size.

2) whenever a received ACK, cwnd size plus one, increases linearly.

3), each time after a round trip delay time RTT (Round-Trip Time), cwnd size is directly doubled, multiplied by 2, increases exponentially.

4), there is a ssthresh (slow start threshold), is an upper limit, when cwnd> = ssthresh, they will enter the "congestion avoidance algorithm" (later would say this algorithm).

Congestion avoidance algorithm - Congestion Avoidance

As said front, when the congestion window size cwnd is larger than ssthresh equal to ssthresh, enters the congestion avoidance algorithm. Algorithm is as follows:

1), a received ACK, the cwnd = cwnd + 1 / cwnd.

2), each time after a round trip delay time RTT, cwnd size plus one.

After a slow start threshold, congestion avoidance algorithm to avoid congestion window window leading to excessive growth, but slow increase in the value of the optimum adjustment to the network.

Algorithm congestion state

Typically, the default TCP congestion control considers the network packet loss due to network congestion caused, it is generally the TCP congestion control algorithm signal loss into the network congestion status. There are two ways to packet loss determining a retransmission timeout RTO [Retransmission Timeout] expires, another three duplicate acknowledgments were received ACK.

Retransmission timeout TCP protocol is an important mechanism to ensure data reliability, the principle is sending data after it is turned on a timer, if not ACK packet sent datagrams, then resend the data within a certain period of time, until sent successfully.

However, if the sender receives three or more duplicate ACK, TCP realized that data is lost, needs to be retransmitted. This mechanism does not need to wait until the retransmission timer expires, so called fast retransmit without using fast retransmit after the slow start algorithm, but congestion avoidance algorithm, so this is also called fast recovery algorithm.

Retransmission RTO [Retransmission Timeout] Timeout, TCP retransmits packets. TCP believes this situation relatively poor, relatively strong reaction:

  • Since the loss occurs, the slow start threshold ssthresh is set to half the current cwnd, i.e. ssthresh = cwnd / 2.

  • cwnd is reset to 1

  • Enter slow start

Most early TCP Tahoe algorithm on the use of the above approach, but due to a loss on all over again, leading to cwnd is reset to 1, is not conducive to the stability of the data transfer network.

Therefore, TCP Reno algorithm is optimized. Upon receipt of three duplicate acknowledgments ACK, TCP Fast Retransmit open fast retransmit algorithm, without waiting for the RTO retransmission timeout and then:

  • cwnd size is reduced to half the current

  • cwnd ssthresh is set to the size of the reduced

  • Then enter the fast recovery algorithm Fast Recovery.

Fast recovery algorithm - Fast Recovery

TCP Tahoe early algorithms, so there is no fast recovery algorithm, and Reno algorithm. Before entering the fast recovery, cwnd and ssthresh has been changed to half of the original cwnd. Logic fast recovery algorithm is as follows:

  • cwnd = cwnd + 3 * MSS, plus 3 * MSS reason is due to the receipt of three duplicate ACK.

  • DACKs retransmission packet specified.

  • If you receive DACKs, then increase the size of a cwnd.

  • If you receive a new ACK, it indicates that the retransmission of the packet is successful, then the exit fast recovery algorithm. The cwnd is set to ssthresh, then enter the congestion avoidance algorithm.

As shown, the fifth packet loss occurs, resulting in the recipient receives the ACK is repeated three times, i.e. ACK5. So the ssthresh set to cwnd half the time, that is 6/2 = 3, cwnd is set to 3 + 3 = 6. Then retransmits the fifth package. When you receive a new ACK, is ACK11, exit fast recovery phase, will be re-set to the current cwnd ssthresh, which is 3, and then enter the congestion avoidance algorithm stage.

postscript

This article describes some of the mechanisms we generally TCP congestion control, congestion control, but they still have a lot of flaws and place to be optimized, the industry also has introduced a new congestion control algorithms, such as Google's BBR. We will continue to explore these follow-up, please continue to pay attention.

Written in the last:

No. I welcome everyone's attention the public opening of the new [ calm as code ], mass Java-related articles, learning materials will be updated on the inside, finishing materials will be on the inside.

I feel good to write on a point of praise, plus followers chant! Point of attention, do not get lost, continuously updated! ! !

Guess you like

Origin juejin.im/post/5e73249bf265da573c0c9912