首页 压测工具wrk2安装与使用
文章
取消

压测工具wrk2安装与使用

简介

wrk2是非wrk作者基于wrk开发的压测工具,解决了协调遗漏问题(Coordinated Omission)

简单用几句话解释协调遗漏。压测发送请求时,10个请求都在10ms内完成,20个请求都在500ms内完成,你以为系统压力是10个请求以后?并不是。实际上请求a0(0点发送0点1ms接收),a1(0点1ms发送0点2ms接收),但是到了a10却是(0点500ms发送0点501ms接收),虽然a10依然只花费了1ms请求时间,但是系统处理能力明显已经开始很吃力了,不然a10应该是(0点10ms发送,0点11ms接收)。传统压测工具只会告诉你a10花费了1ms,而处理过协调遗漏的压测工具还会把500ms加进来,这样你就可以知道真实的系统压力是从什么时候开始的。

下图引用wrk2的说明示例,_CO为有过协调遗漏问题的请求。对比蓝色和红色的线,系统每秒发送16k请求时,传统压测工具给出压力发送到99.999%请求才开始突然爆炸,但是根据蓝线知道,实际上系统在收到99.9%的请求时压力已经开始慢慢增加了。

img1

安装

系统要求:ubuntu20.04

1
2
3
4
5
6
# apt isntall libssl-dev libzip-dev
# wget https://github.com/giltene/wrk2/archive/refs/heads/master.zip
# unzip master.zip
# cd wrk2-master
# make
# cp wrk /usr/local/bin/

使用

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
liuxu@liuxu-Inspiron-7559:~/$ wrk2 -d10 -t2 -c100 -R200 -L https://www.liuquanhao.com/ | tee result.txt
 Running 10s test @ https://www.liuquanhao.com/
  2 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   321.29ms  273.95ms   2.17s    79.17%
    Req/Sec       -nan      -nan   0.00      0.00%
  Latency Distribution (HdrHistogram - Recorded Latency)
 50.000%  244.35ms
 75.000%  406.53ms
 90.000%  699.39ms
 99.000%    1.21s
 99.900%    1.95s
 99.990%    2.17s
 99.999%    2.17s
100.000%    2.17s

  Detailed Percentile spectrum:
       Value   Percentile   TotalCount 1/(1-Percentile)

      15.079     0.000000            1         1.00
      70.847     0.100000          180         1.11
     119.039     0.200000          360         1.25
     161.535     0.300000          540         1.43
     206.847     0.400000          720         1.67
     244.351     0.500000          900         2.00
     263.935     0.550000          990         2.22
     282.623     0.600000         1080         2.50
     300.031     0.650000         1171         2.86
     319.743     0.700000         1260         3.33
     406.527     0.750000         1350         4.00
     441.855     0.775000         1395         4.44
     490.751     0.800000         1441         5.00
     536.063     0.825000         1485         5.71
     600.063     0.850000         1530         6.67
     655.359     0.875000         1575         8.00
     680.959     0.887500         1599         8.89
     699.391     0.900000         1620        10.00
     754.687     0.912500         1643        11.43
     798.207     0.925000         1666        13.33
     831.487     0.937500         1688        16.00
     867.839     0.943750         1699        17.78
     895.487     0.950000         1710        20.00
     932.863     0.956250         1722        22.86
     962.559     0.962500         1734        26.67
     986.623     0.968750         1744        32.00
     993.279     0.971875         1750        35.56
    1015.807     0.975000         1755        40.00
    1050.623     0.978125         1761        45.71
    1089.535     0.981250         1769        53.33
    1141.759     0.984375         1772        64.00
    1165.311     0.985938         1777        71.11
    1180.671     0.987500         1778        80.00
    1210.367     0.989062         1783        91.43
    1229.823     0.990625         1784       106.67
    1286.143     0.992188         1786       128.00
    1318.911     0.992969         1788       142.22
    1339.391     0.993750         1789       160.00
    1452.031     0.994531         1791       182.86
    1457.151     0.995313         1792       213.33
    1474.559     0.996094         1793       256.00
    1639.423     0.996484         1794       284.44
    1784.831     0.996875         1795       320.00
    1811.455     0.997266         1796       365.71
    1811.455     0.997656         1796       426.67
    1818.623     0.998047         1797       512.00
    1818.623     0.998242         1797       568.89
    1946.623     0.998437         1798       640.00
    1946.623     0.998633         1798       731.43
    1946.623     0.998828         1798       853.33
    2017.279     0.999023         1799      1024.00
    2017.279     0.999121         1799      1137.78
    2017.279     0.999219         1799      1280.00
    2017.279     0.999316         1799      1462.86
    2017.279     0.999414         1799      1706.67
    2172.927     0.999512         1800      2048.00
    2172.927     1.000000         1800          inf
#[Mean    =      321.286, StdDeviation   =      273.954]
#[Max     =     2170.880, Total count    =         1800]
#[Buckets =           27, SubBuckets     =         2048]
----------------------------------------------------------
  1802 requests in 10.10s, 18.05MB read
Requests/sec:    178.44
Transfer/sec:      1.79MB

以上例子为压测10秒,使用2个线程,并发100,每秒200请求压测。输出结果可以用wrk2项目的图表显示工具来查看,只需要上传输出的result.txt到这个网站就可以显示图表了,效果如上图。

知识共享许可协议 本文由作者按照 CC BY-SA 4.0 进行授权