Repository navigation
Have a controller's stream wait on one bell, not one per agent (CHOO-3667) - #1253
Closed
abeldantas wants to merge 1 commit into
Closed
abeldantas wants to merge 1 commit into
abeldantas wants to merge 1 commit into
Conversation
…3667) Each wait of a controller's stream started a waiter for the doorbell of every agent on it, two more for the connection and the nudges, and cancelled them all when one fired: with 20 agents that was 22 tasks per wait, and a CPU profile of a load test put the waiting among the larger costs of a delivery. The stream now has one bell that every attached agent's doorbell rings (EventBuffer.listen), so a wait watches three events. Reading a doorbell no longer builds an Event it then discards.
abeldantas
requested review from
agent-runner353,
amaudruz,
christian-mcdermott,
petr-sandbox and
simonflk-sb
as code owners
November 1, 2026 02:35
abeldantas
requested review from
lbangalosbt,
massimo-sandboxaq,
niall-sandboxaq and
raullopez-sandbox
as code owners
November 1, 2026 02:35
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The review records no active issues, with the shared-bell optimization accompanied by regression coverage and documentation despite the noted stale-head caveat.
No open issues 🎉
What changed in this PR
This pull request reduces controller-stream waiting overhead by replacing per-agent waiters with one shared event bell per stream.
Changes:
- Added shared bell listener registration and fan-out to
EventBuffer. - Updated controller streams to wait on one shared bell plus connection and nudge events.
- Added regression coverage for constant wait-task counts.
- Documented the optimization in the changelog.
- A moderate issue remains around stale cached heads when an agent is detached and rebound.
| File | Summary |
|---|---|
core/tests/switch_core/management/test_stream.py |
Verifies that wait-task counts remain constant with multiple attached agents. |
core/switch_core/bridges/agent/protocol/event_buffer.py |
Adds shared bell fan-out and listener lifecycle handling; cached heads may remain stale across agent detach/rebind cycles. |
core/switch_core/bridges/agent/protocol/controller_stream.py |
Uses one shared bell for attached agents and waits on three events. |
CHANGELOG.md |
Documents the controller-stream waiting optimization. |
Review effort: Lite
This was referenced Nov 1, 2026
Collaborator
Author
|
Combined into #1307 with the other scaling PRs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each wait of a controller's stream started a waiter for the doorbell of every agent on it, two more for the connection and the nudges, and cancelled them all when one fired. With 20 agents on a controller that was 22 tasks for every wait, and a CPU profile of a load test put the waiting among the larger costs of a delivery.
In this PR the stream has one bell, which every attached agent's doorbell rings (
EventBuffer.listen), so a wait watches three events. Reading a doorbell also no longer builds anasyncio.Eventit then throws away.Stack (merge order)