同样的环境,大小差不了几个字节的页面,
Nginx的worker_connections 1024;
Apache的MaxClients 150,worker模式;
照理说压Nginx如果用1024个并发压效果是最好的,同样压apache并发150的话效果也是最好的。
Nginx的测试结果:
[root@localhost nginx-0.7.19]# ab -t 60 -c 1024 http://192.168.1.101:8080/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.116 $> apache-2.0 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.1.101 (be patient) Completed 5000 requests Completed 10000 requests Completed 15000 requests Completed 20000 requests Completed 25000 requests Completed 30000 requests Completed 35000 requests Completed 40000 requests Completed 45000 requests Finished 50000 requests Server Software: nginx/0.7.19 Server Hostname: 192.168.1.101 Server Port: 8080 Document Path: / Document Length: 151 bytes Concurrency Level: 1024 Time taken for tests: 28.791802 seconds Complete requests: 50000 Failed requests: 0 Write errors: 0 Total transferred: 18100000 bytes HTML transferred: 7550000 bytes Requests per second: 1736.61 [#/sec] (mean) Time per request: 589.656 [ms] (mean) Time per request: 0.576 [ms] (mean, across all concurrent requests) Transfer rate: 613.89 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 19.0 0 2998 Processing: 33 531 448.3 458 3452 Waiting: 10 298 457.2 237 3415 Total: 33 531 448.7 458 3452 Percentage of the requests served within a certain time (ms) 50% 458 66% 466 75% 478 80% 483 90% 502 95% 599 98% 3409 99% 3428 100% 3452 (longest request)
Nginx5000个请求只花费了28秒就搞定。
Apache的测试结果:
[root@localhost nginx-0.7.19]# ab -t 60 -c 150 http://192.168.1.101/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.116 $> apache-2.0 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.1.101 (be patient) Completed 5000 requests Completed 10000 requests Completed 15000 requests Completed 20000 requests Completed 25000 requests Completed 30000 requests Completed 35000 requests Finished 39842 requests Server Software: Apache/2.2.10 Server Hostname: 192.168.1.101 Server Port: 80 Document Path: / Document Length: 44 bytes Concurrency Level: 150 Time taken for tests: 60.74169 seconds Complete requests: 39842 Failed requests: 0 Write errors: 0 Total transferred: 11953500 bytes HTML transferred: 1753180 bytes Requests per second: 663.21 [#/sec] (mean) Time per request: 226.172 [ms] (mean) Time per request: 1.508 [ms] (mean, across all concurrent requests) Transfer rate: 194.31 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 47.5 0 3000 Processing: 62 223 696.2 111 12013 Waiting: 0 156 605.3 58 9025 Total: 62 224 701.2 111 12013 Percentage of the requests served within a certain time (ms) 50% 111 66% 119 75% 125 80% 129 90% 159 95% 191 98% 3011 99% 3017 100% 12013 (longest request)
Apache一分钟只搞定了4000个请求。
再试试,Nginx的并发150时候的速度:
[root@localhost nginx-0.7.19]# ab -t 60 -c 150 http://192.168.1.101:8080/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.116 $> apache-2.0 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.1.101 (be patient) Completed 5000 requests Completed 10000 requests Completed 15000 requests Completed 20000 requests Completed 25000 requests Completed 30000 requests Completed 35000 requests Completed 40000 requests Completed 45000 requests Finished 50000 requests Server Software: nginx/0.7.19 Server Hostname: 192.168.1.101 Server Port: 8080 Document Path: / Document Length: 151 bytes Concurrency Level: 150 Time taken for tests: 27.603372 seconds Complete requests: 50000 Failed requests: 0 Write errors: 0 Total transferred: 18100000 bytes HTML transferred: 7550000 bytes Requests per second: 1811.37 [#/sec] (mean) Time per request: 82.810 [ms] (mean) Time per request: 0.552 [ms] (mean, across all concurrent requests) Transfer rate: 640.32 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 19.0 0 2998 Processing: 3 81 222.2 63 3066 Waiting: 0 47 216.0 31 3021 Total: 3 81 223.0 63 3066 Percentage of the requests served within a certain time (ms) 50% 63 66% 64 75% 65 80% 66 90% 70 95% 75 98% 86 99% 91 100% 3066 (longest request)
此次和上次Nginx1024个并发相比快了一秒钟,27秒搞定50000个请求
再试试,Apache的并发1024时候的速度:
我估计会被压死,先把帖子发出去,没压死再修改。。。
[root@localhost nginx-0.7.19]# ab -t 60 -c 1024 http://192.168.1.101/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.116 $> apache-2.0 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.1.101 (be patient) Finished 2737 requests Server Software: Apache/2.2.10 Server Hostname: 192.168.1.101 Server Port: 80 Document Path: / Document Length: 44 bytes Concurrency Level: 1024 Time taken for tests: 75.767759 seconds Complete requests: 2737 Failed requests: 0 Write errors: 0 Total transferred: 821100 bytes HTML transferred: 120428 bytes Requests per second: 36.12 [#/sec] (mean) Time per request: 28347.164 [ms] (mean) Time per request: 27.683 [ms] (mean, across all concurrent requests) Transfer rate: 10.57 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 20 248.8 0 3002 Processing: 15158 20495 5117.8 18237 36418 Waiting: 23 9583 5978.2 9136 21205 Total: 15158 20516 5119.1 18238 39402 Percentage of the requests served within a certain time (ms) 50% 18238 66% 21138 75% 21187 80% 21197 90% 24196 95% 36319 98% 36415 99% 36417 100% 39402 (longest request)
居然没有死机! 结论:在我本机当前环境下,Nginx处理高并发小请求的速度要快于Apache。
开始用nginx的时候大家都说它比apache快很多,所以纯跑一下http看谁处理短连接更快,没有关注apache是否比nginx更稳定。
现在用nginx在生产上的项目并不多,apache还是主流,就是因为apache的稳定大家都信任,而nginx还没经受过长时间的考验。
你说的没错,apache很稳定!