通过之前的学习,我们已经了解了各参数以及配置的意义,接下来的文章我们分别从bombardier以及wrk入手,进一步了解彼此之间的联系
bombardier 是一个 HTTP(S) 基准测试工具。它是用 Go 编程语言编写的,并使用优秀的fasthttp代替 Go 的默认 http 库,因为它具有闪电般的快速性能,详细文档查看
其支持参数:
-c, --connections=125 Maximum number of concurrent connections-t, --timeout=2s Socket/request timeout-l, --latencies Print latency statistics-m, --method=GET Request method-b, --body="" Request body-f, --body-file="" File to use as request body-s, --stream Specify whether to stream body using chunked transfer encoding or to serve it from memory --cert="" Path to the client's TLS Certificate --key="" Path to the client's TLS Certificate Private Key-k, --insecure Controls whether a client verifies the server's certificate chain and host name-H, --header="K: V" ... HTTP headers to use(can be repeated)-n, --requests=[pos. int.] Number of requests-d, --duration=10s Duration of test-r, --rate=[pos. int.] Rate limit in requests per second --fasthttp Use fasthttp client --http1 Use net/http client with forced HTTP/1.x --http2 Use net/http client with enabled HTTP/2.0-p, --print=<spec> Specifies what to output. Comma-separated list of values 'intro' (short: 'i'), 'progress' (short: 'p'), 'result' (short: 'r'). Examples: * i,p,r (prints everything) * intro,result (intro & result) * r (result only) * result (same as above)-q, --no-print Don't output anything-o, --format=<spec> Which format to use to output the result. <spec> is either a name (or its shorthand) of some format understood by bombardier or a path to the user-defined template, which uses Go's text/template syntax, prefixed with 'path:' string (without single quotes), i.e. "path:/some/path/to/your.template" or "path:C:\some\path\to\your.template" in case of Windows. Formats understood by bombardier are: * plain-text (short: pt) * json (short: j)并且bombardier支持多平台,可以在Windows、Linux、OSX系统上运行,那接下来我们使用bombardier测试一下百度的压测情况
安装(WSL-Ubuntu):
sudo apt install wgetsudo wget https://github.com/codesenberg/bombardier/releases/download/v1.2.5/bombardier-linux-arm64运行:
./bombardier-linux-arm64 -c 200 -d 1s --insecure -l https://www.baidu.com --print r --format json其中:
在Microsoft.Crank.Jobs.Bombardier项目中Program.cs
bombardier -c 200 -d 1s --insecure -l https://www.baidu.com --print r --format json
其中
BenchmarksEventSource.Register("bombardier/requests;http/requests", Operations.Max, Operations.Sum, "Requests", "Total number of requests", "n0");BenchmarksEventSource.Register("bombardier/badresponses;http/requests/badresponses", Operations.Max, Operations.Sum, "Bad responses", "Non-2xx or 3xx responses", "n0");BenchmarksEventSource.Register("bombardier/latency/mean;http/latency/mean", Operations.Max, Operations.Avg, "Mean latency (us)", "Mean latency (us)", "n0");BenchmarksEventSource.Register("bombardier/latency/max;http/latency/max", Operations.Max, Operations.Max, "Max latency (us)", "Max latency (us)", "n0");BenchmarksEventSource.Register("bombardier/rps/mean;http/rps/mean", Operations.Max, Operations.Sum, "Requests/sec", "Requests per second", "n0");BenchmarksEventSource.Register("bombardier/rps/max;http/rps/max", Operations.Max, Operations.Sum, "Requests/sec (max)", "Max requests per second", "n0");BenchmarksEventSource.Register("bombardier/throughput;http/throughput", Operations.Max, Operations.Sum, "Read throughput (MB/s)", "Read throughput (MB/s)", "n2");BenchmarksEventSource.Register("bombardier/raw", Operations.All, Operations.All, "Raw results", "Raw results", "json");var total = document["result"]["req1xx"].Value<long>() + document["result"]["req2xx"].Value<long>() + document["result"]["req3xx"].Value<long>() + document["result"]["req3xx"].Value<long>() + document["result"]["req4xx"].Value<long>() + document["result"]["req5xx"].Value<long>() + document["result"]["others"].Value<long>();var success = document["result"]["req2xx"].Value<long>() + document["result"]["req3xx"].Value<long>();BenchmarksEventSource.Measure("bombardier/requests;http/requests", total);BenchmarksEventSource.Measure("bombardier/badresponses;http/requests/badresponses", total - success);BenchmarksEventSource.Measure("bombardier/latency/mean;http/latency/mean", document["result"]["latency"]["mean"].Value<double>());BenchmarksEventSource.Measure("bombardier/latency/max;http/latency/max", document["result"]["latency"]["max"].Value<double>());BenchmarksEventSource.Measure("bombardier/rps/max;http/rps/max", document["result"]["rps"]["max"].Value<double>());BenchmarksEventSource.Measure("bombardier/rps/mean;http/rps/mean", document["result"]["rps"]["mean"].Value<double>());BenchmarksEventSource.Measure("bombardier/raw", output);var bytesPerSecond = document["result"]["bytesRead"].Value<long>() / document["result"]["timeTakenSeconds"].Value<double>();// B/s to MB/sBenchmarksEventSource.Measure("bombardier/throughput", bytesPerSecond / 1024 / 1024);优势:
劣势:
bombardier.yml的存在是为Microsoft.Crank.Jobs.Bombardier提供配置参数,Microsoft.Crank.Jobs.Bombardier通过调用开源项目bombardier实现压测,并将压测结果通过BenchmarksEventSource存储并输出到控制台或数据库、csv、json中
源码地址: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,有住房补贴