28 个版本
| 0.1.20 | 2023年3月27日 |
|---|---|
| 0.1.18 | 2022年8月8日 |
| 0.1.17 | 2022年7月10日 |
| 0.1.15 | 2022年3月21日 |
| 0.0.7 | 2020年11月30日 |
406 在 网络编程 类别中排名
每月 93 次下载
6.5MB
2.5K SLoC
概述
网络服务的基准测试工具。目前仅限于HTTP(H1或H2,通过TCP或TLS)。但很容易扩展到其他协议。
它支持以下模式
ab类模式。只需向指定端点发送流量一段时间,或指定请求数量。- 无限请求速率(以找到最大吞吐量)。
- 选择请求速率和并发级别。
- 测量精度到
µs。
- 线性增加请求速率,例如,每分钟增加
1,000,以查看服务如何随着负载而扩展。 - 它可以通过
pushgateway将指标报告给Prometheus。
例如:
发出的指标包括
request_count- 所有请求的计数器success_count- 仅成功请求的计数器bytes_count- 总传输字节数response_codes- 响应代码(200、400等)的计数器success_latency- 仅成功请求的延迟直方图error_latency- 失败请求(如有)的延迟直方图throughput- 仅成功请求的吞吐量直方图latency- 所有请求的延迟直方图latency_{statistic}-{statistic} = {min, mean, max, stddev, p50, p90, p99, p99_9, p99_99, tm99, tm99.9, tm99.99}- 延迟统计仪表
例如,对不同语言的TCP代理进行基准测试:C、C++、Rust、Golang、Java、Python。
安装
对于MacOS、Ubuntu、Windows,您可以使用发布部分中的二进制文件。
或者您可以在您的机器上构建它
安装cargo - 按照这些说明进行。
在Debian上解决OpenSSL构建问题。例如,在Debian上
sudo apt-get install pkg-config libssl-dev
在Red-Hat
sudo dnf install pkg-config openssl-devel
# or
sudo yum install pkg-config openssl-devel
然后
$ cargo install perf-gauge --features full
支持的功能
default- 如果没有指定功能,则仅支持http流量tls-native- TLS支持(基于OpenSSL)tls-boring- TLS支持(基于BoringSSL)。不支持自签名证书。report-to-prometheus- 支持使用Prometheus进行指标收集full-report-to-prometheus+tls-nativefull-boring-report-to-prometheus+tls-boring
用法
$ perf-gauge help
Gauging performance of network services. Snapshot or continuous, supports Prometheus metrics.
USAGE:
perf-gauge [OPTIONS] <SUBCOMMAND>
OPTIONS:
-c, --concurrency <CONCURRENCY>
Concurrent clients. Default `1` [default: 1]
--continuous
If it's a part of a continuous run. In this case metrics are not reset at the end to
avoid saw-like plots
-d, --duration <DURATION>
Duration of the test
-h, --help
Print help information
-m, --max_iter <MAX_ITER>
takes_value "The number of iterations with the max rate. By default `1` [default: 1]
-n, --num_req <NUM_REQ>
Number of requests per client
-N, --name <NAME>
Test case name. Optional. Can be used for tagging metrics
--prometheus <PROMETHEUS>
If you'd like to send metrics to Prometheus PushGateway, specify the server URL. E.g.
10.0.0.1:9091
--prometheus_job <PROMETHEUS_JOB>
Prometheus Job (by default `pushgateway`)
-r, --rate <RATE>
Request rate per second. E.g. 100 or 0.1. By default no limit
--rate_max <RATE_MAX>
Max rate per second. Requires --rate-step
--rate_step <RATE_STEP>
Rate increase step (until it reaches --rate_max)
--request_timeout <REQUEST_TIMEOUT>
Timeout of a single request. E.g. "--request_timeout 30s". Timeouts are treated as fatal
errors
-V, --version
Print version information
SUBCOMMANDS:
help Print this message or the help of the given subcommand(s)
http Run in HTTP(S) mode
http命令的帮助
$ perf-gauge help http
Run in HTTP(S) mode
USAGE:
perf-gauge http [OPTIONS] [TARGET]...
ARGS:
<TARGET>... Target, e.g. https://my-service.com:8443/8kb Can be multiple ones (with
random choice balancing)
OPTIONS:
-B, --body <BODY> Body of the request. Could be either `random://[0-9]+`,
`file://$filename` or `base64://${valid_base64}`. Optional
--conn_reuse If connections should be re-used
-E, --error_stop <ERROR_STOP> Stop immediately on error codes. E.g. `-E 401 -E 403`
-h, --help Print help information
-H, --header <HEADER> Headers in \"Name:Value1\" form. Can be provided multiple
times. It can contain multiple values, e.g.
\"Name:Value1:Value2:Value3\". In this case a random one is
chosen for each request
--http2_only Enforce HTTP/2 only
--ignore_cert Allow self signed certificates
-M, --method <METHOD> Method. By default GET
-V, --version Print version information
例如,使用单次运行测试端点,5秒(最大可能的请求速率)
$ perf-gauge --concurrency 10 \
--duration 1m \
http https:///10kb --conn_reuse
参数
--concurrency 10- 生成负载的并发客户端数量--duration 1m- 步骤持续时间1m(或10s、5m等)http http://local-nginx.org/10kb --conn_reuse- 在http模式下运行到指定的端点,重用连接。
将性能指标报告给Prometheus
另一个用例是增加请求速率并观察延迟如何降低。
例如,每分钟增加1,000 RPS
export PROMETHEUS_HOST=10.138.0.2
$ perf-gauge --concurrency 10 \
--request_timeout 30s \
--rate 1000 --rate_step 1000 --rate_max 25000 \
--max_iter 15 \
--duration 1m \
--name nginx-direct \
--prometheus $PROMETHEUS_HOST:9091 \
http https:///10kb --conn_reuse --ignore_cert
--concurrency 10- 生成负载的并发客户端数量--request_timeout 30s- 如果响应超过30秒,则不等待响应并停止执行。--rate 1000 --rate_step 1000 --rate_max 25000- 以1000 rps的速率开始,然后在每个步骤后添加1000 rps,直到达到25k。--duration 1m- 步骤持续时间1m--max_iter 15- 以最大速率执行15次迭代--name nginx-direct- 测试名称(用于将指标报告到prometheus)--prometheus $PROMETHEUS_HOST:9091- 将指标推送到 Prometheus 的host:port推送网关。http http://local-nginx.org/10kb --conn_reuse- 以https模式运行到指定端点,重用连接且不检查证书。
依赖项
~11–31MB
~511K SLoC