Performance Tuning
Harry
· 12 Sep 2026
· 11 views
Workers and Connections
worker_processes auto; # one per CPU core
worker_rlimit_nofile 65535; # raise fd limit for high concurrency
events {
worker_connections 4096;
use epoll;
multi_accept on;
}Rough ceiling: worker_processes x worker_connections simultaneous connections.
Keepalive to Backends
Reuse backend connections instead of opening a new one per request:
upstream app_servers {
server 127.0.0.1:8080;
keepalive 32;
}
location / {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://app_servers;
}Client-Side Keepalive
keepalive_timeout 65;
keepalive_requests 1000; # many requests per single connectionStatic-Only Optimizations
- sendfile on; (default) - kernel zero-copy file serving.
- tcp_nopush on; - pack responses into fewer packets.
- tcp_nodelay on; - low latency for interactive traffic.
Measure, Don't Guess
# traffic and status over time
sudo apt install -y nginx-module-sts nginx-extras # or parse the access log
ab -n 10000 -c 100 http://localhost/ # quick load test Watch error.log for worker_connections limit warnings and RAM/swap for worker footprint.
Key Points
- Tune workers and file descriptors upward for concurrency.
- keepalive to backends removes a huge TCP overhead.
- Base every knob on measured traffic, not rumor.