How Nginx Handles One Million Concurrent Connections: 4 Key Techniques
The article explains how Nginx sustains one million simultaneous connections by using asynchronous non‑blocking I/O, a robust multi‑process architecture, zero‑copy file transmission, and optimized caching strategies, with concrete configuration examples and performance reasoning.
In high‑concurrency systems Nginx is a critical component; this article details how it can support one million simultaneous connections.
Asynchronous non‑blocking : A traditional blocking model would require one thread per connection, causing crashes at large scales. Nginx runs each worker as a single thread that handles many connections via the epoll event‑notification mechanism, avoiding blocking. Example configuration:
events {
use epoll;
worker_connections 65535; # maximum connections per worker
multi_accept on; # accept connections in batches
}Multi‑process architecture : Nginx separates responsibilities between a master process (signal handling, configuration management, worker monitoring) and multiple worker processes (actual request handling). The number of workers typically matches the number of CPU cores. Workers acquire connections using accept_mutex or the modern SO_REUSEPORT lock, ensuring fair distribution. If a worker crashes, the master immediately spawns a replacement, guaranteeing service continuity and eliminating lock contention and context‑switch overhead.
Zero‑copy transmission : For static assets (images, videos, HTML), Nginx enables the kernel’s sendfile feature. The data path becomes disk → kernel buffer → NIC, bypassing user‑space copies and dramatically reducing CPU usage and memory‑bandwidth consumption, allowing near‑full NIC bandwidth for large files.
Cache architecture strategy : In million‑connection scenarios, static and cacheable content dominate. Nginx serves static files directly with sendfile, tcp_nopush, and tcp_nodelay enabled, and tunes buffers and keep‑alive settings:
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_requests 1000;
keepalive_timeout 60s;
client_header_buffer_size 4k;
large_client_header_buffers 8 8k;
}Dynamic responses that can be cached are stored in Nginx’s cache and coordinated with a CDN to push traffic to edge nodes, reducing origin load and improving global availability and 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.
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.
