What if your server could send files faster by skipping extra steps?
Why sendfile and tcp_nopush in Nginx? - Purpose & Use Cases
Imagine you run a busy website and every time a user requests a file, your server reads the file piece by piece and sends it over the network manually.
This means your server is juggling many small tasks, reading and sending tiny chunks repeatedly.
This manual way is slow because the server spends extra time switching between reading files and sending data.
It also causes more network traffic with many small packets, making the website slower and less efficient.
Using sendfile lets the server send files directly from disk to the network without extra copying.
Adding tcp_nopush groups small packets into bigger ones before sending, reducing network chatter.
Together, they make file delivery faster and smoother.
read file chunk send chunk repeat
sendfile on; tcp_nopush on;
This lets your server deliver files quickly and efficiently, improving user experience and saving resources.
A video streaming site uses sendfile and tcp_nopush to smoothly send large video files without delays or buffering.
Manual file sending is slow and chatty.
sendfile sends files directly from disk to network.
tcp_nopush bundles packets for efficient delivery.