通过之前的学习,我们已经了解了各参数以及配置的意义,接下来的文章我们分别从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= 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= Which format to use to output the result.
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 wget
sudo 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()
+ document["result"]["req2xx"].Value()
+ document["result"]["req3xx"].Value()
+ document["result"]["req3xx"].Value()
+ document["result"]["req4xx"].Value()
+ document["result"]["req5xx"].Value()
+ document["result"]["others"].Value();
var success = document["result"]["req2xx"].Value() + document["result"]["req3xx"].Value();
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());
BenchmarksEventSource.Measure("bombardier/latency/max;http/latency/max", document["result"]["latency"]["max"].Value());
BenchmarksEventSource.Measure("bombardier/rps/max;http/rps/max", document["result"]["rps"]["max"].Value());
BenchmarksEventSource.Measure("bombardier/rps/mean;http/rps/mean", document["result"]["rps"]["mean"].Value());
BenchmarksEventSource.Measure("bombardier/raw", output);
var bytesPerSecond = document["result"]["bytesRead"].Value() / document["result"]["timeTakenSeconds"].Value();
// B/s to MB/s
BenchmarksEventSource.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,欢迎联系我们
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,欢迎联系我们