Skip to content

Benchmark broker fan-out and buffer dispatch#24

Merged
ncode merged 1 commit intomasterfrom
codex/benchmark-broker-fanout
Apr 4, 2026
Merged

Benchmark broker fan-out and buffer dispatch#24
ncode merged 1 commit intomasterfrom
codex/benchmark-broker-fanout

Conversation

@ncode
Copy link
Copy Markdown
Owner

@ncode ncode commented Apr 4, 2026

What changed

  • added a targeted BenchmarkBrokerDispatch benchmark in internal/sshConn/message_test.go to measure broker fan-out
    cost without SSH/session noise
  • added an A/B benchmark-only helper to compare unbuffered per-host channels against a size-1 buffered variant
  • changed Broker to use a size-1 per-host channel buffer in internal/sshConn/message.go

Why it changed

The broker dispatch path was a plausible scaling risk because it fans each request out through per-host channels sequentially. Rather than changing it blindly, this PR first adds measurement coverage and then applies the smallest production change supported by the data.

Using repeated benchmark runs and benchstat, the size-1 buffer showed:

  • hosts_1: +3.72% slower
  • hosts_8: -11.54% faster
  • hosts_32: no statistically significant change (p=0.063)
  • hosts_128: -29.68% faster
  • no allocation change

That makes a one-slot buffer a reasonable low-complexity tradeoff for fan-out workloads.

Impact

  • improves broker dispatch throughput at moderate and large host counts
  • keeps behavior and API shape unchanged
  • leaves the benchmark in place so future fan-out changes can be validated instead of argued from intuition

Validation

  • go test ./internal/sshConn
  • go test ./...
  • go test -run '^$' -bench '^BenchmarkBrokerDispatch$' -benchmem ./internal/sshConn
  • go test -run '^$' -bench '^BenchmarkBrokerDispatch/unbuffered' -benchmem -count=10 ./internal/sshConn
  • go test -run '^$' -bench '^BenchmarkBrokerDispatch/buffered_1' -benchmem -count=10 ./internal/sshConn
  • benchstat /tmp/pretty-broker-unbuffered.norm.txt /tmp/pretty-broker-buffered1.norm.txt

Root cause

Before this change, Broker used unbuffered per-host channels, so fan-out remained synchronously coupled to each
worker's ability to receive the next request. A small buffer reduces that coupling without introducing a broader
redesign.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.00%. Comparing base (b4cb499) to head (71a0e11).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #24      +/-   ##
==========================================
- Coverage   88.26%   87.00%   -1.26%     
==========================================
  Files          18       18              
  Lines        1193     1193              
==========================================
- Hits         1053     1038      -15     
  Misses        108      108              
- Partials       32       47      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ncode ncode merged commit bd06dd9 into master Apr 4, 2026
2 checks passed
@ncode ncode deleted the codex/benchmark-broker-fanout branch April 4, 2026 15:18
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.

2 participants