First of all, both of them do not cancel the Nagle algorithm.
The Nagle algorithm is designed to reduce the number of small network packets in the wire. Algorithm: if the data is less than the limit (usually MSS), wait for the ACK to be received for previously sent packets and, on average, accumulate data from the user. Then send the accumulated data.
if [ data > MSS ] send(data) else wait until ACK for previously sent data and accumulate data in send buffer (data) And after receiving the ACK send(data)
This will help in applications like telnet. However, waiting for an ACK may increase the delay in sending streaming data. In addition, if the recipient implements a “delayed ACK policy”, this will lead to a temporary deadlock situation. In such cases, it is best to disable the Nagle algorithm.
Therefore, TCP_NODELAY is used to disable the Nagle algorithm.
TCP_CORK aggressively accumulates data. If TCP_CORK is enabled on the socket, it will not send data until the buffer fills a fixed limit. Like the Nagle algorithm, it also accumulates data from the user, but until the buffer fills a fixed limit until an ACK is received. This will be useful when sending multiple data blocks. But you have to be more careful when using TCP_CORK.
Prior to kernel 2.6, both of these options are mutually exclusive. But in a later core, both can exist together. In this case, preference will be given to TCP_CORK.
Ref:
theB Nov 15 '13 at 7:19 2013-11-15 07:19
source share