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

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

开销

框架自身代码在每条消息上的开销,以指令数和内存分配次数计,以及这些开销花在哪里。

每条消息的指令数与内存分配

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
consume, JSON decode of a 1 KB body
17,402.8
0
consume on the byte lane, no codec
826
0
consume through a pool of four workers
3,092.1
0
consume on four dedicated threads
457.1
0
consume through a middleware stack of one
1,723
0
consume through a middleware stack of four
1,768
0
consume in batches of 64
1,529.5
0
reply, encoded to a declared destination
2,641
2
reply to a transport that reads the payload
2,106
0
publish through an Out slot with one transform
3,768
6
publish with a typed header contract
3,632
5
read a typed header contract, then publish
4,004.9
2
request and reply, one round trip
9,361.6
13
a delivery that asks to be redelivered, natively by the broker
3,157.7
0
以表格显示数字
场景指令数内存分配冷启动
consume, JSON decode into a small struct1,673015,079 / 26
consume, JSON decode of a 1 KB body17,402.8030,936 / 26
consume on the byte lane, no codec826014,192 / 26
consume through a pool of four workers3,092.1027,005 / 43
consume on four dedicated threads457.1055,119 / 133
consume through a middleware stack of one1,723015,205 / 26
consume through a middleware stack of four1,768015,252 / 26
consume in batches of 641,529.5016,432 / 29
reply, encoded to a declared destination2,641216,787 / 29
reply to a transport that reads the payload2,106016,294 / 29
publish through an Out slot with one transform3,768618,540 / 33
publish with a typed header contract3,632517,990 / 32
read a typed header contract, then publish4,004.9217,762 / 29
request and reply, one round trip9,361.61323,358 / 39
a delivery that asks to be redelivered, natively by the broker3,157.7016,662 / 26

这些数字是进程内 Broker 上每条消息的稳态开销,不包含任何传输。鼠标悬停或聚焦时,该行会显示冷启动:启动服务并处理第一条消息一共花掉的开销,只付一次。

接收一条消息不做任何内存分配。循环为消息保留一个槽位和一个编码缓冲区,每个阶段都是在编译期确定的泛型类型,途中没有动态调用。在运行时组装的 DynStack 每层每条消息花费一个装箱的 future。and_after 后续任务是一个装箱的 future,只有设置了它的消息才需要付出。

如果 Broker 客户端只读取字节,应答不做任何内存分配:它借用循环的缓冲区。进程内 Broker 会保留交给它的内容,所以它的应答要付出编解码器写入的那块缓冲区。其余发布场景分配的,是进程内 Broker 为每条消息保留的内容,以及场景自己构建的东西:一个消息头的值,或一个请求的一次性收件箱。

解码中最贵的是消息内容的大小:对比 1 KB 的消息体和小结构体。基准测试公布了每个场景及其方法,也包括与各 Broker 裸客户端的对照。