Repository navigation
Conversation
This was referenced Nov 2, 2026
kylecarbs
marked this pull request as ready for review
November 3, 2026 22:11
Collaborator
|
ProvisionerJobsToBeReaped is being updated by #31469 ; do the index changes still help the new query? |
Member
Author
|
@spikecurtis it looks like this would still help. I'll put this in draft and wait til #31469 is merged and bench again to be sure. |
kylecarbs
marked this pull request as draft
November 5, 2026 15:34
- GetWorkspacesEligibleForLifecycleAction fetches the latest build per workspace with a LATERAL lookup instead of a correlated MAX(). - AcquireNotificationMessages walks a partial index of queued messages in created_at order and stops at the batch size. - GetProvisionerJobsToBeReaped uses a partial index of incomplete jobs. - The organization provisioner jobs list filters and limits before the joins, and drops a GROUP BY that every one row join made redundant. - DeleteOldWorkspaceAgentLogs starts from agents that have logs and uses EXISTS (newer build) instead of grouping every build. The lifecycle executor change follows the sqlc type of build_template_version_id, which is now non-nullable. Generated by Coder Agents.
kylecarbs
force-pushed
the
perf/db-background-loops
branch
from
November 9, 2026 21:28
4a0a553 to
84f88e1
Compare
Collaborator
This branch has not been deployed
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.
Makes the queries run by background loops (autobuild, notifications, the job reaper, dbpurge) index-backed, so their cost stops growing with total history.
GetWorkspacesEligibleForLifecycleAction(runs every minute)MAX(build_number)AcquireNotificationMessages(batch of 20)GetProvisionerJobsToBeReaped(organization_id, created_at DESC)indexDeleteOldWorkspaceAgentLogs(1.7M log rows)EXISTS (newer build)instead of grouping every buildEvery rewrite returns the same rows:
MAX()filter already behaved as an inner join. Output matched at 5 timestamps, including dormancy, deletion, failed builds, and reminders.GROUP BYwas redundant.lifecycle_executor.gochanges one line because sqlc now typesbuild_template_version_idas non-nullable.NOTE: The
provisioner_jobs (organization_id, created_at DESC)index is about 79 MB at 2.1M jobs and blocks writes toprovisioner_jobswhile it builds. The two partial indexes are tiny. The partial index keys are immutable, so job heartbeats, which only touchupdated_at, stay eligible for HOT updates.Depends on #31624.
Decision log
DeleteExpiredAPIKeys(43 ms) orDeleteOldNotificationMessages(200 ms). Both would add write cost to hot tables.UpdateReplicastalls of up to 22 s seen under load were I/O and checkpoint contention, not the query.Generated by Coder Agents on behalf of @kylecarbs.