一個命令行web接口測試工具
基本信息
#查看當前版本
ab -V
#查看幫助
ab --help
格式:
ab [options] [http[s]://]hostname[:port]/path
常用參數
-n
總請求次數
-c
並發數
-t
測試所進行的最大秒數,默認沒有時間限制
-r
拋出異常繼續執行測試任務
-p
包含了需要 POST 的數據的文件,文件格式根據-T
決定
-T
POST 數據所使用的 Content-type 頭信息,如-T "application/json"
,配合-p
使用
-H
header參數,例-H "token:xxx"
;多個參數時使用多個-H
-C
Cookie參數,例如-C name=value
-w
以 HTML 表的格式輸出結果
請求用例
GET請求
ab -n 100 -c 10 https://www.baidu.com/
POST請求
ab \
-n 10 \
-c 2 \
-C PAGODA_JSESSIONID=3dad67d1-ce05-48f1-b173-19383dc69ec2 \
-T "application/json;charset=UTF-8" \
-p parm.json \
https://erp2.ktest.pagoda.com.cn/erp_pur/PurOrderService/findOrderListByParams
parm.json
{
"createdAtStart": "2022-02-01 00:00:00",
"createdAtEnd": "2022-02-25 23:59:59",
"pageable": {
"pageNumber": 0,
"pageSize": 15
},
"type": 10
}
保存結果為HTML文件
ab -n 100 -c 10 -w https://www.baidu.com/ > abRes.html
結果說明
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 www.baidu.com (be patient).....done
Server Software: BWS/1.1
Server Hostname: www.baidu.com
Server Port: 443
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
Server Temp Key: ECDH P-256 256 bits
TLS Server Name: www.baidu.com
Document Path: /
Document Length: 227 bytes
Concurrency Level: 10
Time taken for tests: 0.857 seconds #測試的持續時間
Complete requests: 100 #完成的請求數量
Failed requests: 0 #失敗的請求數量
Total transferred: 111094 bytes
HTML transferred: 22700 bytes
Requests per second: 116.75 [#/sec] (mean) #吞吐率:每秒請求完成數(TPS)
Time per request: 85.652 [ms] (mean) #平均TPS響應時間
Time per request: 8.565 [ms] (mean, across all concurrent requests)
Transfer rate: 126.66 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 41 58 8.8 56 88
Processing: 12 17 4.3 16 36
Waiting: 12 17 3.8 16 34
Total: 58 75 8.9 73 104
Percentage of the requests served within a certain time (ms)
50% 73
66% 77
75% 80
80% 83
90% 89
95% 94
98% 98
99% 104
100% 104 (longest request)