短板是带宽
我当时目标很简单,如果我的网站能支撑1万个并发 在一分钟内处理完 就谢天谢地了。
经过一轮的折腾之后,我得出的经验是,上万的并发是有钱人的游戏,穷屌丝们只能在区域网里感叹一下
因为,木桶原理,短板在带宽上,最烧钱的也是带宽
假设站点的带宽是4Mbit/s 请求的页面大小是40kb,那么每秒只能处理的12个连接,一万个连接 要14分钟
每秒仅处理12个连接。。。 你还对内存有要求? 还是对CPU 有要求? 还是硬盘的读写速度跟不上了?还在乎用nginx还是apache?
Nginx 还是 Apache
大家都说nginx 在并发上多么多么的有优势,如果网站并发不超过2万,亲测Apache都稍优于Nginx 再大我没有测试过,所以我现在很是后悔以前跟风吹嘘nginx好,epoll好。。。。
我在阿里云一个8G 4核 (Intel Xeon E5-2682v4 / Intel Xeon(Skylake) Platinum 8163 2.5 GHz)的服务器 同时搭建了Apache和Nginx环境 使用ab命令测试的
nginx 10000次381秒
Server Software: nginx/1.12.2
Document Length: 39281 bytes
Concurrency Level: 10000
Time taken for tests: 381.031 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 395170000 bytes
HTML transferred: 392810000 bytes
Requests per second: 26.24 [#/sec] (mean)
Time per request: 381030.615 [ms] (mean)
Time per request: 38.103 [ms] (mean, across all concurrent requests)
Transfer rate: 1012.80 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 26 38 24.2 36 1444
Processing: 2114 192241 109289.0 193797 380294
Waiting: 28 190667 109446.4 192221 378970
Total: 2150 192279 109288.6 193832 380321
Percentage of the requests served within a certain time (ms)
50% 193832
66% 252949
75% 286462
80% 304815
90% 342882
95% 362196
98% 373041
99% 376604
100% 380321 (longest request)
Apache 10000次370秒
Server Software: Apache/2.4.6
Document Length: 39281 bytes
Concurrency Level: 10000
Time taken for tests: 369.933 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 395460000 bytes
HTML transferred: 392810000 bytes
Requests per second: 27.03 [#/sec] (mean)
Time per request: 369933.405 [ms] (mean)
Time per request: 36.993 [ms] (mean, across all concurrent requests)
Transfer rate: 1043.95 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 26 36 21.5 36 1436
Processing: 2168 184588 105904.3 183677 369183
Waiting: 28 182993 106063.1 182085 367833
Total: 2204 184624 105904.7 183715 369213
Percentage of the requests served within a certain time (ms)
50% 183715
66% 242029
75% 274513
80% 292806
90% 333280
95% 351313
98% 362069
99% 365738
100% 369213 (longest request)
这数据 简直难以启齿,没错 我发现带宽只有8M
那么高潮来了 我在阿里云的同区域网租了一台服务器 同样的环境 变成区域网内测试了
Apache 20000 11秒 (1万的并发都不好意思来测试了)
Server Software: Apache/2.4.6
Document Length: 39281 bytes
Concurrency Level: 20000
Time taken for tests: 11.584 seconds
Complete requests: 20000
Failed requests: 0
Write errors: 0
Total transferred: 790920000 bytes
HTML transferred: 785620000 bytes
Requests per second: 1726.48 [#/sec] (mean)
Time per request: 11584.234 [ms] (mean)
Time per request: 0.579 [ms] (mean, across all concurrent requests)
Transfer rate: 66675.35 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 280 615.8 0 4567
Processing: 0 239 429.5 155 8174
Waiting: 0 149 254.0 145 8173
Total: 1 519 838.9 164 10153
Percentage of the requests served within a certain time (ms)
50% 164
66% 320
75% 580
80% 1110
90% 1285
95% 1928
98% 3175
99% 3879
100% 10153 (longest request)
nginx 20000 11秒
Server Software: nginx/1.12.2
Document Length: 39281 bytes
Concurrency Level: 20000
Time taken for tests: 11.336 seconds
Complete requests: 20000
Failed requests: 0
Write errors: 0
Total transferred: 790340000 bytes
HTML transferred: 785620000 bytes
Requests per second: 1764.22 [#/sec] (mean)
Time per request: 11336.451 [ms] (mean)
Time per request: 0.567 [ms] (mean, across all concurrent requests)
Transfer rate: 68082.72 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 516 34.8 516 574
Processing: 572 3190 1618.7 3463 10669
Waiting: 0 754 906.9 475 6658
Total: 1039 3705 1626.3 4002 11237
Percentage of the requests served within a certain time (ms)
50% 4002
66% 4622
75% 4964
80% 5134
90% 5436
95% 5849
98% 6860
99% 7325
100% 11237 (longest request)