TCP traffic control and congestion control

Source: Internet
Author: User

TCP traffic control

1. Implement traffic control using sliding windows

If the sender sends data too quickly, the receiver may not be able to receive the data, which may cause data loss. The so-calledTraffic ControlIt is to make the sender's sending speed not too fast, so that the receiver can receive it in time.

The sliding window mechanism can be used to conveniently control the traffic of the sender over TCP connections.

Set a to send data to B. When the connection is established, B tells a: "My receiving window is rwnd = 400" (here rwnd indicates the receiver window ). Therefore, the sender's sending window cannot exceed the value of the Receiving Window given by the receiver. Note that the unit of TCP window is byte, not the packet segment. The window negotiation process when a TCP connection is established is not shown in the figure. Set the length of each segment to 100 bytes, and the initial value of the serial number of the Data Segment to 1. The upper-case ack indicates the ACK in the header, and the lower-case ack indicates the ACK value of the validation field.

We can see that B has implemented three traffic control measures. The first time the window is reduced to rwnd = 300, the second time it is reduced to rwnd = 100, and the last time it is reduced to rwnd = 0, that is, the sender is not allowed to send data again. This will cause the sender to pause sending until host B resends a new window value. All three packet segments sent by B to a are set with ACK = 1, which is meaningful only when ACK = 1 is confirmed.

TCP provides a persistence timer for each connection ). As long as the TCP connection party receives the zero-window notification from the other party, the continuous timer is started. If the duration specified by the timer expires, a zero-window monitoring packet segment (with 1 byte of data) is sent. Then, the recipient of the packet segment resets the timer.

2. transmission rate must be considered

