Nagle algorithm
TCP / IP protocol, regardless of how much data is sent, always add a protocol header in front of the data, while the other receives the data, need to transmit an ACK to confirm. In order to utilize the network bandwidth as possible, TCP always want to send data as a large enough (MSS sets a connection parameter, therefore, TCP / IP can transmit desired data every data block size MSS). Nagle algorithm is to transmit large blocks of data as much as possible, to avoid flooding the network with many small blocks of data.
Nagle algorithm is the basic definition at any time, at most one unacknowledged small pieces. The so-called "small pieces" refers to a data block size smaller than the MSS; called "unacknowledged", refers to a data block after sending out ACK is not received confirmation that the other data transmission has been received.
Nagle algorithm is completely determined by the protocol TCP ACK mechanism, which will bring some problems, such as if the end of the ACK reply soon, then, will not in fact Nagle stitching too much data packet, although avoiding network congestion, the overall use of the network rates remain low.
Nagle algorithm rules:
(1) if the packet length reaches MSS, this can allow the transmission;
(2) if this comprises a FIN, it is allowed to transmit;
(3) set TCP_NODELAY option is allowed to transmit;
When (4) TCP_CORK option is not set, if all issued to small packets (packet length is less than MSS) are acknowledged, transmission is enabled;
(5) satisfy none of the above conditions, but a timeout occurs (typically 200ms), it is sent immediately.
TCP_NODELAY option
By default, the transmission data using Negale algorithm. Although this improves network throughput, but real-time has decreased, in some highly interactive application is not allowed, use TCP_NODELAY option to prevent Negale algorithm.
reference: