Boost Nginx Performance 10×: Auto CPU Affinity, Epoll, and Zero‑Copy Tweaks
This guide explains how to unleash Nginx's full potential on multi‑core Linux servers by configuring automatic CPU affinity, increasing worker connections with epoll, raising system file limits, and enabling zero‑copy transmission, resulting in up to ten‑fold throughput gains and dramatically lower CPU usage.
Utilize Multi‑Core CPU
Nginx uses a multi‑process, event‑driven architecture but defaults to a single worker process, leaving most CPU cores idle. Setting the worker count and CPU affinity to auto lets Nginx automatically spawn one worker per core and bind each worker to a specific CPU.
worker_processes auto;
worker_cpu_affinity auto;Effect : Automatic core matching, throughput increases 2–3×, CPU utilization rises from ~25% to ~90% on an 8‑core server.
Increase Maximum Concurrent Connections
The worker_connections directive controls how many simultaneous connections each worker can handle. The default of 1024 is far too low for high‑traffic services.
events {
use epoll;
worker_connections 65535;
}Raise the system file‑handle limit to support the larger connection pool: ulimit -n 100000 Effect : Concurrent connection capacity jumps from 10 000 to 500 000, eliminating “too many open files” errors and preventing connection drops during traffic spikes.
Enable Efficient I/O Model
Linux’s epoll provides O(1) event notification, far more efficient than select or poll. Using epoll ensures Nginx only processes sockets with pending events.
Effect : CPU consumption drops ~40%, response latency improves noticeably, and the server remains stable under massive long‑lived connections such as WebSocket streams.
Zero‑Copy and Network Transfer Optimization
By default Nginx copies data between user space and kernel space for each request. Enabling zero‑copy transmission removes this overhead.
sendfile on;
tcp_nopush on;
tcp_nodelay on;Effect : Static resource transfer speed improves ~30%, CPU usage falls ~20%, and real‑time protocols (WebSocket, HTTP/2) become smoother.
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.
Architect Chen
Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.
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.
