The Nagle algorithm of TCP/IP and the 40MS delay refer to the Nagle algorithm. This improves network throughput, but is less real-time, and is not allowed in some highly interactive applications, and using the Tcp_nodelay option disables the Nagle algorithm. Every packet that the application submits to the kernel after the Nagle is banned willSend NowGet out. However, Nagle is forbidden, and the network transmission is still affected by the TCP acknowledgement delay mechanism. Cork meaning is the plug, TCP cork meaning is to plug the connection, so that the data is not sent out, wait until the plug and then send out. When this option is set, the kernel tries to stitch the small packet into a large packet (an MTU) and send it, and after a certain amount of time, the kernel still has to send the existing data when it is not combined into an MTU. However, the implementation of tcp_cork may not be as perfect as you might think, and Cork will not completely plug the connection. The kernel does not really know when the application layer will send the second batch of data to the first batch of data to achieve the size of the MTU, so the kernel will give a time limit, when the time is not stitched into a large package (trying to approach the MTU), the kernel will be sent unconditionally. That is, if the application layer program sends the packet data intervalShort Enough, Tcp_cork has no effect, but loses the real-time data (each packet data will be delayed for a certain time to send, this time exceeds the time limit of the kernel). The Nagle algorithm and the cork algorithm are very similar, but their focus is different, Nagle algorithm mainly avoids the network because too many small packets (the proportion of the protocol head is very large) and congestion, and cork algorithm is to improve the network utilization, so that the overall protocol head occupies as small proportion as possible. So it seems that thisThe two are consistent in avoiding sending packets., at the user control level, the Nagle algorithm is completely not controlled by the user socket, you can simply set the Tcp_nodelay and disable it, Cork algorithm also by setting or clearing tcp_cork enable or disable it, However, the Nagle algorithm is concerned about the network congestion problem, as long as all the ACK back to the contract, while the cork algorithm can be concerned about the content, before and after the packet send interval is very short premise (very important, otherwise the kernel will help you distribute the scattered packets), even if you are scattered to send multiple small packets, You can also do this by enabling the Cork algorithm to stitch the contents into a package, and if you use the Nagle algorithm at this point, you may not be able to do so.
The Tcp_nodelay and tcp_cork of TCP/IP