本页译自英文,由模型翻译。若与英文原文存在差异,以英文原文为准。
开销
框架自身代码在每条消息上的开销,以指令数和内存分配次数计,以及这些开销花在哪里。
AMD Ryzen 9 7900X 12-Core Processor, x86_64 (x86-64-v4), base unknown, min 427 MHz, max 5912 MHz, 12 physical, 24 logical, 62.4 GiB, 4800 MT/s, 6000 MT/s, DDR5, Linux 7.2.9-x64v3-xanmod1-1, 1.99.0, 3.25.1, bench, inheriting release (opt-level = 3, lto = fat, codegen-units = 16, debug = line-tables-only), --no-default-features --features memory,macros,json. ruststream 0.7.0, 测量于 2026-10-06.
以表格显示数字
| 场景 | 指令数 | 内存分配 | 冷启动 |
|---|---|---|---|
| consume, JSON decode into a small struct | 1,673 | 0 | 15,079 / 26 |
| consume, JSON decode of a 1 KB body | 17,402.8 | 0 | 30,936 / 26 |
| consume on the byte lane, no codec | 826 | 0 | 14,192 / 26 |
| consume through a pool of four workers | 3,092.1 | 0 | 27,005 / 43 |
| consume on four dedicated threads | 457.1 | 0 | 55,119 / 133 |
| consume through a middleware stack of one | 1,723 | 0 | 15,205 / 26 |
| consume through a middleware stack of four | 1,768 | 0 | 15,252 / 26 |
| consume in batches of 64 | 1,529.5 | 0 | 16,432 / 29 |
| reply, encoded to a declared destination | 2,641 | 2 | 16,787 / 29 |
| reply to a transport that reads the payload | 2,106 | 0 | 16,294 / 29 |
| publish through an Out slot with one transform | 3,768 | 6 | 18,540 / 33 |
| publish with a typed header contract | 3,632 | 5 | 17,990 / 32 |
| read a typed header contract, then publish | 4,004.9 | 2 | 17,762 / 29 |
| request and reply, one round trip | 9,361.6 | 13 | 23,358 / 39 |
| a delivery that asks to be redelivered, natively by the broker | 3,157.7 | 0 | 16,662 / 26 |
这些数字是进程内 Broker 上每条消息的稳态开销,不包含任何传输。鼠标悬停或聚焦时,该行会显示冷启动:启动服务并处理第一条消息一共花掉的开销,只付一次。
接收一条消息不做任何内存分配。循环为消息保留一个槽位和一个编码缓冲区,每个阶段都是在编译期确定的泛型类型,途中没有动态调用。在运行时组装的 DynStack 每层每条消息花费一个装箱的 future。and_after 后续任务是一个装箱的 future,只有设置了它的消息才需要付出。
如果 Broker 客户端只读取字节,应答不做任何内存分配:它借用循环的缓冲区。进程内 Broker 会保留交给它的内容,所以它的应答要付出编解码器写入的那块缓冲区。其余发布场景分配的,是进程内 Broker 为每条消息保留的内容,以及场景自己构建的东西:一个消息头的值,或一个请求的一次性收件箱。
解码中最贵的是消息内容的大小:对比 1 KB 的消息体和小结构体。基准测试公布了每个场景及其方法,也包括与各 Broker 裸客户端的对照。