Linux ab压力测试工具安装教程

直接执行命令

yum install httpd-tools
1
通过 命令查看使用详解
ab --help或者man ab

使用

ab参数选项

-n:即requests,用于指定压力测试总共的执行次数(常用)。
-c:即concurrency,用于指定的并发数(常用)。
-t:即timelimit,等待响应的最大时间(单位:秒)。
-b:即windowsize,TCP发送/接收的缓冲大小(单位:字节)。
-p:即postfile,发送POST请求时需要上传的文件,此外还必须设置-T参数。
-u:即putfile,发送PUT请求时需要上传的文件,此外还必须设置-T参数。
-T:即content-type,用于设置Content-Type请求头信息,例如:application/x-www-form-urlencoded,默认值为text/plain。
-v:即verbosity,指定打印帮助信息的冗余级别。
-w:以HTML表格形式打印结果。
-i:使用HEAD请求代替GET请求。
-x:插入字符串作为table标签的属性。
-y:插入字符串作为tr标签的属性。
-z:插入字符串作为td标签的属性。
-C:添加cookie信息,例如:"Apache=1234"(可以重复该参数选项以添加多个)。
-H:添加任意的请求头,例如:"Accept-Encoding: gzip",请求头将会添加在现有的多个请求头之后(可以重复该参数选项以添加多个)。
-A:添加一个基本的网络认证信息,用户名和密码之间用英文冒号隔开。
-P:添加一个基本的代理认证信息,用户名和密码之间用英文冒号隔开。
-X:指定使用的和端口号,例如:"126.10.10.3:88"。
-V:打印版本号并退出。
-k:使用HTTP的KeepAlive特性。
-d:不显示百分比。
-S:不显示预估和警告信息。
-g:输出结果信息到gnuplot格式的文件中。
-e:输出结果信息到CSV格式的文件中。
-r:指定接收到错误信息时不退出程序。
-h:显示用法信息,其实就是ab -help。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
结果

##首先是apache的版本信息

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

Benchmarking xxx.xxx.com (be patient)


Server Software: nginx
Server Hostname: xxx.com #请求的域名
Server Port: 443 #请求端口

Document Path: /api/tree/tree
Document Length: 341 bytes #页面长度

Concurrency Level: 100 #并发数
Time taken for tests: 61.872 seconds #共使用了多少时间
Complete requests: 1000 #请求数
Failed requests: (Connect: 0, Receive: 0, Length: 987, Exceptions: 0) #请求结果
Write errors: 0
Total transferred: 646050 bytes #总共传输字节数,包含http的头信息等
HTML transferred: 78618 bytes #html字节数,实际的页面传递字节数
Requests per second: 16.16 [#/sec] (mean) #每秒多少请求,这个是非常重要的参数数值,服务器的吞吐量
Time per request: 6187.232 [ms] (mean) #用户平均请求等待时间
Time per request: 61.872 [ms] (mean, across all concurrent requests) ##服务器平均处理时间,也就是服务器吞吐量的倒数
Transfer rate: 10.20 [Kbytes/sec] received
5.84 kb/s sent
16.04 kb/s total #每秒获取的数据长度

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1735 3538.0 503 31189
Processing: 71 1421 2560.0 807 60062
Waiting: 71 1359 1763.2 804 29124
Total: 156 3156 4351.2 1935 60062

Percentage of the requests served within a certain time (ms)
50% 1935 # 50%的请求在1935ms内返回
66% 2719 # 60%的请求在2719ms内返回
75% 3541
80% 4147
90% 6728
95% 9040
98% 15850
99% 21795
100% 60062 (longest request)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
示例

ab -n 100 -c 10 -p "/www/wwwroot/AbTest/post.txt" -T "application/x-www-form-urlencoded" -H "Content-Type: application/x-www-form-urlencoded" -H "token:TGTf/KvAKE+b/KlwBQQ0ZCWe9qrQf/FXDiiKUl3YBdA" "https://xxxxx/api/tree/tree"
1
post.txt内容

room_id=11&game_type=2&number=1
————————————————
版权声明:本文为CSDN博主「科小洋-lmy」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_37468919/article/details/125482247

posted @ 2023-04-13 11:13  GaoYanbing  阅读(195)  评论(0编辑  收藏  举报