TCP timeout retransmission mechanism and congestion avoidance _ timeout retransmission

Source: Internet
Author: User
Tags ack

TCP timeout and retransmission mechanism
  
TCP protocol is a reliable transmission layer protocol for connection, which guarantees the reliable transmission of data, and the timeout and retransmission mechanism of TCP design for some problems such as error, time lost and so on. The basic principle: After sending a data, it opens a timer, if in this time does not receive send the data ACK acknowledgement message, then carries on the retransmission to this message, when achieves certain number of times has not succeeded to give up and sends a reset signal.
What is more important here is the retransmission timeout, how to set the timer time (RTO), so as to ensure the minimum network resources waste. Because if the RTO is too small, some messages may simply encounter congestion or bad network latency, which can cause unnecessary retransmission. Too large, so that the sender needs to wait too long to find data loss, affecting network transmission efficiency.
Because different network conditions are not the same, it is not possible to set the same RTO, in fact, RTO is based on the RTT (transport round-trip time) in the network from adaptation. The specific relation reference correlation algorithm.
To understand the retransmission mechanism through graphs:
 

As you can see from the diagram, the sender sends 3 packets continuously, in which the second is lost, is not received, so will not return the corresponding ACK, did not send a packet, start a timer, when the second packet timer overflow has not received an ACK, then the retransmission.

TCP Slow start

Slow start is a TCP congestion control mechanism, the basic idea of the slow start algorithm is that when TCP begins to transmit data in a network or discovers data loss and begins to resend, it first slowly tests the actual capacity of the network to avoid blocking due to excessive data being sent.
Slow start adds another window to the sender's TCP: The Congestion window (congestion windows), recorded as CWnd. When a TCP connection is established with a host on another network, the congestion window is initialized to 1 message segments (that is, the message segment size of the other end). Each time an ACK is received, the Congestion window adds a message segment (CWnd in bytes, but the slow start increases in the size of the message segment). The sender takes the minimum value in the Congestion window and the notification window as the sending limit. The Congestion window is the traffic control used by the sender, while the notification window is the traffic control used by the receiver. Sends a message segment at the beginning of the sender and waits for an ACK. When the ACK is received, the congestion window increases from 1 to 2, which means that two message segments can be sent. When a C K is received for these two segments, the congestion window increases to 4. This is an exponential increase in the relationship.

Congestion avoidance algorithm

Congestion in the network can result in the loss of data packets and should be avoided as far as possible. In practice, congestion algorithms are usually implemented together with slow start, and the basic process is:
1. For a given connection, initialize the CWnd to 1 message segments and Ssthresh to 65,535 bytes.
2. The output of the TCP output routine cannot exceed the size of the CWnd and the receiver notification window. Congestion avoidance is the traffic control used by the sender, while the notification window is the flow control carried out by the receiving party. The former is an estimate of the network congestion that the sender feels, and the latter is related to the available cache size of the receiver on the connection.
3. When congestion occurs (timeout or receive a duplicate acknowledgment), the Ssthresh is set to half the current window size (CWnd and the receiver notices the minimum size of the window, but at least 2 message segments). In addition, if the timeout causes congestion, the CWnd is set to 1 segments (this is the slow start).
4. When the new data is confirmed by the other side, increase the CWnd, but the increased method depends on whether the slow start or congestion avoidance. If the CWnd is less than or equal to Ssthresh, a slow start is underway or congestion avoidance is in progress. The slow start continues until half of the time the congestion occurs (because it records half the size of the window that created the trouble in Step 2), and then to perform congestion avoidance.
The slow start algorithm initially sets the CWnd to 1 message segments and then adds 1 to each confirmation. That way, this causes the window to grow exponentially: Send 1 message segments, then 2, then 4 ...

In this diagram, it is assumed that congestion occurs when CWnd is 32 segments. The Ssthresh is then set to 16 message segments, and CWnd to 1 segments. At the moment 0 sends a message segment and assumes that at the moment 1 receives its ACK, at which point the CWnd increases to 2. The 2 message segments are then sent and assumed to receive their ACK at the moment 2, so the CWnd is increased to 4 (1 times for each ACK). This exponential increase algorithm has been carried out until the time between 3 and 4 received 8 ack CWnd equals Ssthresh to stop, from this moment, CWnd to increase linearly, in each round-trip time up to 1 message segments.

Fast retransmission and fast recovery algorithm

This is a patching mechanism given in case of packet loss. In general, retransmission occurs after a timeout, but if the sender receives more than 3 duplicate ACK (the second packet in the image above is lost and receives two identical ack=11), it should be aware that the data is missing and needs to be transferred again. This mechanism does not need to wait for the retransmission timer to overflow, so it is called a fast retransmission, which avoids the sending end to increase network throughput by waiting for a long time for the retransmission timer to be idle. After the transfer, because it is not slow to start but congestion avoidance algorithm, so this is called the Fast Recovery algorithm. The algorithm flow is as follows:
1. When the 3rd duplicate ACK is received, the Ssthresh is set to half the current congestion window CWnd. Retransmission of missing message segments. Set CWnd to Ssthresh plus 3 times times the message segment size.
2. Each time another duplicate ACK is received, CWnd increases the size of 1 segments and sends 1 groupings (if the new CWnd allows to be sent).
3. When the next ACK to confirm new data arrives, set CWnd to Ssthresh (the value set in step 1th). This ACK should be a confirmation of the retransmission in step 1 during a round-trip time after the retransmission. Additionally, this ACK should be a confirmation of all intermediate segments between the lost packet and the 1th repeated ACK received.
  
More references:
Http://baike.baidu.com/link?url=BNBotLOFxb1ReNROQGeqFZdpoSb8MbBJoY_P1xFMK6Qt7oDCBXLynprYbTrMf2fjk4YMMuAv-NJPo2Y1YpjWz_

TCP as a block data stream

Reference: TCP's block data stream

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.