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

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

基准测试

ruststream-rumqttc 在每条消息上的开销:与裸 rumqttc 客户端对照的吞吐量,以及它自身代码的指令数和内存分配次数。

与裸客户端对照​

第一张图在真实的 MQTT 服务器上把每个场景用三种方式运行。裸客户端 直接驱动 rumqttc。Broker crate 用一个自己的循环驱动本 crate 的订阅,上面没有运行时。RustStream 是用户写的服务:应用里的一个 #[subscriber] 处理器。第一项差值是本 crate 比它所封装的客户端多付出的开销,第二项是运行时在其上增加的开销。

每个循环画成一条横条,从最佳一轮延伸到最慢的一轮,圆点标出最佳一轮,缺口标出中位一轮。坐标轴的零点是裸客户端的最佳一轮,圆点在零点右侧表示更慢。空心圆点表示该循环与裸客户端的差异小于各轮的波动范围。图表下方的表格列出最佳一轮,括号里是中位数。

两个场景就是服务读取消息时使用的两种服务质量。在 QoS 0 下,服务器发送每条消息,不结算任何东西。在 QoS 1 下,服务用 PUBACK 确认每个投递,路径一页用图说明了这一点。

代码的开销​

第二张图统计一条消息在服务线程上的开销:稳态下 callgrind 测得的指令数和 DHAT 测得的内存分配次数。每个场景都是一个基于 MqttBroker、在同一台服务器上读取 QoS 1 主题的服务。服务运行在一个线程上,轮询 rumqttc 事件循环的任务也运行在这个线程上,所以计数包括框架、本 crate 以及客户端自己在套接字上的工作,PUBACK 也在其中。生产者的线程不计入。冷启动 是连接、订阅并取得第一条消息一次性付出的开销。

结果​

与裸客户端对照各循环比裸客户端最佳一轮低多少
  • 裸客户端
  • Broker crate
  • RustStream
  • 各轮,从最佳到最慢
  • 最佳一轮
  • 中位一轮
  • 轮次的波动范围
  • 无法区分

ruststream-rumqttc 0.7.0 on ruststream 0.7.0, AMD Ryzen 9 7900X 12-Core Processor, Linux 7.2.11-x64v3-xanmod1-1, eclipse-mosquitto:2 in Docker on localhost, 测量于 2026-10-18. 这些数字是怎样测得的

QoS 0 topic, 512 B JSON
  • 无法区分
  • 无法区分
QoS 1 topic, 512 B JSON, ack each
  • 无法区分
  • 无法区分 (受 Broker 限制)
以表格显示数字
场景裸客户端Broker crateRustStream额外开销
QoS 0 topic, 512 B JSON154,259 msg/s (151,130)152,504 msg/s (137,593) (比客户端 无法区分)153,188 msg/s (151,410)无法区分
QoS 1 topic, 512 B JSON, ack each118,899 msg/s (118,745)117,722 msg/s (116,990) (比客户端 无法区分)118,792 msg/s (116,403)无法区分 (受 Broker 限制)
代码的开销

AMD Ryzen 9 7900X 12-Core Processor, x86_64, 427-5912 MHz, 12 physical, 24 logical, 62.4 GiB, unknown, Linux 7.2.11-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-rumqttc default (none), ruststream macros,json. ruststream-rumqttc 0.7.0, ruststream 0.7.0, 测量于 2026-10-18.

指令数
内存分配
QoS 1 topic, JSON decode into a small struct, ack each
8,769.5
1.2
QoS 1 topic, reply published through this crate's publisher
17,331.2
7.2
QoS 1 topic, batches of 64 assembled on the client
9,087.7
1.2
以表格显示数字
场景指令数内存分配冷启动
QoS 1 topic, JSON decode into a small struct, ack each8,769.51.23,820,572 / 67
QoS 1 topic, reply published through this crate's publisher17,331.27.23,828,301 / 74
QoS 1 topic, batches of 64 assembled on the client9,087.71.23,827,348 / 71

机器​

处理器AMD Ryzen 9 7900X 12-Core Processor
架构x86_64
频率427-5912 MHz
核心数12 physical, 24 logical
内存62.4 GiB
内存速度unknown
操作系统Linux 7.2.11-x64v3-xanmod1-1
Brokereclipse-mosquitto:2 in Docker on localhost
往返时间41.8 microseconds, measured as a QoS 1 publish whose PUBACK the client waits for, averaged over 20,000 exchanges on a connection of its own
编译器1.99.0
构建配置bench, inheriting release (opt-level = 3, lto = fat, codegen-units = 16, debug = line-tables-only)
特性ruststream-rumqttc default (none), ruststream macros,json
RUSTFLAGSnone (the recipe clears RUSTFLAGS, so the numbers are not tied to this CPU)
平均负载9.15 / 10.95 / 9.58 over 1, 5 and 15 minutes when the run ended
Valgrind3.25.1

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