本页译自英文,由模型翻译。若与英文原文存在差异,以英文原文为准。
开销
框架自身代码在每条消息上的开销,以指令数和内存分配次数计,以及这些开销花在哪里。
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, unknown, Linux 7.3.0-3-moloko, 1.99.1, 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,tokio. ruststream 0.8.0, 测量于 2026-11-01.
以表格显示数字
| 场景 | 指令数 | 内存分配 | 冷启动 |
|---|---|---|---|
| consume, JSON decode into a small struct | 1,697.4 | 0 | 16,282 / 26 |
| consume, JSON decode of a 1 KB body | 17,304.2 | 0 | 32,028 / 26 |
| consume on the byte lane, no codec | 862.4 | 0 | 15,563 / 26 |
| consume through a pool of four workers | 3,131.8 | 0 | 29,529 / 43 |
| consume on four dedicated threads | 461.4 | 0 | 56,438 / 133 |
| consume through a middleware stack of one | 1,742.3 | 0 | 16,700 / 26 |
| consume through a middleware stack of four | 1,785.3 | 0 | 16,742 / 26 |
| consume in batches of 64 | 1,516.2 | 0 | 18,273 / 28 |
| consume in batches of 64 through a pool of four workers | 1,538.8 | 0 | 33,921 / 45 |
| reply, encoded to a declared destination | 2,583.4 | 1 | 18,881 / 28 |
| reply to a transport that reads the payload | 2,051.4 | 0 | 18,136 / 29 |
| publish through an Out slot with one transform | 3,143.4 | 2 | 19,056 / 29 |
| publish through an Out slot to a transport that reads the payload | 2,570.4 | 1 | 18,907 / 31 |
| publish with a typed header contract | 3,589.4 | 4 | 19,789 / 31 |
| read a typed header contract, then publish | 3,972.3 | 1 | 19,464 / 28 |
| request and reply, one round trip | 8,920.9 | 10 | 24,823 / 36 |
| a continuation left behind by every delivery | 3,456.6 | 2 | 17,781 / 28 |
| a delivery that asks to be redelivered, natively by the broker | 3,270.5 | 0 | 17,914 / 26 |
| a delayed redelivery the runtime publishes as a copy | 9,531.1 | 6 | 25,096 / 32 |
这些数字是进程内 Broker 上每条消息的稳态开销,不包含任何传输。鼠标悬停或聚焦时,该行会显示冷启动:启动服务并处理第一条消息一共花掉的开销,只付一次。
接收一条消息不做任何内存分配。循环为消息保留一个槽位和一个编码缓冲区,每个阶段都是在编译期确定的泛型类型,途中没有动态调用。在运行时组装的 DynStack 每层每条消息花费一个装箱的 future。and_after 后续任务是一个装箱的 future,只有设置了它的消息才需要付出。
如果 Broker 客户端只读取字节,应答不做任何内存分配:它借用循环的缓冲区。进程内 Broker 会保留交给它的内容,所以它的应答要付出编解码器写入的那块缓冲区。其余发布场景分配的,是进程内 Broker 为每条消息保留的内容,以及场景自己构建的东西:一个消息头的值,或一个请求的一次性收件箱。
解码中最贵的是消息内容的大小:对比 1 KB 的消息体和小结构体。基准测试公布了每个场景及其方法,也包括与各 Broker 裸客户端的对照。