#benchmark #http-request #framework #connection #server #requests #latency

app rewrk

一个简单的 HTTP 压力测试工具

1 个不稳定版本

0.3.2 2023年6月28日

#335 in 性能分析

MIT 许可协议

215KB
1K SLoC

rewrk

一个更现代的 HTTP 框架基准工具。

F:\rewrk> rewrk -h http://127.0.0.1:5000 -t 12 -c 60 -d 5s

Benchmarking 60 connections @ http://127.0.0.1:5000 for 5 seconds
  Latencies:
    Avg      Stdev    Min      Max    
    3.27ms   0.40ms   1.95ms   9.39ms
  Requests:
    Total:  91281  Req/Sec: 18227.81
  Transfer:
    Total: 1.13 MB Transfer Rate: 231.41 KB/Sec

可选 --pct 标志

+ --------------- + --------------- +
|   Percentile    |   Avg Latency   |
+ --------------- + --------------- +
|      99.9%      |     6.88ms      |
|       99%       |     5.62ms      |
|       95%       |     4.62ms      |
|       90%       |     4.24ms      |
|       75%       |     3.78ms      |
|       50%       |     3.49ms      |
+ --------------- + --------------- +

动机

这个项目的动机源于开发者对像 techempower 这样的基准测试的盲点,这些测试使用了名为 wrk 的基准测试工具。

问题在于 wrk 只处理 HTTP 规范的一部分,并且完全偏向于可以大量使用 HTTP/1 Pipelining 的框架和服务器,而这种情况在大多数现代浏览器或客户端中已不再启用,这可能导致比较框架时产生非常不公平和不合理的统计数据,因为那些位于顶部的是在现在不再广泛使用的流程中表现更好的。

这就是 rewrk 的用武之地,这个基准测试器建立在 hyper 的客户端 API 之上,并带来了许多优点和更真实的基准测试方法。

当前功能

  • 支持 HTTP/1 和 HTTP/2
  • 禁用了流水线,以提供更真实的性能概念。
  • 跨平台支持,虽然在 Windows 上开发,但也可以在 Mac 和 Linux 上运行。

待办事项

  • 添加随机人工延迟基准测试,以模拟与客户端的随机延迟。
  • 算术基准测试,以模拟客户端之间的不同负载。
  • 状态检查,使框架和服务器使用所有 API 而不仅仅是最小化集。
  • JSON 反序列化和验证基准测试和检查。
  • 真正并发 HTTP/2 基准测试。

用法

使用相对简单,如果你有一个编译好的二进制文件,只需使用 CLI 运行。

示例

以下是一个示例,生成以下基准测试

  • 256 个连接 (-c 256)
  • 仅支持HTTP/2 (--http2)
  • 12个线程 (-t 12)
  • 15秒 (-d 15s)
  • 带有百分比表 (--pct)
  • 在主机 http://127.0.0.1:5000 上 (-h http://127.0.0.1:5000)

CLI命令
rewrk-c256 -t12 -d 15s-h http://127.0.0.1:5000 --http2 --pct

CLI帮助

要显示帮助菜单,只需运行 rewrk --help 即可生成此帮助信息

USAGE:
    rewrk.exe [FLAGS] [OPTIONS] --duration <duration> --host <host>

FLAGS:
        --help       Prints help information
        --http2      Set the client to use http2 only. (default is http/1) e.g. '--http2'
        --pct        Displays the percentile table after benchmarking.
    -V, --version    Prints version information

OPTIONS:
    -c, --connections <connections>    Set the amount of concurrent e.g. '-c 512' [default: 1]
    -d, --duration <duration>          Set the duration of the benchmark.
    -h, --host <host>                  Set the host to bench e.g. '-h http://127.0.0.1:5050'
    -t, --threads <threads>            Set the amount of threads to use e.g. '-t 12' [default: 1]

从源代码构建

从源代码构建非常简单,只需确保在开始之前安装了一个稳定的Rust版本。

使用Cargo安装

    • 运行 cargo install rewrk --git https://github.com/ChillFish8/rewrk.git

使用Cargo运行

    • 克隆存储库源代码
    • 运行 cargo run --release -- <输入标志这里>

使用Cargo构建

    • 克隆存储库源代码
    • 运行 cargo build --release
    • 从发布文件夹中提取二进制文件
    • 二进制文件已准备好使用。

依赖项

~10–23MB
~329K SLoC