Skip to content

吞吐量相关计算公式推导 #4

Closed

Description

@bowencool

使用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)

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

  • 总任务数量 (num of request)
    n = 9201
  • 本次测试持续时间 (timelimit)
    t = 6s
  • 平均并发数 (concurrency)
    c = 30

下面进入推导:

  • 每秒请求数(Requests/Queries per second,RPS/QPS)

    QPS

  • 累计处理时间

  • 平均响应时间(Time per request,Response Time)

总结

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

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

Activity

  1. Repository owner locked and limited conversation to collaborators on Jan 19, 2024
  2. converted this issue into a discussion #54 on Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions