Static file transfer efficiency
File transfer is not the same as compression
A file server can spend work moving data from storage through userspace to a socket. On supported systems sendfile can move eligible file data through an operating system interface without the usual application read/write path. This can reduce copying and CPU work but does not compress bytes. TLS, filters, operating system behavior and file characteristics can change whether a particular transfer uses that path.
sendfile on;tcp_nopush on;tcp_nodelay on;On Linux tcp_nopush selects TCP_CORK during sendfile transfers; FreeBSD has TCP_NOPUSH. This can help group output into full packets. tcp_nodelay controls Nagle-related behavior in applicable connection states, such as keepalive. These settings are not logical opposites or HTTP/3 tuning knobs. Do not infer the packet pattern from a configuration alone.
Request a byte range
GET /downloads/bytes.bin HTTP/1.1Host: assets.testRange: bytes=0-15Accept-Encoding: identity
HTTP/1.1 206 Partial ContentContent-Range: bytes 0-15/256Content-Length: 16The offsets are inclusive: byte 0 through byte 15 is 16 bytes. A satisfiable range can produce 206; a wholly unsatisfiable request can produce 416. A server may ignore a range and return 200. Ranges apply to the selected representation, not necessarily its decoded bytes, so this demonstration deliberately disables compression and uses identity. A limit on number of ranges controls multipart work, not the total number of downloaded bytes.
location /downloads/ { gzip off; gzip_static off; max_ranges 1;}Measure rather than guess
The benchmark compares level 1, 3, 6 and 9 on the same deterministic text, reporting encoded size, median process CPU time and elapsed time. The input and round-trip result are fixed; timings vary by machine and load. This is a Python gzip codec microbenchmark, not a measurement of Nginx latency or network throughput. The optional live verifier checks body correctness and response headers. For a meaningful server experiment, hold file, client, encoding, concurrency, TLS, cache state and machine constant; compare sendfile off and on with identical bounded workloads, repeat trials, record server CPU and response latency, and do not infer production gains from loopback.
Practice
Predict the response for bytes=250-255 and bytes=256-260 against a 256-byte file. Choose metrics for a controlled sendfile comparison. Next: FastCGI and PHP-FPM.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Static file transfer efficiency
Explain sendfile and TCP options, interpret byte ranges, and design a controlled transfer measurement.
What does sendfile aim to optimize?
How many bytes does bytes=0-15 request?
What can max_ranges 0 do?
Why use identity for the range fixture?
What does the Python codec benchmark establish?