文章

压力测试工具

1. wrk-http(s)压力测试

1.1 安装

1
2
3
4
5
# 项目地址:
https://github.com/wg/wrk

# 安装
下载之后,直接 make 编译 就会生成 wrk的二进制文件

1.2 使用

1
2
3
4
5
6
7
8
9
10
11
-c, --connections: HTTP连接的总数每个线程处理n =连接/线程
-d, --duration:    测试持续时间,例如2s,2m,2H
-t, --threads:     要使用的线程总数
-s, --script:      luajit脚本,请参阅脚本
-h, --header:      HTTP标头要添加到请求,例如“用户代理:WRK”
     --latency:     打印详细的延迟统计
     --timeout:     如果未在内收到响应,请记录超时这段时间。


wrk -t12 -c400 -d30s http://127.0.0.1:8080/index.html
用于:30秒,使用:12线程,并保持:400 打开HTTP连接

2. ab测试-压测

2.1 安装

1
yum -y install httpd-tools

2.2 使用

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
48
49
50
51
52
53
54
55
56
57
ab -n 1000 -c 10 https://json.im
-n 1000表示请求总数为1000
-c 10表示并发用户数为10
参数: 
-A:指定连接服务器的基本的认证凭据;认证
-c:指定一次向服务器发出请求数;并发数
-C:添加cookie;
-g:将测试结果输出为“gnuolot”文件;
-h:显示帮助信息;
-H:为请求追加一个额外的头;
-i:使用“head”请求方式;
-k:激活HTTP中的“keepAlive”特性;
-n:指定测试会话使用的请求数; 请求数量
-p:指定包含数据的文件;
-P:代理服务认证
-q:不显示进度百分比;
-T:使用POST数据时,设置内容类型头;
-v:设置详细模式等级;
-w:以HTML表格方式打印结果;
-x:以表格方式输出时,设置表格的属性;
-X:使用指定的代理服务器发送请求;代理服务器: ip:port  
-y:以表格方式输出时,设置表格属性。
eg:
ab -n 1000 -c 20 -A admin:admin -P admin:admin -X 220.179.102.210:2020 http://www.baidu.com/
ab压力测试返回报文内容详解
    Server Software: Apache #服务器软件
    Server Hostname: json.im #域名
    Server Port: 80 #请求端口号
    Document Path: / #文件路径
    Document Length: 40888 bytes #页面字节数
    Concurrency Level: 10 #请求的并发数
    Time taken for tests: 27.300 seconds #总访问时间
    Complete requests: 1000 #请求成功数量
    Failed requests: 0 #请求失败数量
    Write errors: 0
    Total transferred: 41054242 bytes #请求总数据大小(包括header头信息)
    HTML transferred: 40888000 bytes #html页面实际总字节数
    Requests per second: 36.63 [#/sec] (mean) #每秒多少请求,这个是非常重要的参数数值,服务器的吞吐量
    Time per request: 272.998 [ms] (mean) #用户平均请求等待时间
    Time per request: 27.300 [ms] (mean, across all concurrent requests) #服务器平均处理时间,也就是服务器吞吐量的倒数
    Transfer rate: 1468.58 [Kbytes/sec] received #每秒获取的数据长度
    Connection Times (ms)
    min mean[+/-sd] median max
    Connect: 43 47 2.4 47 53
    Processing: 189 224 40.7 215 895
    Waiting: 102 128 38.6 118 794
    Total: 233 270 41.3 263 945
    Percentage of the requests served within a certain time (ms)
    50% 263 #50%用户请求在263ms内返回
    66% 271 #66%用户请求在271ms内返回
    75% 279 #75%用户请求在279ms内返回
    80% 285 #80%用户请求在285ms内返回
    90% 303 #90%用户请求在303ms内返回
    95% 320 #95%用户请求在320ms内返回
    98% 341 #98%用户请求在341ms内返回
    99% 373 #99%用户请求在373ms内返回
    100% 945 (longest request)  #最大的请求时长

3. JMeter-java压测工具

本文由作者按照 CC BY 4.0 进行授权