Skip to content

Make idle controller agents and startup cheap on the database as deployments grow (CHOO-3667) - #1200

Closed
abeldantas wants to merge 3 commits into
mainfrom
controller-idle-pass
Closed

abeldantas wants to merge 3 commits into
mainfrom
controller-idle-pass

Conversation

@abeldantas

Copy link
Copy Markdown
Collaborator

Two database costs that grew with the size of a deployment, both found in our dev load tests.

In this PR we:

  • read the event heads of all of a controller's agents in one query per stream pass, and their rooms in one query per re-check of a controller held by another process, so an idle agent behind a controller no longer costs queries of its own
  • read room memberships 1,000 rooms at a time when a process starts, so a pod no longer spends close to two minutes under the boot lock when there are many rooms

Idle, 3,000 agents behind 150 controllers, 12 pods:

Before This PR
Database statements/s 2,360 361
CPU across the 12 pods 1.9 cores 0.5 to 0.7 cores

Startup, 17,000 rooms (almost all archived):

Before This PR
Room reconcile, per pod 109 s about 1 s
Rolling 12 pods, 4 at a time pods queued for the lock past the liveness limit and were restarted, over and over 2 min 15 s, no restarts

… agents' rooms at once (CHOO-3667)

With 3,000 agents behind 150 controllers and no messages, the database
ran 2,360 statements a second. Two loops did most of it:

- each controller stream's pass, including the one after every idle
  interval, opened a session per agent to read its events. A pass now
  reads all its agents' heads in one query and reads only the agents
  that have something new.
- every process re-reads each controller another process holds every 30
  seconds, and read each agent's rooms with a query of its own, so the
  count grew with processes times agents. It is now one query per
  controller (RoomStore.room_ids_by_agent).
…again (CHOO-3667)

Every process reconciles every room's clients at startup, under the
boot lock, and read two sessions per room to do it. With tens of
thousands of rooms that took about 100 s, close to the liveness
probe's limit, so pods starting together queued for the lock and were
restarted before they got it. The memberships are now read 1,000 rooms
per query, and only rooms missing a client are written to.

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@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