Different mechanisms can be used to control the transmission time of TCP packets. For example, <1>. TCP maintains a variable that is equal to the maximum message segment length (MSS. As long as the data in the cache reaches the MSS byte, it is assembled into a TCP packet segment and sent out. <2> the sender's application process specifies the request message segment, that is, the push operation supported by TCP. <3> when the sender's timer expires, the existing cached data is loaded into the message segment (but the length cannot exceed MSS) and sent out.

Nagle algorithm: if the sending application process sends the data to be sent byte by byte to the sending cache of TCP, the sender sends the First Data byte first, cache all the data bytes that will arrive later. After receiving the confirmation of the first data character, the sender assembles all the data in the sending cache into a packet segment and then sends it out. At the same time, the sender continues to cache the subsequent data. The next packet segment can be sent only after confirmation of the previous packet segment is received. When the data reaches a fast speed and the network speed is slow, this method can be used to significantly reduce the network bandwidth used. The Nagle algorithm also stipulates that when the incoming data reaches half of the size of the sending window or the maximum length of the packet segment, a packet segment is sent immediately.

In addition,Confused window comprehensive evidence:The cache of the TCP receiver is full, while the interactive application process only reads 1 byte from the receiving cache at a time (this makes the receiving cache space only 1 byte), and then sends confirmation to the sender, and set the window to 1 byte (if the sent datagram is 40 byte ). When receiving, the sender sends one byte of data (the sender's IP datagram is 41 bytes ). The receiver sends it back for confirmation. The window is still set to 1 byte. In this way, the network efficiency is very low. To solve this problem, the receiver can wait for a while, or the receiving cache has enough space to accommodate a maximum packet segment, or wait until the receiver cache has half of the free space. In either case, the receiver sends a confirmation message and notifies the sender of the current window size. In addition, the sender should not send too small packets, but accumulate the data packets into a sufficiently large packet segment, or reach half of the buffer space of the receiver.

 

TCP congestion control

1. Congestion: the demand for resources exceeds the available resources. If many resources in the network are insufficient at the same time, the network performance will deteriorate significantly, and the throughput of the entire network will decrease as the load increases.

Congestion Control:Prevent excessive data from being injected into the network, so that the routers or links in the network are not overloaded.There isPremise: the network can withstand the existing network load.Congestion Control isGlobal ProcessIt involves all hosts, routers, and all factors related to reducing network transmission performance.

Traffic control: point-to-point traffic control, which is an end-to-end positive problem. The purpose of traffic control is to suppress the sending speed of data so that the receiving end can receive the data in time.

Congestion Control Cost: You need to obtain information about the traffic distribution in the network. Before implementing congestion control, you also need to exchange information and various commands between nodes to select control policies and implement control. In this way, additional overhead is generated. Congestion Control also needs to allocate some resources to individual users so that network resources cannot be shared better.

2. Several Congestion Control Methods

Slow-start, congestion avoidance, fast retransmit, and fast recovery ).

2.1 slow start and congestion avoidance

The sender maintains a state variable of the congestion window cwnd (congestion window. The size of the congestion window depends on the degree of network congestion and is dynamically changing. The sender makes the sending window equal to congestion.

The principle of the sender's control over the congestion window is: as long as the network is not congested, the congestion window is increased to send more groups. However, as long as the network is congested, the congestion window is reduced to reduce the number of groups injected into the network.

Slow Start Algorithm: when the host starts to send data, if a large number of data bytes are immediately injected into the network, it may cause network congestion, because it is not clear about the network load. Therefore, a better method is to first test, that is, gradually increase the sending window from small to large, that is, gradually increase the congestion window value from small to large. Generally, when sending a packet segment, set the cwnd In the congestion window to the value of MSs in the Maximum packet segment. After receiving a confirmation message segment, the congestion window is increased to one MSS value. Using this method to gradually increase the sender's congestion window cwnd can make the packet injection rate to the network more reasonable.

 

Figure 5-24 the sender did not receive a confirmation and increased the window cwnd by a factor of 1.

 

The congestion window cwnd doubles every transmission round. The time that a transmission round goes through is actually the round-trip time RTT. However, the "transmission round" emphasizes that the packets allowed to be sent by the cwnd In the congestion window are continuously sent out, and the last byte that has been sent is confirmed.

In addition, the slow start does not mean that the growth rate of cwnd is slow, but that cwnd = 1 is set when TCP starts to send packets, this allows the sender to send only one packet segment at the beginning (to test network congestion) and then gradually increase the value of cwnd.

To prevent network congestion caused by excessive cwnd growth in the congestion window, you also need to set a slow start threshold ssthresh status variable (how to set ssthresh ). The usage of the slow start threshold ssthresh is as follows:

When cwnd <ssthresh is used, the preceding slow start algorithm is used.

When cwnd> ssthresh, stop using the slow start algorithm and use the congestion avoidance algorithm instead.

When cwnd = ssthresh, you can use either the slow start algorithm or the congestion control algorithm.

Congestion Avoidance algorithm: increases the cwnd of the congestion window slowly. That is, the cwnd of the sender is added to 1 rather than doubled every round-trip time. In this way, the congestion window cwnd increases slowly according to the linear law, which is much slower than the growth rate of the congestion window of the slow start algorithm.

No matter in the slow start phase or in the congestion avoidance phase, as long as the sender determines that the network is congested (the sender has not received confirmation ), set the slow start threshold ssthresh to half of the sender's window value when congestion occurs (but not less than 2 ). Then, set the congestion window cwnd to 1 and run the slow start algorithm. This aims to quickly reduce the number of groups that the host sends to the network, so that the congested router has enough time to process the backlog of groups in the queue.

For example, the above congestion control process is described with a specific value. The size of the current sending window is as large as that of the congestion window.

<1> when the TCP connection is initialized, set the congestion window cwnd to 1. As mentioned above, in order to facilitate understanding, the window unit in the figure uses the number of message segments instead of bytes. The initial value of the slow start threshold is 16 packet segments, that is, cwnd = 16.

<2> when the slow start algorithm is executed, the initial value of the cwnd In the congestion window is 1. After receiving a confirmation ack for the new packet segment, the sender sets the congestion window value to another 1 and starts the next transmission (in the figure, the X coordinate is the transmission round ). Therefore, the cwnd congestion window increases exponentially with the number of transmission rounds. When the cwnd threshold of the congestion window increases to ssthresh (when cwnd = 16), the congestion control algorithm is executed, and the congestion window increases linearly.

<3> if the number of congestion windows increases to 24, the network times out (this is probably because the network is congested ). The updated ssthresh value is changed to 12 (that is, half of the value of 24 in the congestion window when timeout occurs), the congestion window is reset to 1, and the slow start algorithm is executed. When cwnd = ssthresh = 12, the congestion avoidance algorithm is executed. The congestion window increases linearly, increasing the size of an MSS for each round-trip time.

Emphasize: "Congestion Avoidance" does not mean that congestion can be completely avoided. Using the above measures to completely avoid network congestion is still impossible. "Congestion Avoidance" means to control the congestion window to linear growth in the congestion avoidance phase,This makes the network less prone to congestion.

2.2 fast retransmission and fast recovery

If the time-out timer set by the sender has reached but has not been confirmed, it is likely that the network is congested, resulting in packet segments being discarded somewhere in the network. At this time, TCP immediately reduces the congestion window cwnd to 1, executes the slow start algorithm, and halved the slow start threshold ssthresh. This is the case where fast retransmission is not used.

The fast retransmission algorithm requires the receiver to send a duplicate confirmation immediately after receiving an out-of-order packet segment (in order to enable the sender to know that a packet segment has not arrived at the recipient) don't wait until you send the data.

After receiving m1 and m2, the recipient sends confirmation respectively. Now it is assumed that the receiver does not receive the M3 but then receives the M4. Obviously, the receiver cannot confirm M4 because M4 is the out-of-order message segment received. Based on the reliable transmission principle, the receiver can do nothing, or send a confirmation of M2 at an appropriate time. However, according to the rules of the fast retransmission algorithm, the receiver should promptly send duplicate validation of M2, so that the sender can know that the message segment m3 has not arrived at the receiver as soon as possible. The sender then sends M5 and M6. After receiving the two packets, the receiver also needs to repeat the message m2. In this way, the sender receives four m2. The last three are repeated. The fast retransmission algorithm also stipulates that as long as the sender receives three repeated confirmations in a row, it should immediately re-transmit the message segment m3 that the recipient has not yet received, instead of waiting for the retransmission timer set by the M3 to expire. Because the sender retransmits unconfirmed packets as soon as possible, the network throughput can be increased by about 20% after fast retransmission.

The fast recovery algorithm is used in combination with fast retransmission. The process involves the following two key points:

<1> when the sender receives three repeated confirmations in a row, the "Multiplication and reduction" algorithm is executed to halved the slow start threshold ssthresh. This is to prevent network congestion. Note: Do not run the slow start algorithm.

<2>. because the sender thinks that the network is likely not congested, the difference from the slow start is that the slow start algorithm is not executed now (that is, the congestion window cwnd is not set to 1 now ), instead, the cwnd value is set to the value after the ssthresh threshold is halved, and the congestion avoidance algorithm ("addition increase") is executed, so that the congestion window increases linearly slowly.

Provides fast retransmission and fast recovery, and indicates the "TCP Reno version ".

Difference: the New TCP Reno version uses the fast recovery algorithm after fast retransmission instead of the slow start algorithm.

 

Some fast retransmission Methods increase the value of cwnd In the congestion window at the beginning, that is, ssthresh + 3 x MSS. The reason for doing so is: Since the sender receives three repeated confirmations, it indicates that three groups have left the network. These three groups no longer consume network resources but stay in the recipient's cache. It can be seen that the network does not accumulate groups, but reduces three groups. Therefore, we can expand the congestion window.

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

This congestion control method is used to significantly improve TCP performance.

The receiver sets the Receiving Window rwnd based on its own receiving capability, writes the window value to the window field in the TCP header, and sends it to the sender. Therefore, a receiving window is also called a notification window. Therefore, from the perspective of the receiver's traffic control over the sender, the sender's sending window must not exceed the receiver's rwnd.

Upper Limit of the sender window = min [rwnd, cwnd]

When rwnd <cwnd, the receiving capacity of the receiver limits the maximum value of the sender's window.

When cwnd <rwnd, network congestion limits the maximum value of the sender's window.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.