Congestion and retransmission of TCP congestion and retransmission mechanism network congestion
Most of the network requests on the network are now transmitted in the form of TCP. Network links are fixed, and various link conditions are not the same. Network congestion has always been the TCP protocol design and use of the time to avoid. For example, from the TCP protocol design of the network Packet Protocol, TCP uses a one-off ACK of the network packet confirmation method, rather than using NAK this will increase the way to confirm the package to do a confirmation mechanism. This is the effort to reduce the number of packets on the network, to avoid network congestion.
What else is the way to control the congestion in the network?
Slow start
When a connection is connected to the network, it should not send a large number of packets to the network at a time, otherwise, if the network link condition is not very good, these network packets may aggravate the network congestion situation. So after the initial TCP connection is established, the size of the sending network packet is increasing, starting with the 1 maximum message size, and then the exponentially increasing number of packets. This is the slow start mechanism.
But by a single value, it is no longer possible to do exponential growth, and this time, the growth of the network packet from exponential growth to linear growth, is to add an MSS at a time. This is the congestion avoidance phase.
Nagle algorithm
If the Internet is a small package, it is absolutely a disaster, each network requests are expensive resources, if a piece of data is divided into fragmented many small packets, each network transmission only a small packet, then is a typical waste of resources, increase congestion. Confused window syndrome is that the sender and receiver muddle through the negotiation is the delivery of small packets.
In order to solve this problem, a lot of methods came into being, Nagle algorithm is one of the methods.
The Nagle algorithm specifies that a connection on the sender's network link can have only one request packet that does not get an ACK. This means that the sender only waits for the ACK of the last request to send the next request, so that in the middle of the two request process, the sender's buffer is stored with enough sliding window size of the packet to be passed, which effectively avoids the large number of packets produced.
Cork algorithm
Another way to solve the confused window syndrome is the cork algorithm. This algorithm is more aggressive than the Nagle algorithm, and simply calculates a value, when the sender's sliding window is larger and smaller than the value, the packet is not sent. This algorithm can effectively eliminate the emergence of small packets. Of course, it may lead to a certain delay in the data.
Both the Nagle and Cork algorithms are controlled by the sender, and the focus of the two algorithms is different, and the Nagle algorithm focuses on avoiding small packets and more end-to-end optimization. The cork algorithm is designed to improve the utilization of the network.
Delay ACK
From the receiving side also has the ability to prevent confused Windows syndrome. The delay ACK algorithm is that the receiver does not send an ACK immediately after the request is received, but instead turns on a timer and waits until the timer ends to send an ACK. Alternatively, the receiver sends back the ACK of the last request when it needs to send the request back. This mechanism, if combined with the Nagle algorithm, allows the connected sliding window to achieve a better value than expected.
Re-transmission mechanism
It's all about preventing blocking, but what if it's blocked? The sent request packet does not receive an ACK within the specified time, whether the request packet is lost, the ACK packet is lost, or the network delay, in short, there is a need for a retransmission mechanism. There are two kinds of retransmission mechanisms for TCP: time-out retransmission and fast retransmission.
Time-out retransmission
To be blunt is to open a timer when the request packet is sent out, when the timer reaches the time, does not receive an ACK, then the operation of the re-send request, has been re-sent until the maximum number of re-send or receive an ACK.
Fast re-transmission
Another mechanism is the rapid retransmission, when the receiver received the packet is an abnormal sequence number, then the receiver will repeat the ACK should be received repeatedly sent, this time, if the sender receives 3 consecutive serial number of the ACK, then the fast retransmission mechanism will be initiated, Resend this ACK corresponding to the sending packet. For details, refer to:
Reference
TCP retransmission and duplicate ACK for network performance troubleshooting
TCP slow start, congestion avoidance, fast retransmission, fast recovery
Congestion and retransmission of TCP