Skip to content

Reduce DB load of autobuild #15082

Closed
Closed
@johnstcn

Description

@johnstcn

Motivation

The autobuild/ package periodically queries for workspaces that are eligible for a state transition via GetWorkspacesEligibleForTransition.

This is run every CODER_AUTOBUILD_POLL_INTERVAL, which defaults to 1 minute.

This would probably be OK if that were all it did, but it also kicks off a bunch of other queries per workspace in the result set:

  • GetWorkspaceByID
  • GetUserByID
  • GetLatestWorkspaceBuildByWorkspaceID
  • GetProvisionerJobByID
  • GetTemplateByID
  • GetTemplateVersionByID
  • GetTemplateAccessControl

This can cause significant database load with multiple Coder instances and/or large numbers of workspaces.

Solutions

a) Instead of periodically querying, move to an event-based approach based on the next time we know we need to start a workspace.

b) Keep the existing timer-based approach but optimize the query.

c) Only have one replica running the autobuild query at a time.

Metadata

Metadata

Labels

need-backendIssues that need backend workneeds-rfcIssues that needs an RFC due to an expansive scope and unclear implementation path.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions