Boost Nginx Concurrency: Key Settings and Practical Configurations
This guide explains how to maximize Nginx concurrency by configuring worker_processes, worker_connections, keepalive_timeout, and high‑performance I/O options such as sendfile, tcp_nopush, and tcp_nodelay, including formulae, example calculations, recommended values, and system‑level considerations.
worker_processes – Upper limit of concurrency
worker_processes defines how many worker processes Nginx can spawn; setting it to auto makes Nginx create one worker per CPU core, maximizing CPU utilization while avoiding excessive context switches.
worker_processes auto;worker_connections – Connections per worker
worker_connections specifies the maximum number of simultaneous connections a single worker can handle. The theoretical maximum concurrent connections is calculated as:
max_concurrency = worker_processes * worker_connections;For example, 8 workers × 10240 connections = 81 920 concurrent connections. A typical recommended setting is: worker_connections 10240; Note: the operating system’s ulimit -n must be increased accordingly, otherwise the setting will not take effect.
keepalive_timeout – Tuning persistent connections
Long‑lived keep‑alive connections occupy slots, reducing overall concurrency and QPS. Reducing keepalive_timeout frees connections for new clients. A common value is 15 seconds, but for short‑lived traffic (e‑commerce APIs) it can be lowered to 3–10 seconds.
keepalive_timeout 15;High‑Performance I/O Trio
These directives are especially useful for serving static assets (images, videos, etc.) at high throughput.
sendfile on;
tcp_nopush on;
tcp_nodelay on;sendfile enables zero‑copy file transmission, reducing CPU load. tcp_nopush merges small packets to improve throughput. tcp_nodelay disables Nagle’s algorithm, lowering latency for fast‑response services. Combined, they provide high throughput with low latency.
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.
