Closed
Description
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.