TCP/IP: TCP_NODELAY, TCP_CORK, and tcpnodelay

Source: Internet
Author: User

TCP/IP: TCP_NODELAY, TCP_CORK, and tcpnodelay
The Nagle algorithm and the 40 ms latency of TCP/IP refer to the Nagle algorithm. In this way, although the network throughput is improved, the real-time performance is reduced. In some highly interactive applications, the Nagle algorithm can be disabled by using the TCP_NODELAY option. If Nagle is disabled, each packet sent by the application to the kernel is immediately sent. However, if Nagle is disabled, network transmission is still affected by the TCP validation delay mechanism. The CORK indicates a plug-in. The CORK in TCP indicates that the connection is blocked, so that the data is not sent out, and then sent out after the plug-in is pulled out. After this option is set, the kernel will try its best to splice small data packets into a large data packet (One MTU) and then send it out. after a certain period of time, when the kernel is still not combined into an MTU, the existing data must also be sent. However, the implementation of TCP_CORK may not be as perfect as you think, and CORK will not completely plug the connection. The kernel does not know when the application layer will send the second batch of data for splicing with the first batch of data to reach the MTU size. Therefore, the kernel will give a time limit, if you do not splice a large package (try to get close to MTU) during this time, the kernel will send it unconditionally. That is to say, if the application layer program does not send small packets of data at short intervals, TCP_CORK will have no effect, but will lose the real-time data (each small packet of data will be sent after a certain delay, this time exceeds the kernel time limit ). The Nagle algorithm and the CORK algorithm are very similar, but their focus is different. The Nagle algorithm mainly avoids network congestion due to too many packets (the proportion of protocol headers is very large, the CORK algorithm aims to improve the network utilization and minimize the proportion of protocol headers in general. In this case, the two are the same in avoiding sending packets. At the user control level, the Nagle algorithm is not controlled by the user socket. You can only simply set TCP_NODELAY and disable it, the CORK algorithm also enables or disables TCP_CORK by setting or clearing TCP_CORK. However, the Nagle algorithm is concerned with network congestion issues, and packets are sent when all ACK is returned, however, the CORK algorithm can focus on the content. It is very important to ensure that the frontend and backend packets are sent at a short interval (otherwise, the kernel will send scattered packets to you ), even if you send multiple small data packets in a distributed manner, you can use the CORK algorithm to splice the content into a package. If you use the Nagle algorithm at this time, you may not be able to do this.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.