跳到主要内容
英文版本为准

本页译自英文,由模型翻译。若与英文原文存在差异,以英文原文为准。

基准测试

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. 这些数字是怎样测得的

Standard queue, 512 B JSON, delete per message
  • 无法区分
  • 无法区分
FIFO queue, 64 message groups, 512 B JSON, delete per message
  • 无法区分
  • +1.8%
以表格显示数字
场景裸客户端Broker crateRustStream额外开销
Standard queue, 512 B JSON, delete per message724 msg/s (711)705 msg/s (621) (比客户端 无法区分)718 msg/s (687)无法区分
FIFO queue, 64 message groups, 512 B JSON, delete per message692 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
reply through the default SqsPublish policy, one SendMessage each
823,549.6
871.3
batches of 10, one ReceiveMessage each, delete per message
452,297.8
461.3
以表格显示数字
场景指令数内存分配冷启动
standard queue, JSON decode into a small struct, delete per message454,735.5461.32,514,593 / 2,728
reply through the default SqsPublish policy, one SendMessage each823,549.6871.32,541,645 / 2,729
batches of 10, one ReceiveMessage each, delete per message452,297.8461.32,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
Brokerlocalstack/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
RUSTFLAGSnone (the recipe clears RUSTFLAGS, so the numbers are not tied to this CPU)
Valgrind3.25.1

数字来自本版本的 docs/benchmarks/results.json,由基准测试命令写入。方法论说明它们是怎样测得的,数字说明可以从中得出什么结论。