When should I use TCP_NODELAY and when TCP_CORK?

前端 未结 4 1439
余生分开走
余生分开走 2020-11-30 18:07

I understood that both of them disable Nagle\'s algorithm.

When should/ shouldn\'t I use each one of them?

4条回答
  •  执念已碎
    2020-11-30 18:40

    TCP_NODELAY

    Used to disable Nagle's algorithm to improve TCP/IP networks and decrease the number of packets by waiting until an acknowledgment of previously sent data is received to send the accumulated packets.

    //From the tcp(7) manual:

    TCP_CORK (or TCP_NOPUSH in FreeBSD)

    If set, don't send out partial frames. All queued partial frames are sent when the option is cleared again. This is useful for prepending headers before calling sendfile(2), or for throughput optimization. As currently implemented, there is a ** 200-millisecond ceiling** on the time for which output is corked by TCP_CORK. If this ceiling is reached, then queued data is automatically transmitted. This option can be combined with TCP_NODELAY only since Linux 2.5.71. This option should not be used in code intended to be portable.

提交回复
热议问题