本页译自英文,由模型翻译。若与英文原文存在差异,以英文原文为准。
基准测试
ruststream-sqs-sns 在每条消息上的开销:与裸 aws-sdk-sqs 客户端对照的吞吐量,以及它自身代码的指令数和内存分配次数。
与裸客户端对照
第一张图对同一个 SQS 端点把每个场景用三种方式运行。裸客户端 直接驱动 aws-sdk-sqs。Broker crate 用一个自己的循环驱动本 crate 的订阅,上面没有运行时。RustStream 是用户写的服务:应用里的一个 #[subscriber] 处理器。第一项差值是本 crate 比它所封装的客户端多付出的开销,第二项是运行时在其上增加的开销。
每个循环画成一条横条,从最佳一轮延伸到最慢的一轮,圆点标出最佳一轮,缺口标出中位一轮。坐标轴的零点是裸客户端的最佳一轮,圆点在零点右侧表示更慢。空心圆点表示该循环与裸客户端的差异小于各轮的波动范围。图表下方的表格列出最佳一轮,括号里是中位数。
两个场景都用一次单独的 DeleteMessage 删除每条消息,因为这正是 ack 在这里做的事。FIFO 场景把消息分散到 64 个消息组上,因此被扣住的组绝不会决定速度,消息组一页用图说明了这一点。
代码的开销
第二张图统计一条消息在服务线程上的开销:稳态下 callgrind 测得的指令数和 DHAT 测得的内存分配次数。每个场景都是一个基于 SqsBroker、连接同一个端点的服务。计数包括框架的分发和本 crate 的代码,也包括 AWS SDK 在该线程上的工作:构建并签名每个请求、HTTP 交换,以及解析每个应答。这部分工作占了每个数字的大部分,因此这些数字不能与客户端在自己线程上工作的 Broker 的数字相比较。冷启动 是加载 AWS 配置、解析队列、读取它的可见性超时并取得第一条消息一次性付出的开销。
结果
- 裸客户端
- Broker crate
- RustStream
- 各轮,从最佳到最慢
- 最佳一轮
- 中位一轮
- 轮次的波动范围
- 无法区分
ruststream-sqs-sns 0.7.0 on ruststream 0.7.0, AMD Ryzen 9 7900X 12-Core Processor, Linux 7.2.10-x64v3-xanmod1-1, localstack/localstack:4.14.0 (the LocalStack emulator, not the hosted service) in Docker on localhost, 测量于 2026-10-18. 这些数字是怎样测得的
- 无法区分
- 无法区分
- 无法区分
- +1.8%
以表格显示数字
| 场景 | 裸客户端 | Broker crate | RustStream | 额外开销 |
|---|---|---|---|---|
| Standard queue, 512 B JSON, delete per message | 724 msg/s (711) | 705 msg/s (621) (比客户端 无法区分) | 718 msg/s (687) | 无法区分 |
| FIFO queue, 64 message groups, 512 B JSON, delete per message | 692 msg/s (691) | 686 msg/s (685) (比客户端 无法区分) | 679 msg/s (679) | +1.8% |
AMD Ryzen 9 7900X 12-Core Processor, x86_64, 427-5912 MHz, 12 physical, 24 logical, 62.4 GiB, unknown, Linux 7.2.10-x64v3-xanmod1-1, 1.99.0, 3.25.1, bench, inheriting release (opt-level = 3, lto = fat, codegen-units = 16, debug = line-tables-only), ruststream-sqs-sns default (none), ruststream macros,json. ruststream-sqs-sns 0.7.0, ruststream 0.7.0, 测量于 2026-10-18.
以表格显示数字
| 场景 | 指令数 | 内存分配 | 冷启动 |
|---|---|---|---|
| standard queue, JSON decode into a small struct, delete per message | 454,735.5 | 461.3 | 2,514,593 / 2,728 |
| reply through the default SqsPublish policy, one SendMessage each | 823,549.6 | 871.3 | 2,541,645 / 2,729 |
| batches of 10, one ReceiveMessage each, delete per message | 452,297.8 | 461.3 | 2,534,373 / 2,730 |
机器
| 处理器 | AMD Ryzen 9 7900X 12-Core Processor |
|---|---|
| 架构 | x86_64 |
| 频率 | 427-5912 MHz |
| 核心数 | 12 physical, 24 logical |
| 内存 | 62.4 GiB |
| 内存速度 | unknown |
| 操作系统 | Linux 7.2.10-x64v3-xanmod1-1 |
| Broker | localstack/localstack:4.14.0 (the LocalStack emulator, not the hosted service) in Docker on localhost |
| 往返时间 | 612 us per request to the stand |
| 编译器 | 1.99.0 |
| 构建配置 | bench, inheriting release (opt-level = 3, lto = fat, codegen-units = 16, debug = line-tables-only) |
| 特性 | ruststream-sqs-sns default (none), ruststream macros,json |
| RUSTFLAGS | none (the recipe clears RUSTFLAGS, so the numbers are not tied to this CPU) |
| Valgrind | 3.25.1 |
数字来自本版本的 docs/benchmarks/results.json,由基准测试命令写入。方法论说明它们是怎样测得的,数字说明可以从中得出什么结论。