To estimate the maximum concurrant connections Nginx can handle, use the following formula:
(Total RAM in GB × 1024 − System Overhead) / Average Request Size
- Total RAM in GB: Physical memory available on the server.
- System Overhead: Memory reserved for OS processes, background services, and buffer space (typically 2–4 GB).
- Average Request Size: Size of each request in KB for static content (e.g., images, CSS) or MB for dynamic content (e.g., PHP, API responses).
On a 32 GB RAM server with 16 CPU cores, assuming 4 GB system overhead and an average static request size of 5 KB, the theoretical maximum concurrency is approximately:
(32 × 1024 − 4096) / 5 ≈ 5,898
In practice, such a system can sustain 40,000–60,000 concurrent connections before hitting file descriptor limits or network stack constraints.
Load Testing with Apache Benchmark (ab)
Install the benchmarking tool:
yum install httpd-tools -y
Run a basic test:
ab -n 2000 -c 200 http://127.0.0.1/index.html
-n: Total number of requests to simulate.-c: Number of concurrent clients.-k: Enable HTTP keep-alive (optional).
Sample output:
Server Software: nginx/1.12.2
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /index.html
Document Length: 19 bytes
Concurrency Level: 200
Time taken for tests: 1.013 seconds
Complete requests: 2000
Failed requests: 0
Total transferred: 510000 bytes
HTML transferred: 38000 bytes
Requests per second: 9333.23 [#/sec] (mean)
Time per request: 101.315 [ms] (mean)
Time per request: 0.507 [ms] (mean, across all concurrent requests)
Transfer rate: 491.58 [Kbytes/sec] received
- Requests per second: Throughput metric — higher values indicate better performance.
- Time per request: Average time for a client to receive a resposne.
- Transfer rate: Network bandwidth utilization; helps detect bottlenecks.
Monitoring Active Connections
View TCP connection states for Nginx/Apache:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
Typical output:
ESTABLISHED 1597
TIME_WAIT 1057
SYN_RECV 30
FIN_WAIT1 51
FIN_WAIT2 504
LAST_ACK 5
Connection state definitions:
- ESTABLISHED: Active, ongoing data transfer.
- TIME_WAIT: Connection closed, waiting for cleanup (normal after high traffic).
- SYN_RECV: Incoming connection request received but not yet acknowledged.
- FIN_WAIT1/2: Connection closing in progress.
- LAST_ACK: Final acknowledgment pending before full closure.
Count active Nginx worker processes:
ps -ef | grep nginx | grep -v grep | wc -l
Count established connections on port 80:
netstat -antp | grep ':80' | grep ESTABLISHED | wc -l
Use these metrics to correlate system load with observed concurrency and adjust Nginx worker limits, keepalive timeouts, or file descriptor limits accordingly.