Skip to content

Re-check controller connections only when they changed (CHOO-3667) - #1255

Closed
abeldantas wants to merge 2 commits into
recheck-bindingsfrom
recheck-connections
Closed

abeldantas wants to merge 2 commits into
recheck-bindingsfrom
recheck-connections

Conversation

@abeldantas

Copy link
Copy Markdown
Collaborator

Every 30 seconds every process read the connection row of every controller that ever opened one, revoked ones included, with its status and platform JSON, and for each controller another process held, the rooms of all its agents. In a load test with 10,000 agents behind 500 controllers on 12 processes, that was a one-second query on each process every 30 seconds, decoding that JSON was about a quarter of the processes' CPU while nothing else happened, and the room reads ran about ten times a second on each process at 3 ms each.

In this PR the re-check (ControllerSignals.recheck):

  • first compares a fingerprint of the connection columns it acts on, and the set of processes holding a lease, with what its last full read found, and reads again only when either changed (AgentControllerStore.connections_fingerprint)
  • reads only those columns when it reads (AgentControllerStore.connections), where it read whole rows

The rooms of a controller's agents stay current meanwhile through the membership signals and MessageRouter.recheck_agent_rooms, which re-reads them every 30 seconds. Startup and a reconnect still read everything.

Stack (merge order)

  1. Read only the clients and agents a change names, so creating agents stops pinning every process (CHOO-3667) #1229
  2. Re-check controller bindings in one narrow query, and only when placements changed (CHOO-3667) #1237
  3. This PR ← you are here

Every 30 seconds every process read the connection row of every
controller that ever opened one, revoked ones included, with their
status and platform JSON, and for each controller another process held,
the rooms of all its agents. At 10,000 agents behind 500 controllers
that was a one-second query and about a second of CPU decoding JSON per
process every 30 seconds, and about ten room queries a second.

The re-check now first compares a fingerprint of the connection
columns it acts on, and of the processes holding a lease, with the last
full read, and reads only the connection columns when it reads at all.
The rooms of a controller's agents are kept by the membership signals
and MessageRouter.recheck_agent_rooms meanwhile.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A moderate issue remains where newly bound agents on remote controllers may miss room membership refreshes and stay absent from message delivery until a later change or restart.

1 open issue
What changed in this PR

This pull request optimizes periodic controller reconciliation by checking connection and lease fingerprints before performing full reads, while retaining full startup and reconnect synchronization. It also adds targeted regression coverage and changelog documentation.

Changes:

  • Added narrow controller connection projections and fingerprint queries.
  • Skipped unchanged periodic connection and room reads.
  • Preserved rechecks for connection, lease, startup, and reconnect changes.
  • Added tests for unchanged, disconnected, and expired-lease scenarios.
  • Documented the optimization in the changelog.
  • Identified a moderate issue where newly bound agents on remotely held controllers may not receive an initial room refresh.
File Summary
core/​tests/​switch_core/​management/​test_controller_signals.py Adds coverage for skipped reads and rechecks triggered by connection or lease changes.
core/​switch_core/​management/​signals.py Uses connection and lease fingerprints to avoid unnecessary periodic reads; newly bound agents on remote controllers require room-refresh handling.
core/​switch_core/​db/​stores/​agent_controller_store.py Adds narrow connection-column queries and matching fingerprint calculation.
CHANGELOG.md Documents the reduced controller reconciliation workload.

Review effort: Lite

Comment on lines +325 to +326
seen |= self._connections_seen.get(tenant_id, set())
continue
@abeldantas

Copy link
Copy Markdown
Collaborator Author

Combined into #1307 with the other scaling PRs.

@abeldantas abeldantas closed this Nov 2, 2026
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