Dispatch pubsub work only to recipient-owner proactors
perfloop/dragonfly · Fan Out
https://perfloop.ai/t/oss/case_tha75mg38a
Verdict
VERIFIED · settled 2026-11-05 · pull request opened as dragonflydb/dragonfly#8758
What happened: The paired measurements met the required improvement.
Hypothesis
A targeted source-path check showed that `Service::Publish` builds a one-element message array and calls `ChannelStore::SendMessages` once per PUBLISH. In `SendMessages`, the snapshot is sorted by owner thread, but the callback passed to `pool()->DispatchBrief` receives every worker index, runs `lower_bound` on the full snapshot, and sends only while that index owns a matching range. A focused pool API-use check also found `DbSlice::SendQueuedInvalidationMessages` documenting its sibling pool brief operation as a broadcast to threads unrelated to a key's subscribers, and `DispatchMonitor` uses the same indexed `DispatchBrief` shape to inspect per-thread monitor state. This is source evidence for the pool-wide fan-out, not a runtime measurement; no profile or latency benchmark was run. The hypothesized removed delta is one no-op cross-proactor callback plus one range search for each of T-H nonrecipient threads on the real cadence of every PUBLISH. Confirm with a reproducible pub/sub benchmark sweeping pool size T, occupied owner threads H, subscriber count, and message bytes; instrument executed brief callbacks and empty callbacks, collect CPU profiles and PUBLISH p50/p99 latency, and differentially verify delivery count, per-connection ordering, and backpressure behavior. The required signal is callback count falling from T to H and reduced target-path CPU/latency specifically when H is materially below T.
Change to test: Keep the shared subscriber snapshot and payload, but record each contiguous owner-thread range while the existing sorted snapshot is preflighted. Post one brief callback directly to each range's `pool()->at(thread_id)` instead of broadcasting one callback through the whole pool; each callback walks its known range rather than doing a `lower_bound`. Preserve one enqueue per matching subscription, the existing per-thread memory-budget check, connection-close checks, shared payload lifetime, and source PUBLISH ordering; retain a compatibility fallback until direct per-proactor queue ordering is proven equivalent.
Where it lives
perfloop/dragonfly · src/server/main_service.cc
Evidence
PUBLISH sparse owners · 33 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
cpu_ns/publish |
224000 |
68000 |
−69.6% (−156000) |
−180000 to −132000 |
gain > 0; gain > 0.05 × |baseline median|; arm medians separated |
PASSED |
publish_p50_ns |
177935 |
151131 |
−14.3% (−25498) |
−27426 to −12811 |
gain > 0; gain > 0.05 × |baseline median|; arm medians separated |
PASSED |
publish_p99_ns |
253936 |
232955 |
−36528 |
−90231 to +9371 |
loss ≤ 0.05 × |baseline median| |
PASSED |
PUBLISH sparse owner with one I/O thread · 48 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
cpu_ns/publish |
249000 |
30000 |
−86.3% (−215000) |
−244000 to −186000 |
gain > 0; gain > 0.05 × |baseline median|; arm medians separated |
PASSED |
publish_p50_ns |
190680 |
141284 |
−26% (−49526) |
−52428 to −44589 |
gain > 0; gain > 0.05 × |baseline median|; arm medians separated |
PASSED |
publish_p99_ns |
272083 |
217368 |
−54665 |
−80186 to +4476 |
loss ≤ 0.05 × |baseline median| |
PASSED |
PUBLISH dense owners · 543 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
cpu_ns/publish |
336667 |
336667 |
0 |
−13333 to +13333 |
loss ≤ 0.05 × |baseline median| |
PASSED |
publish_p50_ns |
177415 |
177458 |
+173 |
−1951 to +2848 |
loss ≤ 0.05 × |baseline median| |
PASSED |
publish_p99_ns |
255000 |
250690 |
−900 |
−10338 to +12370 |
loss ≤ 0.05 × |baseline median| |
PASSED |
PUBLISH large fanout · 59 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
cpu_ns/publish |
790000 |
670000 |
−100000 |
−230000 to +30000 |
loss ≤ 0.05 × |baseline median| |
PASSED |
publish_p50_ns |
215577 |
157931 |
−27.6% (−59407) |
−71866 to −53497 |
loss ≤ 0.05 × |baseline median| |
PASSED |
publish_p99_ns |
348830 |
287419 |
−19.9% (−69406) |
−135926 to −10512 |
loss ≤ 0.05 × |baseline median| |
PASSED |
PUBLISH single-thread pool · 519 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
cpu_ns/publish |
28500 |
28000 |
−500 |
−1500 to +1000 |
loss ≤ 0.05 × |baseline median| |
PASSED |
publish_p50_ns |
96126 |
96212 |
−11 |
−848.5 to +917 |
loss ≤ 0.05 × |baseline median| |
PASSED |
publish_p99_ns |
158714 |
158973 |
−1737 |
−9588 to +7778 |
loss ≤ 0.05 × |baseline median| |
PASSED |
PUBLISH brief callbacks · 14 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
callbacks/publish |
8 |
1 |
−87.5% (−7) |
−7 to −7 |
gain > 0; gain > 0.05 × |baseline median|; arm medians separated |
PASSED |
empty_callbacks/publish |
7 |
0 |
−100% (−7) |
−7 to −7 |
gain > 0; gain > 0.05 × |baseline median|; arm medians separated |
PASSED |
Checks: 5 of 5 passed. Verification: no defect found.
Timeline
2026-07-22· Case opened2026-11-06· PR opened