Boost Nginx High-Concurrency Performance by Up to 10×: Practical Tuning Guide
This article explains how to unleash Nginx's full potential for high‑concurrency workloads by adjusting worker processes, raising file‑descriptor limits, enlarging TCP connection queues, and persisting sysctl settings, enabling up to ten‑fold throughput improvements in production environments.
Worker Processes
Nginx uses a master+worker multi‑process model; each worker is single‑threaded and can run on a separate CPU core. The default single worker underutilizes multi‑core CPUs. Setting worker_processes auto (or the number of cores) enables parallel request handling and reduces context‑switch overhead. Optionally bind CPU affinity with worker_cpu_affinity auto.
File Descriptor Optimization
In Linux, network connections are file descriptors. Nginx consumes a descriptor for each connection, log file, and backend socket. Insufficient descriptors cause “too many open files” errors. Raise the system limit fs.file-max and the per‑process limit ulimit -n. In Nginx config set worker_rlimit_nofile 100000; and worker_connections 65535; to support high‑concurrency long‑connections and massive static file serving.
TCP Connection Queue Optimization
When request arrival exceeds worker processing speed, new connections queue. A small queue leads to dropped connections or client timeouts, especially in flash‑sale (秒杀) systems. Increase the Linux kernel backlog with net.core.somaxconn = 65535 to allow more pending connections.
Production‑Ready System Settings
Rather than using temporary sysctl -w commands, persist the tuned parameters in system configuration files. Example settings:
fs.file-max = 1000000
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 15
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216These values together enable Nginx to handle ten times more concurrent requests in production environments.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
