如何估算 网站峰值 RPS ?

目标
估算网站系统,峰值 RPS。
概念
PV: page view,即页面被浏览的次数。
RPS: Requests per second,即每秒请求次数。
关于 QPS/RPS 概念,详见 如何使用 sysbench 对 RDS进行压力测试
峰值 RPS
原理:按照二八原则,网站每天 80%的访问量集中在 20% 的时间里,这20%时间叫做峰值时间。
公式:( 总PV数 * 80% ) / ( 每天秒数 * 20% ) = 峰值时间每秒请求数(RPS)。
机器:峰值时间每秒 RPS / 单台机器的RPS = 需要的机器。
举个栗子
假设,某 Web系统每天有 1000万 PV访问量,这个网站需要准备多少 RPS?
RPS: ( 10000000 * 0.8 ) / (86400 * 0.2 ) = 463
再假设,经过测试单台服务器有效处理能力为 100 RPS,需要多少服务器?
服务器: 463 / 100 = 5台
使用 ab 压力测试
使用 apche ab 工具,对某项目网站Web系统进行压测,共4次每次间隔 5分钟。
1. 测试过程
第1次测试,请求:1000 并发:100 RPS: 1048/s 平均等待时间: 95.463 /ms
ab -n 1000 -c 100 
...省略
Benchmarking  (be patient)
Completed 100 requests
...省略
Completed 1000 requests
Finished 1000 requests
Server Software:        
Server Hostname:       
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
...省略
Benchmarking 
Completed 100 requests
...省略
Completed 1000 requests
Finished 1000 requests
Server Software:        
Server Hostname:      
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:       
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:      


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)
2. 测试小结
a. 压测端与服务器端,在相同的网络,所以网络带宽不是瓶颈。
b. RPS 随着并发数的增加而减少,系统负载升高,CPU 成为瓶颈。
c. 平均等待时间,并发数成正比,即并发数量越大,用户等待时间越长,直到Web系统拒绝响应(见 SSL握手失败)
扩展: 测试原则&关键点
不同系统对最大负载的要求不一样。就通常的 web网站来说基本指标是:在合理的响应时间内,系统能提供最大的每秒请求数(QPS/RPS/TPS)。
1. 合理响应时间,3-5s是一个合格的网站渲染首屏最多花费的时间,如果单纯看最大qps而不管响应时间的话,这个测试是无意义的;
2. 每个页面包含的功能不一样多,所以指标也定不相同,那么访问最频繁的页面的性能指标应该是我们最关注的;
3. web网站大多读写急不平衡,但在有持续写入的情况下测试出来的指标与单纯读指标的对比,对判断锁的性能很有帮助;
4. 最重要的一点是,刚创业的站点应多注意快速开发业务,心里有性能这根弦,不犯愚蠢错误就足够了。等站点真正做出来再回头调优,应该是个甜蜜的过程。

猜你喜欢

转载自www.cnblogs.com/chenjianshi/p/10003862.html