Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ec9df3

Browse files
authored
fix: reduce impact of GetPrebuildMetrics on database (#19694)
see coder/internal#959 but the tl; dr is: - we call this DB query on an interval (every 15s) and it would be called on each coderd replica as well - the generated values update very infrequently (for our most used internal template I saw the builds created/claimed update twice in a 1h period) - we have no index on the initiator ID, so this query has to scan the entire workspace_builds table on every request In reality this should likely just be a Prometheus metric, and Prometheus can handle the counter reset behaviour at query time, but for now this should at least cut the load of the query to 25% of it's current impact. --------- Signed-off-by: Callum Styan <[email protected]>
1 parent 2030907 commit 0ec9df3

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

coderd/database/dump.sql

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Remove index on workspace_builds.initiator_id
2+
DROP INDEX IF EXISTS idx_workspace_builds_initiator_id;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Add index on workspace_builds.initiator_id to optimize prebuild queries
2+
-- This will dramatically improve performance for:
3+
-- - GetPrebuildMetrics (called every 15 seconds)
4+
-- - Any other queries using workspace_prebuild_builds view
5+
-- - Provisioner job queue prioritization
6+
CREATE INDEX idx_workspace_builds_initiator_id ON workspace_builds (initiator_id);

enterprise/coderd/prebuilds/metricscollector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ var (
105105
)
106106

107107
const (
108-
metricsUpdateInterval = time.Second * 15
108+
metricsUpdateInterval = time.Second * 60
109109
metricsUpdateTimeout = time.Second * 10
110110
)
111111

0 commit comments

Comments
 (0)