今天用apache的小工具ab测试apache及nginx两个webserver的响应速度。平时总能在网上看到nginx比apache如何如何强的帖子,但自己从来没有测试过。今天有空测试了一下。相同的代码、相同网络状况相同的数据库。
对比情况如下:
apache:
Document Length: 3960 bytes
Concurrency Level: 10
Time taken for tests: 0.604543 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Total transferred: 42400 bytes
HTML transferred: 39600 bytes
Requests per second: 16.54 [#/sec] (mean)
Time per request: 604.543 [ms] (mean)
Time per request: 60.454 [ms] (mean, across all concurrent requests)
Transfer rate: 67.82 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 2 2 0.0 2 2
Processing: 22 363 252.5 390 602
Waiting: 21 275 175.3 382 389
Total: 24 365 252.5 392 604
Percentage of the requests served within a certain time (ms)
50% 392
66% 598
75% 602
80% 602
90% 604
95% 604
98% 604
99% 604
100% 604 (longest request)
nginx:
Document Length: 3960 bytes
Concurrency Level: 10
Time taken for tests: 0.104265 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Total transferred: 42120 bytes
HTML transferred: 39600 bytes
Requests per second: 95.91 [#/sec] (mean)
Time per request: 104.265 [ms] (mean)
Time per request: 10.426 [ms] (mean, across all concurrent requests)
Transfer rate: 393.23 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 9 11 2.1 11 15
Processing: 29 61 21.2 70 88
Waiting: 25 59 21.7 68 87
Total: 38 73 23.0 81 103
Percentage of the requests served within a certain time (ms)
50% 81
66% 87
75% 92
80% 101
90% 103
95% 103
98% 103
99% 103
100% 103 (longest request)
apache:最长响应的时间——604ms 每秒事务数——16.54 [#/sec] 平均事务响应时间——604.543 [ms]
nginx:最长响应的时间——103ms 每秒事务数——95.91 [#/sec] 平均事务响应时间——104.265 [ms]
想到过nginx比apache强,但是都是别人说的自己是头一回亲眼见证,这大大的增强了我更换webserver的决心。
至于有人说:apache比起nginx相对安全与稳定就如上面的说法一样,我也是听别人说的。回头自己亲自测试一下。实践方能出真知!
测试命令:
ab -n 10 -c 10 http://www.microsoft.com/
-n:发请求次数
-c:每次发请求的数量(并发concurrency )
转载于:https://blog.51cto.com/yjw1983/737171