sendfile_max_chunk

The sendfile_max_chunk directive sets the maximum size of data to send with the sendfile system call in NGINX.

Syntaxsendfile_max_chunk size;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The sendfile_max_chunk directive determines the maximum amount of data, in bytes, that can be transmitted using the sendfile system call in a single operation. This is particularly useful for optimizing file sending performance on high-load servers, where the underlying operating system’s limits may need to be adjusted to optimize throughput.

When set, the directive limits the amount of data that can be transferred in one sendfile call, which may help to manage memory usage and avoid blocking on large file transmissions. If the size of the file being sent exceeds the specified chunk size, NGINX will break the transmission into multiple sendfile calls, each capped at the defined max chunk size. This behavior ensures that resources are used efficiently and can improve overall server responsiveness under heavy load.

The directive is particularly relevant for serving static files like images or videos, where performance might suffer under scaling workloads without this limitation in place. Tuning this parameter allows operators to find a balance between resource consumption and application performance, making it an important consideration in NGINX performance tuning.

Config Example

http {
    sendfile on;
    sendfile_max_chunk 1m;
}

Setting the value too low may lead to inefficient data transfer and higher CPU usage due to frequent context switching.

In environments with small file sizes, a high value may have little benefit and may unnecessarily complicate resource management.

← Back to all directives