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

perf: optimize GetTemplateAppInsightsByTemplate by pre-filtering apps based on start/end times#20669

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

Open
cstyan wants to merge2 commits intomain
base:main
Choose a base branch
Loading
fromcallum/app-insights-optimize

Conversation

@cstyan
Copy link
Contributor

In this PR we're optimizing theGetTemplateAppInsightsByTemplate query by pre-filtering out apps which do not have an active session during the start/end time window.
Note: as of Nov 4 this is our most expensive query internally in terms of DB load though it only is called ~900 times in a 24h period it has a 1s average execution time and minimum of ~400ms.

This query currently looks at all entries inworkspace_app_stats (IIUC each row is an app session), then splits them into per-minute buckets before filtering out buckets that do not fall within our start/end time window. This leads to expensive query processing time to do sequential scans and joins for various data that will eventually just be thrown away due to being outside the time range.

Instead, we can pre-filter out themajority of the buckets that need to be thrown away by only retrieving entries fromworkspace_app_stats for sessions where at least some portion of the sessions active time range is within our start/end time range. We keep the existing filter of buckets to ensure we still filter out buckets that fall outside the time range.

The default time window for the query is 5 minutes, so start =time.Now() - 5m and end =time.Now(). UsingEXPLAIN and a specific 5 minute time window from earlier today (2025-11-03 18:00–18:05 UTC) the difference is pretty obvious:

  • Current: 444.8 ms, shared buffers 6,385, Parallel Seq Scan on workspace_app_stats, generate_series called ~67,380 times.
  • Optimized: 16.09 ms, shared buffers 1,782, only 4 generate_series calls.

I compared/verified the output of the queries, the filtered rows and distinct app names/template IDs, and thatterminal is still not considered an app.

start/end timesSigned-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

@cstyancstyan

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@cstyan

[8]ページ先頭

©2009-2025 Movatter.jp