Boost Nginx Performance: 5 Essential Settings for Ten‑Fold Throughput
This guide explains how to tune Nginx for maximum performance by leveraging multi‑core CPUs, increasing concurrent connections, enabling zero‑copy file transfer, and optimizing keep‑alive settings, with concrete configuration examples and practical recommendations.
Utilize Multi‑Core CPUs
Set the worker_processes directive to match the number of CPU cores (or a multiple) to fully exploit parallelism. Too many workers cause excessive context switches; too few waste resources.
worker_processes 4;Increase Maximum Concurrent Connections
Adjust worker_connections to define how many simultaneous connections each worker can handle. The overall maximum is worker_processes * worker_connections. Choose a value based on server memory and expected traffic, commonly 10240 or higher, while also raising the OS file‑descriptor limit.
worker_connections 10240;Zero‑Copy and Network Transfer Optimizations
Enable sendfile to use zero‑copy, reducing kernel‑user space copying. Use tcp_nopush to batch headers and data, and tcp_nodelay to disable Nagle’s algorithm for lower latency on small packets.
sendfile on; tcp_nopush on; tcp_nodelay on;Connection Timeout and Keep‑Alive Settings
Configure keepalive_timeout to define how long an idle persistent connection stays open, and keepalive_requests to limit the number of requests per connection. A typical timeout is 30‑60 seconds, balancing reuse benefits against idle resource consumption.
http {
keepalive_timeout 60s;
keepalive_requests 1000;
}Practical Recommendations
Increase keepalive_timeout moderately (e.g., 30‑60 s) to reduce connection‑setup overhead, but avoid excessively long values that tie up server resources. Combine the above settings to achieve noticeable performance gains, often up to ten times higher throughput when properly tuned.
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
