使用wrk2压力测试WAF


这是我使用WRK2对我写的WAF压力测试的一些笔记。
我基于OpenRestyLua写了一个WAF,想测试一下性能,找来找去找到了wrk2这么一款压力测试工具。

wrk2是一个主要基于wrk的HTTP基准测试工具
wrk2经过修改后可以产生恒定的吞吐量负载,并且可以为高9s提供准确的延迟细节(即,当运行时间足够长时,可以产生准确的99.9999%的ile)。除了wrk的参数之外,wrk2还通过--rate或-R参数获取吞吐量参数(每秒总请求数)(默认值为1000)。
安装

git clone https://github.com/giltene/wrk2.git
cd wrk2
make

测试

./wrk -t5 -c500 -d30s -R200 http://127.0.0.1/?a=select * from

解释:打开5个线程,同时打开的连接为500个,持续30秒,每秒200个请求,请求的URL为http://127.0.0.1/?a=select * from
结果

Running 30s test @ http://127.0.0.1/?a=select
  5 threads and 500 connections
  Thread calibration: mean lat.: 0.920ms, rate sampling interval: 10ms
  Thread calibration: mean lat.: 0.863ms, rate sampling interval: 10ms
  Thread calibration: mean lat.: 0.876ms, rate sampling interval: 10ms
  Thread calibration: mean lat.: 0.868ms, rate sampling interval: 10ms
  Thread calibration: mean lat.: 0.909ms, rate sampling interval: 10ms
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.00ms  415.54us   2.62ms   66.46%
    Req/Sec    38.03     82.30   333.00     83.07%
  6005 requests in 30.01s, 5.11MB read
  Socket errors: connect 0, read 0, write 0, timeout 1508
Requests/sec:    200.12
Transfer/sec:    174.52KB

每秒请求量为200。

./wrk -t5 -c500 -d30s -R2000 http://127.0.0.1/?a=select * from

解释:打开5个线程,同时打开的连接为500个,持续30秒,每秒2000个请求,请求的URL为http://127.0.0.1/?a=select * from
结果

Running 30s test @ http://127.0.0.1/?a=select
  5 threads and 500 connections
  Thread calibration: mean lat.: 1.013ms, rate sampling interval: 10ms
  Thread calibration: mean lat.: 0.993ms, rate sampling interval: 10ms
  Thread calibration: mean lat.: 1.011ms, rate sampling interval: 10ms
  Thread calibration: mean lat.: 0.989ms, rate sampling interval: 10ms
  Thread calibration: mean lat.: 0.962ms, rate sampling interval: 10ms
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.00ms  443.00us   4.38ms   65.20%
    Req/Sec   417.59     53.72   666.00     81.95%
  59747 requests in 30.00s, 50.88MB read
Requests/sec:   1991.30
Transfer/sec:      1.70MB

每秒请求量为1991。

./wrk -t5 -c500 -d30s -R5000 http://127.0.0.1/?a=select * from

解释:打开5个线程,同时打开的连接为500个,持续30秒,每秒5000个请求,请求的URL为http://127.0.0.1/?a=select * from
结果

Running 30s test @ http://127.0.0.1/?a=select
  5 threads and 500 connections
  Thread calibration: mean lat.: 1.217ms, rate sampling interval: 10ms
  Thread calibration: mean lat.: 1.151ms, rate sampling interval: 10ms
  Thread calibration: mean lat.: 1.137ms, rate sampling interval: 10ms
  Thread calibration: mean lat.: 1.157ms, rate sampling interval: 10ms
  Thread calibration: mean lat.: 1.206ms, rate sampling interval: 10ms
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.17ms  515.50us   5.06ms   66.02%
    Req/Sec     1.05k   125.79     1.67k    79.57%
  148990 requests in 30.00s, 126.88MB read
Requests/sec:   4965.76
Transfer/sec:      4.23MB

每秒请求量为4965。

./wrk -t5 -c500 -d30s -R10000 http://127.0.0.1/?a=select * from

解释:打开5个线程,同时打开的连接为500个,持续30秒,每秒10000个请求,请求的URL为http://127.0.0.1/?a=select * from
结果

Running 30s test @ http://127.0.0.1/?a=select
  5 threads and 500 connections
  Thread calibration: mean lat.: 75.269ms, rate sampling interval: 78ms
  Thread calibration: mean lat.: 94.075ms, rate sampling interval: 92ms
  Thread calibration: mean lat.: 77.506ms, rate sampling interval: 80ms
  Thread calibration: mean lat.: 117.682ms, rate sampling interval: 316ms
  Thread calibration: mean lat.: 78.990ms, rate sampling interval: 81ms
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   278.83ms  633.90ms   4.42s    88.33%
    Req/Sec     1.98k   318.01     3.45k    86.06%
  294242 requests in 30.00s, 250.57MB read
  Socket errors: connect 0, read 0, write 0, timeout 52
Requests/sec:   9807.81
Transfer/sec:      8.35MB

