我使用 ab(ab -c50 -t5s)对同一台服务器上的 Apache V Nginx 静态文件进行基准测试。
Apache 在每秒处理 200 个请求时 CPU 占用率会很高,而 Nginx 在每秒处理 5211 个请求时 CPU 占用率约为 25%。
Apache 没有发生交换,因此不存在内存不足的问题。
我知道 Nginx 和 Apache 都有大量不同的配置,但 Nginx 落后 Apache 如此之多简直令人难以置信。
事实上太荒谬了,我认为我错过了 Apache 的一些东西。
有什么想法从哪里开始吗?
以下是 ab 结果:
Server Software: nginx
Server Port: 80
Document Path: /images/15.jpg
Document Length: 15088 bytes
Concurrency Level: 50
Time taken for tests: 5.494 seconds
Complete requests: 26059
Failed requests: 0
Write errors: 0
Total transferred: 400370476 bytes
HTML transferred: 393178192 bytes
Requests per second: 5211.29 [#/sec] (mean)
Time per request: 9.595 [ms] (mean)
Time per request: 0.192 [ms] (mean, across all concurrent requests)
Transfer rate: 78189.48 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 4 0.6 4 10
Processing: 3 5 0.8 5 13
Waiting: 0 2 1.3 2 10
Total: 6 9 0.9 9 19
Percentage of the requests served within a certain time (ms)
50% 9
66% 9
75% 9
80% 9
90% 10
95% 10
98% 11
99% 12
100% 19 (longest request)
Server Software: Apache
Server Port: 81
Document Path: /images/15.jpg
Document Length: 15088 bytes
Concurrency Level: 50
Time taken for tests: 5.31551 seconds
Complete requests: 1008
Failed requests: 0
Write errors: 0
Total transferred: 15681815 bytes
HTML transferred: 15433585 bytes
Requests per second: 200.34 [#/sec] (mean)
Time per request: 249.581 [ms] (mean)
Time per request: 4.992 [ms] (mean, across all concurrent requests)
Transfer rate: 3043.59 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 2 84 47.5 78 222
Processing: 24 158 46.5 162 260
Waiting: 1 96 45.1 91 221
Total: 187 242 48.5 232 428
Percentage of the requests served within a certain time (ms)
50% 232
66% 238
75% 246
80% 249
90% 304
95% 380
98% 409
99% 423
100% 428 (longest request)
答案1
此岗位现已不再存在。
我发现这不是标准的 Apache 设置,而扩展的 mod_security 规则才是问题所在。