Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: optimize workspace_latest_builds view query#17789

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
dannykopping merged 3 commits intomainfromdean/optimize-latest-builds-query
May 13, 2025

Conversation

deansheather
Copy link
Member

@deansheatherdeansheather commentedMay 13, 2025
edited
Loading

Avoids two sequential scans of massive tables (workspace_builds,provisioner_jobs) and uses index scans instead. This new view largely replicates our already optimized queryGetWorkspaces to fetch the latest build.

The original query and the new query were compared against the dogfood database to ensure they return the exact same data in the exact same order (minus the newworkspaces.deleted = false filter to improve performance even more). The performance is massively improved even without theworkspaces.deleted = false filter, but it was added to improve it even more.

Note: these query times are probably inflated due to high database load on our dogfood environment that this intends to partially resolve.

Before: 2,139ms (explain)

After: 33ms (explain)

Co-authored-by: Cian Johnstoncian@coder.com

johnstcn
johnstcn previously approved these changesMay 13, 2025
@deansheatherdeansheatherforce-pushed thedean/optimize-latest-builds-query branch from0d2d188 to9811abeCompareMay 13, 2025 11:19
@dannykopping
Copy link
Contributor

Let's please wait for@evgeniy-scherbina to review this before merging.

Thank you for the effort put into this ❤️

deansheather and johnstcn reacted with thumbs up emoji

Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM, nice work!

…mization.up.sqlCo-authored-by: Mathias Fredriksson <mafredri@gmail.com>
Copy link
Contributor

@evgeniy-scherbinaevgeniy-scherbina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM

Good idea with LATERAL JOIN and filtering out deleted workspaces.

Optionally we can preserve formatting & comments when we recreateworkspace_prebuilds view.

Signed-off-by: Danny Kopping <dannykopping@gmail.com>
@dannykopping
Copy link
Contributor

I'm going to merge#17792 first so we can observe the impact on database load from that, and then merge this in to see it further drop.

Thanks all 🎉

dannykopping added a commit that referenced this pull requestMay 13, 2025
`Collect()` is called whenever the `/metrics` endpoint is hit toretrieve metrics.The queries used in prebuilds metrics collection are quite heavy, and wewant to avoid having them running concurrently / too often to keep dbload down.Here I'm moving towards a background retrieval of the state required toset the metrics, which gets invalidated every interval.Also introduces `coderd_prebuilt_workspaces_metrics_last_updated` whichoperators can use to determine when these metrics go stale.See#17789 as well.---------Signed-off-by: Danny Kopping <dannykopping@gmail.com>
@dannykoppingdannykopping merged commitef745c0 intomainMay 13, 2025
34 checks passed
@dannykoppingdannykopping deleted the dean/optimize-latest-builds-query branchMay 13, 2025 18:51
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsMay 13, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@mafredrimafredrimafredri left review comments

@johnstcnjohnstcnjohnstcn approved these changes

@evgeniy-scherbinaevgeniy-scherbinaevgeniy-scherbina approved these changes

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@deansheather@dannykopping@mafredri@johnstcn@evgeniy-scherbina

[8]ページ先頭

©2009-2025 Movatter.jp