Protocol forest 10 devil details (TCP Sliding Window Management)

Source: Internet
Author: User

Author: vamei Source: http://www.cnblogs.com/vamei welcome reprint, please also keep this statement. Thank you!

 

In TCP communication with "stream", we have established the basic concept of sliding window. Through the combination of sliding windows and ACK, we have achieved the reliability of TCP transmission, and also improved the efficiency to a certain extent. The working method is shown in the following video:

If there is a problem with video loading, click the link below: http://v.youku.com/v_show/id_XNDg1NDUyMDUy.html

However, the previous explanation is only conceptual. In order to achieve better transmission efficiency, TCP has made many improvements to the above working method.The dedevil is in the details.We need to go deep into the details to understand the wisdom of TCP.

 

Accumulated ACK

In TCP connections, we use ack Reply to "Attach" other data fragments to reduce the traffic consumed by ack reply. But this is not all the story. TCP does not send ACK replies to each segment. What is TCP actually used?Accumulative acknowledgement). The receiver often uses an ACK to notify the successful receipt of multiple consecutive fragments. By accumulating ACK, the required ack replies can usually be reduced to 50%.

As shown in, orange indicates the received part. The box contains sliding windows, which can contain 3 segments.

Accumulated ACK

 

When the Sliding Window does not receive segment 7, it receives Segment 8 and 9. In this way, a hole is created in the sliding window ). When the Sliding Window finally receives segment 7, the sliding window sends an ACK reply with the reply number 10. The sender receives the response and realizes that the fragments before segment 10 have been successfully received in order. The whole process saves two ack replies required for segment 7 and Segment 8.

In addition, when the receiver receives the part and replies to ACK, it will intentionallyLatencySome time. If a later segment arrives during the delay, you can use the accumulated ack to reply together.

 

Sliding Window Structure

In the previous discussion, we used fragments to measure the size of sliding windows. The real sliding window isIn bytesIndicates the size, but this does not have a big impact on our previous discussions.

SenderSliding windows can be divided into the following two parts.Offered windowThe size of the sliding window.

 

ReceiverSliding windows can be divided into three parts:

 

As you can see, the receiver's sliding window has one more than the sender's sliding window."Received; acked; not sent to proc". The text stream received by the receiver must wait.Process. If the process is busy with other tasks, these text streams must temporarily occupy the receiving cache even if they are correctly received. When the above usage occurs, the available part of the sliding window (that is, the figure below)Advertised window. This means that the processing capability of the receiver is reduced. If the sender still sends data to the receiver at the previous rate, the receiver will not be able to receive the data.

 

Traffic Control

The TCP protocol automatically changes the hop window size as needed to achieve traffic control.Flow Control)Indicates that the receiverSize of the advertised windowNotify the sender to instruct the sender to modify the offered window size. The receiver places this information in the TCP HeaderWindow SizeRegion:

When receiving the window size notification, the sender adjusts the size of the sliding window to make the offered window consistent with the advertised window. In this way, the sending window decreases, and the text stream transmission rate decreases, thus reducing the burden on the recipient.

 

Zero Window

The size of the advertised window may change0This means that the recipient's receiving capacity is reduced to 0. When the sender receives an advertised window notification with a size of 0,Stop sending.

Zero Window

When the receiver is processed and an available advertised window is generated again, the receiver will notify the sender through a pure ack reply, so that the sender can resume sending. However, Ack reply transmission is not reliable. If the ACK reply is lost, TCP transmission will be in the Deadlock State.

Therefore, the sender continuously detects the receiver's window after the Zero Window.Window Probe)The sender sends a TCP segment containing a 1 byte text stream to the receiver and waits for an ACK response (the ACK response contains window size ). Because 1 byte of data exists, the transmission is reliable without worrying about ack reply loss. If the display window of the test result is still 0, the sender willWait for a longer timeAnd then perform a window test again until the TCP transmission recovers.

 

Idiot window syndrome

Sliding Window Mechanism may cause illness, suchSilly window syndrome). Assume that the receiver announces a small window (advertise) and the sender sends a small segment based on the advertised window. The receiver's small window is filled. After processing, the receiver announces a small window ...... This is "idiot window syndrome ":The TCP communication segment contains a small amount of data.. In this case, the information contained in the TCP communication segment is very small, and the network traffic is mainly the header of the TCP segment, resulting in a waste of traffic (because the TCP header is very large, we want each TCP segment to contain more data ).

 

If the sender keeps sending small fragments, it will also create an "idiot window ". To solve this problem, we need to start from two aspects. TCP has related rules and requirements:

1. The window advertised by the receiver must be of a certain size; otherwise, wait.

2. Except for some special cases, the size of the clip sent by the sender must reach a certain size; otherwise, wait. In special cases, it mainly refers to TCP applications that need to minimize latency (such as command line interaction ).

 

Summary

Accumulated ack reduces the ACK traffic required during TCP transmission. Through traffic management, the working capabilities at both ends of the TCP connection can be matched to reduce unnecessary transmission waste. Both ack and traffic control are important features of TCP.

The TCP protocol is quite complex and full of details. However, TCP is such an important protocol that has led the Internet for thirty years. These details are the reason for the success of the TCP protocol and deserve our in-depth understanding.

 

Welcome to the "protocol Forest" Series

 

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.