tcp_nopush
The tcp_nopush directive controls whether NGINX sends data using the TCP_CORK socket option on Linux.
Description
The tcp_nopush directive, when enabled, instructs NGINX to utilize the TCP_CORK option on Linux systems. This option allows NGINX to optimize the transmission of responses by preventing packets from being sent prematurely. Instead of sending data in small packets, TCP_CORK ensures that the data is only sent when the entire response is ready or when the socket buffer is full. This can reduce the number of packets sent over the network and increase throughput, especially for large responses or file transfers.
By default, this directive is turned off, meaning that NGINX will not use TCP_CORK, which can lead to a larger number of smaller packets being transmitted. The directive is useful when the performance of data transmission is critical, such as when serving large files or during high-load operations. However, it’s important to note that enabling tcp_nopush can introduce latency in response times since the server will wait to send the data until conditions are met for TCP_CORK to be released.
The directive accepts a flag argument, which can either be "on" or "off". Setting tcp_nopush on allows the behavior of TCP_CORK to be enabled, whereas setting it off reverts to the standard packet sending behavior. It is applicable in various contexts including http, server, and location blocks, providing flexibility in defining the optimal behavior for different parts of an NGINX configuration.
Config Example
http {
tcp_nopush on;
server {
location / {
# Additional location settings
}
}
}Ensure that the server is running on a Linux system, as TCP_CORK is a Linux-specific feature.
Be cautious when enabling tcp_nopush on APIs or real-time services, as it may increase response time for small payloads.