目录
- 参数说明
- 示例1:压力测试
- 示例2:测试post接口
- post数据文件该如何编写?
- apr_pollset_poll: The timeout specified has expired (70007)
- apr_socket_recv: Connection reset by peer (104)
- 参考
参数说明
官方文档参考这里。
ab -c 100 -n 10000 -k -r https://www.baidu.com/
- -c:concurrency,每次发送的请求次数,默认一次一个。如:-c 100 表示每次发送100个请求,模拟100人同时访问。
- -n:requests,本次测试的总请求数。
- 上面命令的含义:每次发送100个请求,共发送10000个请求。
示例1:压力测试
shell> ab -c 100 -n 10000 -k -r https://www.baidu.com/
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 www.baidu.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requestsServer 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.comDocument Path: /
Document Length: 227 bytesConcurrency Level: 100
Time taken for tests: 6.655 seconds
Complete requests: 10000
Failed requests: 0
Keep-Alive requests: 0
Total transferred: 13929176 bytes
HTML transferred: 2270000 bytes
Requests per second: 1502.72 [#/sec] (mean)
Time per request: 66.546 [ms] (mean)
Time per request: 0.665 [ms] (mean, across all concurrent requests)
Transfer rate: 2044.11 [Kbytes/sec] receivedConnection Times (ms)min mean[+/-sd] median max
Connect: 36 51 4.4 51 200
Processing: 12 15 4.6 14 205
Waiting: 12 14 4.1 13 205
Total: 54 66 6.1 65 267Percentage of the requests served within a certain time (ms)50% 6566% 6675% 6780% 6890% 6995% 7198% 7599% 78100% 267 (longest request)
示例2:测试post接口
ab -c 100 -n 1000 -r -k -p postdata_001_001.txt -T 'application/json' https://xxx.xxx.xxx/api
- postdata_001_001.txt 为post数据文件。post数据文件中的内容与接口所需参数保持一致。
post数据文件该如何编写?
可能是这样
uid=1&data={"username": "admin", "msg":"并发测试","type": "txt", "file": "","time":"2021-12-22
也可能是这样
{
"address":"124",
"amount":125
}
如果不能确定是什么样,可以先用接口测试工具测通,从接口测试工具中将post数据导出并保存成post数据文件。以apifox为例:
apr_pollset_poll: The timeout specified has expired (70007)
加个-k参数
apr_socket_recv: Connection reset by peer (104)
加个-r参数
参考
http://httpd.apache.org/docs/2.2/programs/ab.html
Apache Bench(ab 压力测试工具)的安装与使用
https://www.cnblogs.com/yoyoketang/p/10255100.html