Reference: http://blog.chinaunix.net/uid-26275986-id-4109679.html
Go on! TCP traffic control and congestion control.
TCP relative UDP reliable place lies in its congestion control, flow control.
A. Flow control :
If the sender sends the data too fast, the receiver may be too late to receive it, which can result in loss of data. The so-called flow control is to send the sender of the rate is not too fast, to let the receiver in time to receive. The sliding window mechanism can be used to control the sender's traffic conveniently on the TCP connection. The primary way to do this is to return an ACK containing the size of its own acceptance window, and use the size to control the sender's data delivery.
Sliding Window Protocol : TCP is a full-duplex protocol, and the sender and receiver each control their own buffers. Sending the data sent successfully, only the receiver's confirmation, the sliding window will be moved away from the sent data, while the receiver confirms the continuous data grouping, for the disorderly sequence of the packet is first received, to avoid the network repeated transmission
Stop Waiting Protocol : Both the sender and the receiver use a sliding window of size 1. The sender sends one packet at a time, and then waits for a confirmation before sending the next packet. It is connection-oriented, providing flow control and error control. The required buffer storage space is the least, the disadvantage is the channel efficiency is very low. At any time there is only one grouping and one acknowledgment in the channel. Flow control is achieved by forcing the sender to wait for confirmation, and error control is achieved by discarding the broken packet and having the sender retransmit the unacknowledged packet after the timer supermarket.
return N Protocol : In order to improve the efficiency of transmission, there should be more than one packet being transmitted while the sender waits for confirmation. That is, we should have multiple groups waiting for confirmation so that the sender waits for confirmation while the channel remains in a busy green state. The key to GBN is that we can send multiple groupings before we receive the acknowledgement, but only one group can be cached by the receiver. The sender saves a copy of the sent packet until the confirmation arrives. The Send window must be less than 2^m. (The sender does not wait for the receiver to answer, continuously send multiple frames, if it is found that there is an error in the sent frame, then all the frames from the beginning of the wrong frame and then all the frame is again sent again.) The complexity is low, but unnecessary frames are re-sent, so the efficiency is not high when used in a large range.
Flow control
Two. Congestion control
both the link capacity in the network and the caches and processors in the switching nodes have a working limit, and congestion occurs when the requirements of the network exceed their operating limits. Congestion control is to prevent excessive data from being injected into the network, so that routers or links in the network are not overloaded. The usual methods are:
1. Slow start, congestion control
2. Fast re-transmission, fast recovery
The basics of everything are slow to start, and this approach is the idea:
-1. The sender maintains a variable called "congestion Window", which together determines the sender's sending window;
-2. When the host begins to send data, avoid injecting large amounts of bytes into the network at once, causing or increasing congestion and choosing to send a 1-byte heuristic message;
-3. When the first byte of the data is received, a 2-byte message is sent;
-4. If you receive a 2-byte acknowledgment again, send 4 bytes, then increment the number of digits by 2;
-5. End up with a preset "slow start threshold" such as 24, which sends 24 groupings at a time, following the conditions below:
* CWnd < Ssthresh, continue to use the slow start algorithm;
* * CWnd > Ssthresh, stop using the slow start algorithm and use the congestion avoidance algorithm instead;
CWnd = Ssthresh, you can use either the slow-start algorithm or the congestion avoidance algorithm;
-6. The so-called congestion avoidance algorithm is: each through a roundtrip time RTT will send the sender of the Congestion window +1, that is, the congestion window increases slowly, according to the Linear law growth;
-7. When network congestion occurs, such as packet loss, the slow start threshold is set to half the original, then CWnd is set to 1, and the slow start algorithm (lower starting point, exponentially increasing) is executed;
The purpose of this method is to reduce the number of packets sent by the host to the network in a sequential manner, so that the congested routers have enough time to complete the backlog of packets in the queue. Slow start and congestion control algorithms are often used as a whole, and fast retransmission and fast recovery is to reduce the retransmission time caused by packet loss due to congestion, thus avoiding the passing of useless data to the network. The mechanism for fast retransmission is:
-1. The receiver establishes such a mechanism that if a packet is lost, the retransmission request for the packet continues to be sent to the subsequent packet;
-2. Once the sender receives three identical confirmations, it is known that an error occurred after the packet and immediately re-transmits the packet;
-3. At this point the sender begins to execute the "fast Recovery" algorithm:
* * slow start threshold halved;
* * CWnd is set to the value after the slow start threshold is halved;
implementation of congestion avoidance algorithm (high starting point, linear growth);
QUIZ:
After the TCP connection is established, what is maintained by what?
ANSWER:
The data received and sent from the network are implemented through sockets. However, if the socket is disconnected, then sending data and receiving data will definitely cause problems. How can I tell if a socket is available? How to keep a long connection? TCP sets a mechanism for us to call the heartbeat, if the heartbeat is set, then TCP will be in a certain amount of time to send you set the number of heartbeats, and this information does not affect the protocol, let the other side know that they are "alive" to ensure the validity of the connection.
QUIZ:
What is a long connection? What is a short connection?
ANSWER:
A long connection means that multiple packets can be sent continuously on a TCP connection, and if no packet is sent during TCP connection retention, both parties are required to detect the packet in order to maintain the connection; a short connection is a TCP connection that is established when the data is exchanged between the two sides of the communication, and the TCP connection is disconnected when the data is sent. Long connection is suitable for frequent operation, point-to-point communication, and the number of connections is not too much, short connection for the bank, because it is relatively simple to manage, the existence of connections are reasonable connection.
TCP/IP Knowledge Summary (TCP/IP protocol family reading Note IV)