tcp_nodelay

The tcp_nodelay directive disables Nagle's algorithm for TCP connections, allowing for low-latency communication.

Syntaxtcp_nodelay on | off;
Defaultoff
Contexthttp, server, location
Argumentsflag

Description

The tcp_nodelay directive is used within the context of HTTP, server, and location blocks in NGINX configuration files. When set to 'on', it disables Nagle's algorithm for the TCP connections, which means that packets are sent immediately without waiting to accumulate more data for transmission. This can help improve the performance of real-time applications where low latency is critical, such as online gaming, VoIP, and streaming services.

When Nagle's algorithm is enabled (the default), small packets may be delayed while the system attempts to combine them into larger packets to optimize network usage. This can result in higher latency for applications that require immediate data transmission. By using tcp_nodelay, administrators can ensure that when data is ready to be sent, it is sent immediately, thus reducing latency at the cost of potentially increased network traffic. It is important to carefully consider the implications on network bandwidth when using this directive.

The directive accepts a flag parameter; setting it to 'on' enables TCP_NODELAY, whereas 'off' enables the default behavior. It is important to be aware that this directive mainly impacts performance characteristics rather than functional behavior, so it should be tuned based on the specific needs of the application being served.

Config Example

server {
    listen 80;
    location / {
        tcp_nodelay on;
        proxy_pass http://backend;
    }
}

Setting tcp_nodelay to on can increase network traffic as packets are sent immediately.

Use with caution in applications where bandwidth efficiency is more critical than low latency.

← Back to all directives