[Computer network] - TCP to ensure reliable transmission and improve network utilization

How TCP to ensure reliable transmission

Through TCP checksum and sequence number, acknowledgment, retransmission control, connection management and other window control mechanism to achieve the transmission reliability

The acknowledgment (ACK) mechanism

  • Normal data transmission, when the receiver receives the data transmission side, it will return an acknowledgment ACK response has been received
    Normal data transmission
  • TCP each byte of data is numbered, that is, serial number , and each comes with ACK acknowledgment number corresponding mean to tell the sender, I have received what data the next time you should begin from where .
    serial number

Retransmission timeout

  • Data sent to host A host B, it may be due to reasons such as network congestion, the host B such that no data is received, packet loss
  • If the host at a time interval A host B does not receive a response, we will resend the data
    Retransmission timeout

But if the situation is the host B receives the data, but returns an ACK packet is lost, causing the host A response was received it?
Loss
Host B receives the above data that duplicate TCP protocol needs to be able to identify those packets are duplicate packets and to discard duplicate this time we can use the aforementioned sequence number , it can be done easily to weight effect, which is to re-TCP protocol mechanisms, but also to ensure the reliability of TCP transmission mechanism.

Confirm retransmission time

Retransmission time

  • Ideally, find a minimum of time, to ensure that "the acknowledgment will be able to return at this time."
  • But the length of time, with different network environments, there is a difference.
  • If the timeout set too long, it will affect the overall efficiency of retransmission;
  • If the timeout time is set too short, there may frequently send the same packet;

TCP in order to ensure, in any environment can be relatively high performance communication, thus dynamically calculate the maximum timeout .

  • In Linux (BSD Unix and Windows, too), the timeout to a control unit for 500ms, every integer multiple of determining the retransmission timeout is a timeout of 500ms.
  • If after a heavy hair, still not answering, waiting for retransmission 2 * 500ms before.
  • If you still can not answer, wait 4 * 500ms retransmission. And so on, is incremented exponentially.
  • Accumulated to a certain number of retransmissions, TCP network or abnormality that occurs on the host side, forcibly closed connection

Connection management mechanism

  • Different TCP and UDP, which is connection-oriented, it may establish a TCP connection and disconnection is completed at least seven packets sent back and forth
    Waving and shaking hands

flow control

Data receiving side processing speed is limited. If the sender sent too fast, resulting in the buffer is played in the receiving end, if the transmitting side continues to transmit time, packet loss will result, and then cause retransmission of packet loss and so a . series chain reaction
thus TCP support the processing capability of the receiving terminal, determines the transmission speed of the transmitting side of this mechanism is called flow control (flow control).;

  • The receiving end can receive their buffer size into the TCP header in the "window size" field, an ACK to inform the sender terminal;
  • The larger the window size field, the higher the throughput of the network;
  • Once the receiving end own buffer is almost full, it will set the window size to be a smaller value notified to the sender;
  • After sending the termination by the window, it will slow down its transmission speed;
  • If the receiving buffer is full, the window will be set to 0; not the sender to send data at this time, it needs to send a periodic window probe segment, the reception side to inform the transmitting side window size
    flow control

Congestion Control

Although TCP sliding window with this big kill, can efficiently and reliably send large amounts of data, but if you send large amounts of data at the beginning stage, may still cause problems.
Because there are a lot of computers on the network, it may be the current network status it has been more congested. in the current network status is unclear, hastily send large amounts of data, it is likely to cause matters worse.
TCP introducing slow-start mechanism, starting a small amount of data, beating the road, to find out the current state of network congestion , and then decide how to transfer data in accordance with the velocity;
Congestion Control

  • Here is a process to introduce the concept of congestion window
  • Transmission start time, the congestion window size is defined as 1;
  • Each time an ACK response is received, the congestion window plus 1;
  • Every time transmission data packet, the window size of the congestion window and the receiver host fed back comparison, take a smaller value as the actual transmission of the window;

Such as congestion window growth rate above the index level is. "Slow start" only refers to the beginning of the slow, but growing very fast.

  • In order not to grow so fast, you can not simply doubling the congestion window.
  • Which is incorporated herein called slow start threshold
  • When the congestion window exceeds this threshold, no longer grow exponentially, but increase in a linear fashion
    Congestion Control

Improve network utilization

Sliding window

According to our previous statement, TCP data transmission once data is sent, a reply to the case shown below will appear, that if a message is very long, so the packet round-trip time is very long, network throughput it will be poor.
The normal transmission of data
Since such a way out of low income performance, then we send a plurality of data, you can greatly improve performance (in fact, the overlap multiple segments of the wait time)
Sliding window

  • It refers to a window size acknowledgment without waiting for the maximum value and may continue to transmit data. FIG upper window size is 4000 bytes (four segments).
  • When four segments before transmission, without waiting for the ACK any, is sent directly;
  • After receiving the ACK a first, rearward movement of the sliding window, the fifth continue sending data segments; and so on;
  • In order to maintain the operating system kernel sliding window, we need to open up the transmit buffer to record the current data What is not answered;
  • Only confirmed data response had to be deleted from the buffer;
  • The larger the window, the higher the throughput of the network;

Sliding window

  • With the sliding window mechanism, without waiting for an answer, send it directly
  • In fact, the sliding window is part of the TCP send buffer
  • Sliding window size of the reception buffer size is determined by the receiver, both in the first communication, the sender will determine the size of the recipient receives packets through the buffer

Delayed Answer

If the host receives data immediately return ACK response, time to return to this window may be relatively small.

  • Suppose the receiving end buffer is 1M 500K of data once received; if the answer immediately return window is 500K;
  • But it may actually speed the processing side processing quickly, within 10ms put 500K of data from the buffer consumption fell;
  • In this case, the receiving side processing far reached their limits, even if the window zooming in, can handle up;
  • If the receiving terminal is slightly again later responses, such as 200ms and then waits for a response, then the return time window size is 1M;

You must remember that the larger the window, the greater network throughput, higher transmission efficiency Our goal is to maximize transmission efficiency in the case to ensure that the network is not congested; So all packets are delayed answering it certainly? not;

  • Quantity: a response to every N packets;
  • Time limit: response time exceeds the maximum delay time;

The number and specific timeout, depending on different operating systems also different; typically N is 2, timeout of 200ms;
Delayed Answer

Piggybacking

On the basis of the response delay, we found that, in many cases, a client-server application layer is "pitch-catch" of. Means that the client to the server to say "How are you", the server will return to the client a "Fine, thank you";
so this time ACK can hitch a ride, and server response "Fine, thank you" back to the client,
Piggybacking

Published 167 original articles · won praise 175 · views 10000 +

Guess you like

Origin blog.csdn.net/chenxiyuehh/article/details/100124599