[TCP/IP explanation: Study Notes] TCP Timer

Source: Internet
Author: User

For each TCP connection, TCP manages four different timers:

    1. Retransmission timer is used when you want to receive confirmation from the other end. If no confirmation is received when the timer overflows, the TCP connection retransmits the data;
    2. Insist that the timer is the window size information to keep flowing, even if the other end closes its receiving window;
    3. The retention timer can detect when the other end of an idle connection crashes or restarts;
    4. 2 MSL Timer measures the time when a connection is in the time_wait state.

 

TCP timeout and retransmission

The important part of TCP timeout and retransmission is to measure the round-trip time (RTT) of a given connection, and change the timeout time through RTT changes.

 

Congestion preventionAlgorithmAnd slow start algorithms are two different and independent algorithms. However, when congestion occurs, you can call slow start to reduce the transmission rate of the group into the network.

The congestion avoidance algorithm and the slow start algorithm need to maintain two variables for each TCP connection:

    1. Congestion window cwnd;
    2. Slow Start threshold ssthresh;

 

Working Process of algorithm Congestion Avoidance:

    1. For a given connection, the initial cwnd is a packet segment, and the ssthresh is 65535 bytes;
    2. The output of TCP output history cannot exceed the size of the cwnd and receiver announcement window. Congestion avoidance is the estimation of network congestion felt by the sender, and the announcement window is related to the available cache size of the receiver on the Link;
    3. When congestion occurs (timeout or repeated confirmation is received), ssthresh is set to half of the current window size (cwnd and the receiver pass through the minimum window size, but at least one packet segment. In addition, if timeout causes congestion, cwnd is set to 1 packet segment (that is, slow start );
    4. Cwnd is added when the new data is confirmed by the other party, but the method to be added depends on whether or not the data is being started slowly or congested. If cwnd is less than or equal to ssthresh, a slow start is underway; otherwise, congestion is being avoided. Slow Start continues until we return to the half of the congestion sending location, and then changes to congestion avoidance.

 

Quick Algorithm recovery:

    1. When 3rd duplicate ACK packets are received, set ssthresh to half of the cwnd in the current congestion window. Retransmission of the lost packet segment. Set cwnd to ssthresh and multiply the packet segment size;
    2. When receiving another duplicate ACK, cwnd increases the size of one segment and sends one group (if the new cwnd can be sent );
    3. When the next ack confirms that the new data arrives, set cwnd to ssthresh. This ack should be used to confirm the re-transfer in step 1 within a round-trip time after retransmission.

 

It is no longer in the slow start state, but in the congestion avoidance state. The new cwnd value is calculated as follows:

 

 

The most common ICMP errors that TCP can encounter are Origin Site suppression, host unavailability, and network unavailability.Berkeley-based implementation handles these errors:

    1. When a connection receives the suppression from the source station, the congestion window cwnd is set to the size of one packet segment to send the slow start, but the slow start threshold ssthresh remains unchanged, therefore, the window will open until it opens all the channels (limited by the window size and the round-trip time) or congestion occurs;
    2. When a connection receives an inaccessible host or network, it is ignored.

 

When TCP times out and re-transmits packets, TCP allows grouping and sending a large packet segment, which helps improve performance. This method is allowed in the protocol, because TCP uses byte numbers instead of segment numbers to identify the data to be sent and confirm.

 

TCP persistence Timer

 

If a confirmation is lost, the two parties may terminate the connection because they are waiting for the other party: the receiver is waiting to receive data, and the sender is waiting for a window update that allows it to continue sending data. To prevent this deadlock, the sender uses a persistence timer to periodically query the receiver so as to check whether the window has increased.

 

IfConfused window syndrome SWS Phenomenon, Then a small amount of data will be exchanged through the connection, rather than the full length of the packet segment. Take measures at any end to avoid confusion window syndrome:

    1. The recipient does not notice a small window. The common algorithm is that the receiver does not advertise a window larger than the current window (which can be 0), unless the window can increase the size of a packet segment (that is, the MSS to be received) alternatively, you can increase the size of the receiving cache window by half, regardless of the actual size;
    2. The sender can avoid confusion window syndrome by sending data only when one of the following conditions is met:
      • A full-length packet segment can be sent;
      • It can send at least half the size of the receiver's announcement window;
      • You can send any data and do not want to receive ACK or use the Nagle algorithm on the connection.

TCP retention Timer

The server uses the TCP retention timer to check whether the client host crashes, shuts down, crashes, and restarts. For example, if the client disappears, leaving a semi-open connection on the server while the server is waiting for data from the customer, the server will always wait.The alive function is to help the server to detect this semi-open connection..

 

If a given connection does not take any action within two hours, the server is like a client sending a probe packet segment.The client host must be in one of the following four States:

    1. the client host still runs normally and is accessible from the server . That is, the customer's TCP response is normal, and the server knows that the other party is working normally. The server will reset the timer after two hours. If the Program is used to exchange data with the server within these two hours, the timer will reset the timer in the next two hours after the data is exchanged;
    2. the client host has crashed and is disabled or is restarting . In any case, the customer's TCP does not respond, the server will not be able to receive a response to the probe, and timeout in 75 seconds.
    3. the client host crashes and has been restarted . At this time, the server will receive a response to the probe, but the response is a reset, causing the server to terminate the connection;
    4. the client host runs normally, but the slave server is inaccessible . It is the same as status 2 because TCP cannot distinguish between status 2 and status 4. What it can find is that it does not receive the probe response.
Related Article

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.