每秒请求量为9807。

./wrk -t5 -c500 -d30s -R20000 http://127.0.0.1/?a=select * from

解释:打开5个线程,同时打开的连接为500个,持续30秒,每秒20000个请求,请求的URL为http://127.0.0.1/?a=select * from
结果

Running 30s test @ http://127.0.0.1/?a=select
  5 threads and 500 connections
  Thread calibration: mean lat.: 1317.152ms, rate sampling interval: 6418ms
  Thread calibration: mean lat.: 1166.639ms, rate sampling interval: 5292ms
  Thread calibration: mean lat.: 1293.208ms, rate sampling interval: 6111ms
  Thread calibration: mean lat.: 1206.496ms, rate sampling interval: 5230ms
  Thread calibration: mean lat.: 1314.024ms, rate sampling interval: 6496ms
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     5.15s     4.08s   22.82s    72.04%
    Req/Sec     2.42k   173.28     2.68k    60.00%
  357840 requests in 30.00s, 304.73MB read
  Socket errors: connect 0, read 0, write 0, timeout 2271
Requests/sec:  11927.99
Transfer/sec:     10.16MB

每秒请求量为11927。

./wrk -t5 -c500 -d30s -R30000 http://127.0.0.1/?a=select * from

解释:打开5个线程,同时打开的连接为500个,持续30秒,每秒30000个请求,请求的URL为http://127.0.0.1/?a=select * from
结果

Running 30s test @ http://127.0.0.1/?a=select
  5 threads and 500 connections
  Thread calibration: mean lat.: 2022.057ms, rate sampling interval: 6688ms
  Thread calibration: mean lat.: 1532.238ms, rate sampling interval: 5746ms
  Thread calibration: mean lat.: 1505.978ms, rate sampling interval: 5976ms
  Thread calibration: mean lat.: 9223372036854776.000ms, rate sampling interval: 10ms
  Thread calibration: mean lat.: 1482.885ms, rate sampling interval: 5984ms
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     7.42s     3.53s   28.05s    73.92%
    Req/Sec   195.35    321.70     3.53k    88.91%
  367423 requests in 30.00s, 312.89MB read
  Socket errors: connect 0, read 0, write 0, timeout 2682
Requests/sec:  12247.15
Transfer/sec:     10.43MB

每秒请求量为12247。

./wrk -t5 -c500 -d30s -R40000 http://127.0.0.1/?a=select * from

解释:打开5个线程,同时打开的连接为500个,持续30秒,每秒40000个请求,请求的URL为http://127.0.0.1/?a=select * from
结果

Running 30s test @ http://127.0.0.1/?a=select
  5 threads and 500 connections
  Thread calibration: mean lat.: 2666.320ms, rate sampling interval: 9437ms
  Thread calibration: mean lat.: 2554.859ms, rate sampling interval: 9797ms
  Thread calibration: mean lat.: 2658.172ms, rate sampling interval: 10436ms
  Thread calibration: mean lat.: 2539.604ms, rate sampling interval: 9691ms
  Thread calibration: mean lat.: 2523.757ms, rate sampling interval: 9568ms
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    11.63s     4.25s   28.38s    65.59%
    Req/Sec     2.33k   291.97     2.69k    62.50%
  356505 requests in 30.00s, 303.59MB read
  Socket errors: connect 0, read 0, write 0, timeout 2516
Requests/sec:  11883.50
Transfer/sec:     10.12MB

每秒请求量为11883。

./wrk -t5 -c500 -d30s -R50000 http://127.0.0.1/?a=select * from

解释:打开5个线程,同时打开的连接为500个,持续30秒,每秒50000个请求,请求的URL为http://127.0.0.1/?a=select * from
结果

Running 30s test @ http://127.0.0.1/?a=select
  5 threads and 500 connections
  Thread calibration: mean lat.: 3129.624ms, rate sampling interval: 11608ms
  Thread calibration: mean lat.: 2988.403ms, rate sampling interval: 11378ms
  Thread calibration: mean lat.: 3052.796ms, rate sampling interval: 11313ms
  Thread calibration: mean lat.: 3057.170ms, rate sampling interval: 11681ms
  Thread calibration: mean lat.: 3194.934ms, rate sampling interval: 11575ms
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    13.52s     4.35s   25.94s    62.64%
    Req/Sec     2.44k    75.76     2.51k    60.00%
  368120 requests in 30.00s, 313.49MB read
  Socket errors: connect 0, read 0, write 0, timeout 2585
Requests/sec:  12270.91
Transfer/sec:     10.45MB

每秒请求量为12270。
可见QPS为1.2万左右,对这个结果我已经很满意了,1C2G的机子这样的表现很不错了。
很显然在本机上测试本机应用是有性能损耗的,但是粗略测试也能说明性能问题,至少说明QPS>=1.2万。

声明:物博网|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - 使用wrk2压力测试WAF


喜欢安全与WEB开发