作者:E4b9a6, 创建:2021-02-20, 字数:3601, 已阅:35, 最后更新:2021-02-20
对于Web服务程序来讲,衡量并发性能通常会用到QPS(Queries Per Second)
和TPS(Transactions Per Second)
以上2个指标可以使用ab
(http)或singe
(https)来做简单测试
安装ab
程序
sudo apt install apache
使用ab
来测试并发性,-n表示请求总数,-c表示请求并发数
ab -n 1000 -c 100 http://www.baidu.com/
例子:使用10个并发数请求1000次 ** http://www.baidu.com/** 如下
❯ ab -n 1000 -c 10 http://www.baidu.com/
~
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking v.hao123.baidu.com [through 10.0.0.155:3128] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: Apache
Server Hostname: v.hao123.baidu.com
Server Port: 80
Document Path: /dongman/
Document Length: 28430 bytes
# 并发数
Concurrency Level: 10
# 总请求时间
Time taken for tests: 32.629 seconds
# 完成的请求(包含失败)
Complete requests: 1000
# 失败的请求
Failed requests: 13
(Connect: 0, Receive: 0, Length: 13, Exceptions: 0)
Non-2xx responses: 11
Total transferred: 28799265 bytes
HTML transferred: 28109801 bytes
# 每秒请求数(系统吞吐量)
Requests per second: 30.65 [#/sec] (mean)
# 请求平均等待时间(毫秒)
Time per request: 326.287 [ms] (mean)
# 服务器平均处理时间
Time per request: 32.629 [ms] (mean, across all concurrent requests)
Transfer rate: 861.95 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 1
Processing: 1 323 672.7 224 7378
Waiting: 1 205 588.6 119 7201
Total: 2 323 672.7 224 7378
Percentage of the requests served within a certain time (ms)
50% 224
66% 267
75% 305
80% 343
# 90%的请求在447毫秒内返回
90% 447
95% 620
98% 927
99% 3514
100% 7378 (longest request)
ab压力测试HTTPS通常会有不支持证书等问题,所以也可以使用siege来做压力测试
sudo apt install siege
使用siege来测试并发数,-c表示并发数,-r表示重复次数
siege -c 20 -r 10 https://www.baidu.com
举例如下
❯ siege -c 20 -r 10 https://www.baidu.com
{
"transactions": 4217,
"availability": 93.03,
"elapsed_time": 185.07,
"data_transferred": 55.28,
"response_time": 0.35,
"transaction_rate": 22.79,
"throughput": 0.30,
"concurrency": 7.90,
"successful_transactions": 4250,
"failed_transactions": 316,
"longest_transaction": 14.54,
"shortest_transaction": 0.07
}
其参数含义如下
参数 | 解释 |
---|---|
transactions | 请求总次数 |
availability | 请求成功百分比 |
elapsed_time | 请求所耗费总时间 |
data_transferred | 请求总数据量大小 |
response_time | 请求的响应时间 |
transaction_rate | 请求的处理请求频率 |
throughput | 系统吞吐量(网络传输速度) |
concurrency | 请求并发连接数 |
successful_transactions | 请求成功次数 |
failed_transactions | 请求失败次数 |
longest_transaction | 请求最大耗时 |
shortest_transaction | 请求最短耗时 |