如何估算网站RPS峰值?
2018-06-05 by dongnan
目标
估算网站RPS
峰值
概念
- PV:
page view
即页面被浏览的次数。 - RPS:
Requests per second
即每秒请求次数。
二八定律
- 峰值: 按照二八定律的思想,网站每天
80%
的访问量集中在20%
的时间里,这段20%
时间叫做峰值时间。 - 公式: 峰值
RPS = (总PV数 * 80%) / (每天秒数 * 20%)
。 - 资源: 简单来理解就是服务器,
服务器 = 峰值RPS / 单台机器的最大RPS
。
举个栗子
假设,某项目网站每天有 1000万PV
访问量,设计这个网站需要多少峰值RPS
?
(10000000 * 0.8) / (86400 * 0.2) = 463/s
再假设,经过压力测试单台服务器最大RPS为 100/s
,需要多少台服务器?
答案是大约5台 463 / 100 = 5
再再假设,考虑整个网站系统设计具有30%
的冗余性,那么需要多少台服务器?
答案是大约7台 5 + 5 * 0.3
压力测试
使用 apache
压力测试工具,对某项目网站系统进行压测,共4次每次间隔 5分钟。
测试过程
第1次测试,请求:1000
并发:100
RPS:1048/s
平均等待时间:95.463/ms
。
ab -n 1000 -c 100 https://www.demo.com/passport/login
# ...省略
Benchmarking www.demo.com (be patient)
Completed 100 requests
# ...省略
Completed 1000 requests
Finished 1000 requests
Server Software:
Server Hostname: www.demo.com
Server Port: 443
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
Document Path: /passport/login
Document Length: 10668 bytes
Concurrency Level: 100
Time taken for tests: 0.955 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 11242000 bytes
HTML transferred: 10668000 bytes
Requests per second: 1047.53 [#/sec] (mean)
Time per request: 95.463 [ms] (mean)
Time per request: 0.955 [ms] (mean, across all concurrent requests)
Transfer rate: 11500.28 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 8 48 45.2 36 320
Processing: 9 43 11.7 45 94
Waiting: 9 38 11.1 40 90
Total: 19 91 45.9 83 361
Percentage of the requests served within a certain time (ms)
50% 83
# ...省略
99% 319
100% 361 (longest request)
第2次测试,请求:1000
并发:200
RPS:951.34/s
平均等待时间:210.231/ms
。
ab -n 1000 -c 200 https://www.demo.com/passport/login
# ...省略
Benchmarking www.demo.com (be patient)
Completed 100 requests
...省略
Completed 1000 requests
Finished 1000 requests
Server Software:
Server Hostname: www.demo.com
Server Port: 443
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
Document Path: /passport/login
Document Length: 10668 bytes
Concurrency Level: 200
Time taken for tests: 1.051 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 11242000 bytes
HTML transferred: 10668000 bytes
Requests per second: 951.34 [#/sec] (mean)
Time per request: 210.231 [ms] (mean)
Time per request: 1.051 [ms] (mean, across all concurrent requests)
Transfer rate: 10444.26 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 7 88 80.8 61 519
Processing: 9 76 36.8 84 299
Waiting: 8 54 30.5 49 247
Total: 16 164 90.7 162 567
Percentage of the requests served within a certain time (ms)
50% 162
# ...省略
99% 399
100% 567 (longest request)
第3次测试,请求:1000
并发:300
RPS:806.40/s
平均等待时间:372.023/ms
。
ab -n 1000 -c 300 https://www.demo.com/passport/login
# ...省略
Benchmarking www.demo.com (be patient)
Completed 100 requests
# ...省略
Finished 1000 requests
Server Software:
Server Hostname: www.demo.com
Server Port: 443
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
Document Path: /passport/login
Document Length: 10668 bytes
Concurrency Level: 300
Time taken for tests: 1.240 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 11242000 bytes
HTML transferred: 10668000 bytes
Requests per second: 806.40 [#/sec] (mean)
Time per request: 372.023 [ms] (mean)
Time per request: 1.240 [ms] (mean, across all concurrent requests)
Transfer rate: 8853.09 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 8 131 124.2 94 1009
Processing: 9 117 52.1 116 433
Waiting: 9 64 43.2 51 263
Total: 18 249 140.9 201 1041
Percentage of the requests served within a certain time (ms)
50% 201
# ...省略
99% 757
100% 1041 (longest request)
第4次测试,请求:5000
并发:100
RPS:589.81/s
平均等待时间:169.546/ms
其它: 出现 SSL握手失败。
ab -n 5000 -c 100 https://www.demo.com/passport/login
# ...省略
Benchmarking www.demo.com (be patient)
Completed 500 requests
# ...省略
Completed 3000 requests
SSL handshake failed (5).
# ...省略
Finished 5000 requests
Server Software:
Server Hostname: www.demo.com
Server Port: 443
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
Document Path: /passport/login
Document Length: 10668 bytes
Concurrency Level: 100
Time taken for tests: 8.477 seconds
Complete requests: 5000
Failed requests: 1
(Connect: 0, Receive: 0, Length: 1, Exceptions: 0)
Write errors: 0
Total transferred: 56198758 bytes
HTML transferred: 53329332 bytes
Requests per second: 589.81 [#/sec] (mean)
Time per request: 169.546 [ms] (mean)
Time per request: 1.695 [ms] (mean, across all concurrent requests)
Transfer rate: 6473.94 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 130 305.0 13 3019
Processing: 5 29 47.7 17 823
Waiting: 8 27 41.7 16 622
Total: 5 160 310.5 34 3035
Percentage of the requests served within a certain time (ms)
50% 34
# ...省略
99% 1246
100% 3035 (longest request)
测试小结
- 压测端与服务器端,在相同的网络,所以网络带宽不是瓶颈。
- RPS 随着并发数的增加而减少,系统负载升高、CPU成为瓶颈。
- 平均等待时间,并发数成正比,即并发数量越大,用户等待时间越长,直到网站系统拒绝响应(SSL握手失败)。
RPS测试原则
不同系统对最大负载的要求不一样。就通常的网站来说基本指标是:在合理的响应时间内,系统能提供最大的每秒请求数(QPS/RPS/TPS)。
- 合理响应时间,
3-5s
是一个合格的网站渲染首屏最多花费的时间,如果单纯看最大qps
而不管响应时间的话,这个测试是无意义的。 - 每个页面包含的功能不一样多,所以指标也定不相同,那么访问最频繁的页面的性能指标应该是我们最应该关注的。
- 最重要的一点是,刚创业的站点应多注意快速开发业务,心里有性能这根弦,不犯愚蠢错误就足够了。等站点真正做出来再回头调优,应该是个甜蜜的过程。