-
Notifications
You must be signed in to change notification settings - Fork 943
fix: optimize queue position sql query #17974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
7078fc2
e16598d
5069c1d
eae97c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,17 +80,21 @@ pending_jobs AS ( | |
WHERE | ||
job_status = 'pending' | ||
), | ||
online_provisioner_daemons AS ( | ||
SELECT id, tags FROM provisioner_daemons pd | ||
WHERE pd.last_seen_at IS NOT NULL AND pd.last_seen_at >= (NOW() - (@stale_interval_ms::bigint || ' ms')::interval) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be a more descriptive param like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use |
||
), | ||
ranked_jobs AS ( | ||
-- Step 3: Rank only pending jobs based on provisioner availability | ||
SELECT | ||
pj.id, | ||
pj.created_at, | ||
ROW_NUMBER() OVER (PARTITION BY pd.id ORDER BY pj.created_at ASC) AS queue_position, | ||
COUNT(*) OVER (PARTITION BY pd.id) AS queue_size | ||
ROW_NUMBER() OVER (PARTITION BY opd.id ORDER BY pj.created_at ASC) AS queue_position, | ||
COUNT(*) OVER (PARTITION BY opd.id) AS queue_size | ||
FROM | ||
pending_jobs pj | ||
INNER JOIN provisioner_daemons pd | ||
ON provisioner_tagset_contains(pd.tags, pj.tags) -- Join only on the small pending set | ||
INNER JOIN online_provisioner_daemons opd | ||
ON provisioner_tagset_contains(opd.tags, pj.tags) -- Join only on the small pending set | ||
), | ||
final_jobs AS ( | ||
-- Step 4: Compute best queue position and max queue size per job | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be grouped with the rest of the
github.com/coder/coder/v2
imports. Also, thecdr.dev/slog
import should be grouped in with those as wellThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done