本页译自英文,由模型翻译。若与英文原文存在差异,以英文原文为准。
基准测试
ruststream-zeromq 在每条消息上的开销:与裸 zeromq 客户端对照的吞吐量,以及它自身代码的指令数和内存分配次数。
与裸客户端对照
第一张图在真实的套接字上把每个场景用三种方式运行。裸客户端 直接驱动 zeromq 套接字。Broker crate 用一个自己的循环驱动本 crate 的订阅,上面没有运行时。RustStream 是用户写的服务:应用里的一个 #[subscriber] 处理器。第一项差值是本 crate 比它所封装的客户端多付出的开销,第二项是运行时在其上增加的开销。
每个循环画成一条横条,从最佳一轮延伸到最慢的一轮,圆点标出最佳一轮,缺口标出中位一轮。坐标轴的零点是裸客户端的最佳一轮,圆点在零点右侧表示更慢。空心圆点表示该循环与裸客户端的差异小于各轮的波动范围。图表下方的表格列出最佳一轮,括号里是中位数。
两个场景都是 PUSH/PULL,分别运行在本 crate 支持的两种传输上:环回地址上的 tcp:// 和 ipc://。两者只在消息穿过内核的路径上不同,因此这一对场景显示出开销中有多少属于套接字。
每个循环的另一端都是同一进程里的一个套接字,因为 ZeroMQ 的对端彼此直接通信,方法论一页说明了这一点。
代码的开销
第二张图统计一条消息在服务线程上的开销:稳态下 callgrind 测得的指令数和 DHAT 测得的内存分配次数。每个场景都是基于生产 Broker 的服务,绑定到环回地址上的一个端口,对端运行在自己的线程上。计数包括框架的分发、本 crate 的代码,以及 zeromq 客户端在该线程上的组帧。对端的线程和内核不计入。冷启动 是启动服务、接受对端的连接并取得第一条消息一次性付出的开销。
结果
- 裸客户端
- Broker crate
- RustStream
- 各轮,从最佳到最慢
- 最佳一轮
- 中位一轮
- 轮次的波动范围
- 无法区分
ruststream-zeromq 0.7.0 on ruststream 0.7.0, AMD Ryzen 9 7900X 12-Core Processor, Linux 7.2.10-x64v3-xanmod1-1, none: ZeroMQ has no broker, so the peer is a PUSH socket in the same process, over tcp:// on the loopback and over ipc://, with default socket options (the zeromq crate exposes no high-water mark), 测量于 2026-10-18. 这些数字是怎样测得的
- 无法区分
- 无法区分
- 无法区分
- +3.4%
以表格显示数字
| 场景 | 裸客户端 | Broker crate | RustStream | 额外开销 |
|---|---|---|---|---|
| PUSH/PULL over tcp:// on the loopback, 512 B JSON | 241,721 msg/s (237,164) | 238,327 msg/s (237,795) (比客户端 无法区分) | 241,545 msg/s (231,957) | 无法区分 |
| PUSH/PULL over ipc://, 512 B JSON | 972,020 msg/s (955,055) | 952,265 msg/s (934,673) (比客户端 无法区分) | 939,038 msg/s (936,838) | +3.4% |
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-zeromq default (none), ruststream macros,json. ruststream-zeromq 0.7.0, ruststream 0.7.0, 测量于 2026-10-18.
以表格显示数字
| 场景 | 指令数 | 内存分配 | 冷启动 |
|---|---|---|---|
| PUSH/PULL on the loopback, JSON decode into a small struct, ack each | 5,036.1 | 5 | 1,075,776 / 614 |
| DEALER/ROUTER on the loopback, answered to the requesting peer | 13,686 | 18 | 1,090,494 / 632 |
| PUSH/PULL on the loopback, in batches of 64 assembled on the client | 5,017.1 | 5 | 1,082,736 / 618 |
机器
| 处理器 | 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 |
| 传输 | none: ZeroMQ has no broker, so the peer is a PUSH socket in the same process, over tcp:// on the loopback and over ipc://, with default socket options (the zeromq crate exposes no high-water mark) |
| 往返时间 | tcp:// 15.8 us, ipc:// 11.1 us (20000 REQ/REP exchanges on the same transport, outside every loop) |
| 编译器 | 1.99.0 |
| 构建配置 | bench, inheriting release (opt-level = 3, lto = fat, codegen-units = 16, debug = line-tables-only) |
| 特性 | ruststream-zeromq 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,由基准测试命令写入。方法论说明它们是怎样测得的,数字说明可以从中得出什么结论。