About Nagle algorithm

 

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.

 

 TCP_CORK Options
  CORK is the so-called plug meaning, vividly understand the connection is plugged with CORK, so that data is not sent out first, and then wait until uncorking sent out. After setting this option, the kernel will try to put small packets together into a large data packet (a MTU) re-sent, of course, if after a certain time (typically 200ms, the value is yet to be confirmed), the kernel is still not combined into a It must also send existing data (data not let it has been waiting for) when MTU.

 

reference:

https://baike.baidu.com/item/Nagle%E7%AE%97%E6%B3%95

Guess you like

Origin www.cnblogs.com/iouwenbo/p/11225888.html