Socket option TCP_NODELAY、TCP_CORK and TCP_QUICKACK

1. Introduction:

TCP_ Nodelay turns off the Nagle algorithm and controls the sending of data. According to the Nagle algorithm, if the packet is larger than MSS (max segment size) or contains fin, it will be sent immediately. Otherwise, it will be put into the buffer and sent after the sent packet is confirmed. That is, there can only be one unconfirmed packet on the network. It can reduce the number of network packets, reduce the proportion of IP header in the network, and improve the network performance.

TCP_ Cork: after setting, no packets will be sent (less than MSS) unless the timeout is 200ms

TCP_ Quickack (since Linux 2.4.4) will send confirmation ack immediately after setting, rather than delay sending ack. If it is not enabled, the delay ACK will delay the confirmation, so that the protocol has the opportunity to consolidate the ACK and improve the network utilization. By default, the 40ms timeout confirmation and the system value can be configured.


2. Test:

Test method: server IP 192.168 x.5,client ip 192.168. x.7。 Sever accepts client connections but does not do any processing; After the client establishes a connection with the server, 10 characters are sent continuously:

1. Close quickack on the server side and nodelay on the client side (that is, the sending will be delayed): the server closes quickack, so it will wait for a timeout to confirm or wait until there is a data sending to confirm the ACK, but the server does not send data, so wait until 40ms to timeout; Since the client does not receive the ACK from the server, and nodelay is closed, that is, delayed sending is enabled, the client will not continue to send the remaining data until the ACK from the server is received


2. Enable quickack on the server side and nodelay on the client side (send immediately): the server side immediately sends a confirmation to the client after receiving a data


3. The server turns off quickack and the client turns on nodelay (send immediately): the client sends 10 characters without waiting for confirmation. The server sends ack after 10ms. Question: why send ack after 10ms? "


4. The server turns on quickack and the client turns off nodelay (that is, it will delay sending): the server immediately sends a confirmation to the client after receiving the data, and the client sends the remaining 9 characters in combination.


5. Turn off quickack on the server side and turn on TCP on the client side_ Cork: the client sends 10 characters, which is much smaller than MSS, so it will be sent after 200ms timeout


3. Summary:

Latency and bandwidth utilization cannot be combined. If the delay needs to be reduced, quickack and nodelay shall be enabled; Otherwise, both are turned off to improve bandwidth utilization.

Comments

Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example