Skip to content

bench: measure how fanout cost scales with subscriber count - #31

Merged
userFRM merged 1 commit into
masterfrom
bench/fanout-scaling
Jul 27, 2026
Merged

userFRM merged 1 commit into
masterfrom
bench/fanout-scaling

Conversation

@userFRM

@userFRM userFRM commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Users could not tell what this crate buys them, because nothing measured the property it is built around.

Delivering one message to N consumers is O(N) work somewhere. The useful question is where it lands, and whether the producer pays it. benches/fanout_scaling.rs measures the same logical work across four shapes — publish once, then have all N consumers observe it — single-threaded and in-cache, isolating protocol overhead from scheduling.

N consumers 1 2 4 8 16 32 marginal
photon 3.9 5.9 8.5 14.9 25.9 50.2 1.5 ns
shared-ring broadcast 47.7 65.5 99.2 167.3 306.9 579.6 17.2 ns
point-to-point, one per consumer 22.3 44.3 87.8 176.5 351.3 701.9 21.9 ns
point-to-point, one per consumer (alt) 27.4 53.9 108.7 217.6 428.4 859.3 26.8 ns

The marginal column is the result: a subscriber costs roughly one cursor read and one stamp check, because subscribers share no state, so the producer's work does not grow with the audience.

Published with the caveats that make it honest. The numbers are single-threaded and in-cache, so they measure protocol overhead and do not predict cross-core fanout latency. And a point-to-point queue is not broadcast — fanning out means the producer sends once per consumer, so that row shows what broadcast costs on a queue that doesn't do broadcast, not a race those libraries lost. They solve the different and equally real problem of exactly one receiver owning each message, and both tables say so.

Reproducible with cargo bench --bench fanout_scaling.

Verified: 219 tests, clippy clean, rustdoc clean, HTML tag balance checked.

Users could not tell what this crate buys them, because nothing measured the property it is built around. Delivering one message to N consumers is O(N) work somewhere; the useful question is where it lands and whether the producer pays it.

benches/fanout_scaling.rs measures the same logical work across four shapes: publish once, then have all N consumers observe it. Single-threaded and in-cache, so it isolates protocol overhead rather than scheduling.

Time in nanoseconds at N = 1, 2, 4, 8, 16, 32, and the marginal cost of one more consumer:

  photon                    3.9   5.9   8.5  14.9  25.9   50.2     1.5 ns
  shared-ring broadcast    47.7  65.5  99.2 167.3 306.9  579.6    17.2 ns
  point-to-point (x N)     22.3  44.3  87.8 176.5 351.3  701.9    21.9 ns
  point-to-point alt (x N) 27.4  53.9 108.7 217.6 428.4  859.3    26.8 ns

The marginal column is the result. A subscriber here costs roughly one cursor read and one stamp check because subscribers share no state, so the producer's work does not grow with the audience.

Published with the caveats that make it honest: the numbers are single-threaded and in-cache, so they do not predict cross-core fanout latency; and a point-to-point queue is not broadcast, so its row shows what broadcast costs on a queue that does not do broadcast rather than a race it lost. Those libraries solve the different and equally real problem of exactly one receiver owning each message, and the tables say so.
@userFRM
userFRM merged commit afa5673 into master Jul 27, 2026
18 checks passed
@userFRM
userFRM deleted the bench/fanout-scaling branch July 27, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant