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(coderd/database): optimize GetRunningPrebuiltWorkspaces#18588

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
johnstcn merged 3 commits intomainfromcj/optimize/GetRunningPrebuiltWorkspaces
Jul 1, 2025

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedJun 25, 2025
edited
Loading

Fixescoder/internal#715

After this change, the only use of theworkspace_prebuilds view is theClaimPrebuiltWorkspace query. A subsequent PR will update the view.

Before: ~44mshttps://explain.dalibo.com/plan/76cbe21d1a4c9329#plan

~After:3.7mshttps://explain.dalibo.com/plan/f61beg93f9306fc0#plan

After: 7.3mshttps://explain.dalibo.com/plan/5abbdf926315677e#plan

@johnstcnjohnstcn marked this pull request as ready for reviewJune 26, 2025 20:50
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.

I was a bit thrown off by the indentation, but I tried my best 😆, left some suggestions and questions.

AS (
SELECT
latest_prebuilds.job_id,
BOOL_AND(workspace_agents.lifecycle_state='ready'::workspace_agent_lifecycle_state)::booleanAS ready
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
BOOL_AND(workspace_agents.lifecycle_state='ready'::workspace_agent_lifecycle_state)::booleanAS ready
workspace_agents.lifecycle_state='ready'::workspace_agent_lifecycle_stateAS ready

What's this, it actually works?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I just copied it from theworkspace_prebuilds view.

latest_prebuilds.created_at
FROM
latest_prebuilds
LEFT JOIN ready_agentsON
Copy link
Member

Choose a reason for hiding this comment

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

This join will duplicate rows when there are multiple agents since there is no group-by here or in theready_agents CTE, was this considered?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

That's a good point. I'll add some unit tests to compare the behaviour of the previous query.

Copy link
MemberAuthor

@johnstcnjohnstcnJun 30, 2025
edited
Loading

Choose a reason for hiding this comment

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

The 'correct' behaviour seems to be one row per provisioner job / workspace build.

@johnstcnjohnstcnforce-pushed thecj/optimize/GetRunningPrebuiltWorkspaces branch fromab80dc0 to9131d78CompareJune 30, 2025 11:23
}
}

funcTestGetRunningPrebuiltWorkspaces(t*testing.T) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

reivew: adapted fromTestWorkspacePrebuildsView.

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.

Would love to see an updated plan but looks good, nice work on the optimization!

johnstcn reacted with thumbs up emoji
latest_prebuilds.created_at
FROM latest_prebuilds
LEFT JOIN ready_agentsONready_agents.job_id=latest_prebuilds.job_id
ORDER BYlatest_prebuilds.workspace_idASC;
Copy link
Member

Choose a reason for hiding this comment

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

Nice, formatting ischef's kiss

@johnstcn
Copy link
MemberAuthor

The updated plan is slower than the previous one, but correct according to the added unit tests.

@mafredri
Copy link
Member

The updated plan is slower than the previous one, but correct according to the added unit tests.

Interesting, it could be due to moving WHERE conditions. It's always interesting how a hypothesis for optimization can crumble in the face of actual data layout. And where naive improvements may actually stomp on the query planners feet. 😅 Either way, the "slower" improvement is still great, no need to micro optimize IMO. 👍🏻

@johnstcnjohnstcn merged commit258a839 intomainJul 1, 2025
29 checks passed
@johnstcnjohnstcn deleted the cj/optimize/GetRunningPrebuiltWorkspaces branchJuly 1, 2025 08:42
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJul 1, 2025
@johnstcn
Copy link
MemberAuthor

Revert here:#18688

This caused the prebuilds reconciler to continuously attempt to delete failed prebuilds.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@mafredrimafredrimafredri approved these changes

@SasSwartSasSwartSasSwart approved these changes

Assignees

@johnstcnjohnstcn

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

bug: GetRunningPrebuiltWorkspaces creates lots of DB load
3 participants
@johnstcn@mafredri@SasSwart

[8]ページ先頭

©2009-2025 Movatter.jp