nginx配置大概是
limit_req_zone $binary_remote_addr zone=req_zone:1m rate=1r/s; server { listen 80; server_name localhost; access_log /var/log/nginx/host.access.log main; root /usr/share/nginx/html; location / { root /usr/share/nginx/html; index index.html index.htm; limit_req zone=req_zone; } }
p.php是phpinfo
ab -n 20 -c 20 http://192.168.1.251/p.php
结果是
Concurrency Level: 20
Time taken for tests: 0.071 seconds
Complete requests: 20
Failed requests: 3
(Connect: 0, Receive: 0, Length: 3, Exceptions: 0)
Write errors: 0
Total transferred: 1645517 bytes
HTML transferred: 1642257 bytes
Requests per second: 282.81 [#/sec] (mean)
Time per request: 70.719 [ms] (mean)
Time per request: 3.536 [ms] (mean, across all concurrent requests)
Transfer rate: 22723.03 [Kbytes/sec] received
而压测静态文件结果是
ab -n 20 -c 20 http://192.168.1.251/1.html
Concurrency Level: 20
Time taken for tests: 0.022 seconds
Complete requests: 20
Failed requests: 19
(Connect: 0, Receive: 0, Length: 19, Exceptions: 0)
Write errors: 0
Non-2xx responses: 19
Total transferred: 8843 bytes
HTML transferred: 4928 bytes
Requests per second: 892.38 [#/sec] (mean)
Time per request: 22.412 [ms] (mean)
Time per request: 1.121 [ms] (mean, across all concurrent requests)
Transfer rate: 385.32 [Kbytes/sec] received
为什么差距那么大呢?