coder / code-server

VS Code in the browser
https://coder.com
MIT License
67.27k stars 5.51k forks source link

[Bug]: A slow SQl query is causing high database load #6674

Closed liji-canva closed 6 months ago

liji-canva commented 6 months ago

Is there an existing issue for this?

OS/Web Information

N/A

Steps to Reproduce

We found this issue by checking AWS RDS metrics.

Expected

Reasonable query time and database load.

Actual

Data shows this query is causing high db load and average query time is 42s. -- name: GetDeploymentDAUs :many SELECT (created_at at TIME ZONE cast($1::integer as text))::date as date, user_id FROM workspace_agent_stats WHERE connection_count > ? GROUP BY date, user_id ORDER BY date ASC

Logs

No response

Screenshot/Video

Screenshot 2024-02-14 at 2 26 07 pm

Does this issue happen in VS Code or GitHub Codespaces?

Are you accessing code-server over a secure context?

Notes

We keep getting AWS RDS high load alert. By checking the metrics, we found this query is very slow and takes up most of the db resource. We may have a query or table to optimise here.

-- name: GetDeploymentDAUs :many SELECT (created_at at TIME ZONE cast($1::integer as text))::date as date, user_id FROM workspace_agent_stats WHERE connection_count > ? GROUP BY date, user_id ORDER BY date ASC

liji-canva commented 6 months ago

Sorry, it seems I created the issue to the wrong repo. I will close it and re-create.