上一篇文章我们了解了bombardier,并知道了bombardier.yml与开源项目bombardier的关系,接下来的文章我们了解一下wrk、wrk2,并对比一下它们与bombardier的关系
wrk是一种现代 HTTP 基准测试工具,能够在单个多核 CPU 上运行时产生大量负载。它结合了多线程设计和可扩展的事件通知系统,例如 epoll 和 kqueue。
其支持参数:
-c, --connections: total number of HTTP connections to keep open with each thread handling N = connections/threads-d, --duration: duration of the test, e.g. 2s, 2m, 2h-t, --threads: total number of threads to use-s, --script: LuaJIT script, see SCRIPTING-H, --header: HTTP header to add to request, e.g. "User-Agent: wrk" --latency: print detailed latency statistics --timeout: record a timeout if a response is not received within this amount of time.基础用法:
运行了30秒的基准测试, 使用2个线程、100个http连接:
wrk -t2 -c100 -d30s http://127.0.0.1:8080/index.html进阶用法:
每次发送三个http请求:
wrk -t2 -c100 -d30s --script ./pipeline.lua http://127.0.0.1:8080新建pipeline.lua
-- example script demonstrating HTTP pipelininginit = function(args) local r = {} r[1] = wrk.format(nil, "/?foo") r[2] = wrk.format(nil, "/?bar") r[3] = wrk.format(nil, "/?baz") req = table.concat(r)endrequest = function() return reqendwrk2是一个主要基于 wrk 的 HTTP 基准测试工具。是一个被 wrk 修改以产生恒定的吞吐量负载,并将延迟细节精确到高 9s(即当运行足够长的时间时可以产生准确的 99.9999%'ile)。除了 wrk 的参数之外,wrk2 通过 --rate 或 -R 参数(默认为 1000)采用吞吐量参数(每秒总请求数)
除支持wrk的参数之外,还支持参数:
-R, --rate: 采用吞吐量参数(每秒总请求数),默认为1000基础用法:
运行了30秒的基准测试, 使用2个线程、100个http连接、并保持每秒2000个请求的恒定吞吐量:
wrk -t2 -c100 -d30s -R2000 http://127.0.0.1:8080/index.html高级用法与wrk一致,此处忽略不写
我们使用wrk2测试一下百度的压测情况
安装:
sudo apt install wgetsudo wget https://aspnetbenchmarks.blob.core.windows.net/tools/wrk2运行:
./wrk2 -d 3s -c 200 -t 200 -R 10 -L https://www.baidu.com输出了本次请求每秒请求次数、吞吐量以及详细情况:
在Microsoft.Crank.Jobs.Wrk项目中Program.cs
其中:
优势:
劣势:
wrk.yml的存在是为Microsoft.Crank.Jobs.Wrk提供配置参数,Microsoft.Crank.Jobs.Wrk通过调用开源项目wrk实现压测,并将压测结果通过BenchmarksEventSource存储并输出到控制台或数据库、csv、json中
wrk2是基于wrk二次开发,拥有所有wrk的配置,并且支持吞吐量限制,bombardier、wrk、wrk2都是http基准测试工具,丰富了crank对于Http的基准测试能力,三者之间并无优劣之分,根据三者之间的优劣势自行选择适合自己的即可
源码地址:https://github.com/doddgu/crank/tree/sample
MASA.BuildingBlocks:https://github.com/masastack/MASA.BuildingBlocks
MASA.Contrib:https://github.com/masastack/MASA.Contrib
MASA.Utils:https://github.com/masastack/MASA.Utils
MASA.EShop:https://github.com/masalabs/MASA.EShop
MASA.Blazor:https://github.com/BlazorComponent/MASA.Blazor
如果你对我们的 MASA Framework 感兴趣,无论是代码贡献、使用、提 Issue,欢迎联系我们

自动签名
欢迎加入技术交流群:
招.Net中/高级开发工程师:坐标杭州下沙,联系方式进群找群主,薪资范围16-30K,有住房补贴