Skip to content

吞吐量相关计算公式推导

发布于  at 14:46

使用apachebench(mac 自带)进行一次压测:

ab -c30 -t6 http://127.0.0.1:3000/test

输出如下:

This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 5000 requests
Finished 9201 requests


Server Software:
Server Hostname:        127.0.0.1
Server Port:            3000

Document Path:          /test
Document Length:        40 bytes

Concurrency Level:      30
Time taken for tests:   6.000 seconds
Complete requests:      9201
Failed requests:        3
   (Connect: 0, Receive: 0, Length: 3, Exceptions: 0)
Total transferred:      1821996 bytes
HTML transferred:       368237 bytes
Requests per second:    1533.46 [#/sec] (mean)
Time per request:       19.564 [ms] (mean)
Time per request:       0.652 [ms] (mean, across all concurrent requests)
Transfer rate:          296.54 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0      16
Processing:     0    1   4.9      0     283
Waiting:        0    0   4.9      0     283
Total:          0    1   4.9      0     284

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      1
 100%    284 (longest request)

首先,挑出几个最容易理解的基本数据:

下面进入推导:

总结

QPS

TPS的计算方式和QPS一样,取决于c代表的意义。 公式大概就这几个,根据已知条件自行变换,例如:

concurrency (平均并发数 = 平均响应时间 * 平均每秒请求数)

分享到: