Skip to content
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

Performance increase with lots of recordings #8525

Merged
merged 5 commits into from
Nov 7, 2023

Conversation

tpjanssen
Copy link
Contributor

I noticed long query times on my database with lots of recordings, therefore I changed some code and databases indices. I see a serious performance increase on all queries running on the recordings table.

Copy link

netlify bot commented Nov 7, 2023

Deploy Preview for frigate-docs canceled.

Name Link
🔨 Latest commit 4f7dcb4
🔍 Latest deploy log https://app.netlify.com/sites/frigate-docs/deploys/654a90e5a56c4a0009a68224

@@ -1584,20 +1584,10 @@ def recordings_summary(camera_name):
)
.where(Recordings.camera == camera_name)
.group_by(
fn.strftime(
Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

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

This is removing the timezone handling for recordings which is incorrect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why so? Grouping is done by the hour, which does not depend on timezone?

Copy link
Sponsor Collaborator

@NickM-27 NickM-27 Nov 7, 2023

Choose a reason for hiding this comment

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

it does depend on the timezone, the api accepts a timezone query arg which affects how hours are displayed. That timezone query arg is now just ignored in this implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It isn't ignored, it is still in the select part of the query. Only grouping is now done based on the Unix epoch, the output of the query is exactly the same.

Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

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

I see what you're saying, this will still cause problems for timezones that have 30 minute and 15 minute offsets from UTC

Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

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

You could perhaps catch the case that minute_modifier is not 0 and use the current grouping in that case or if it is 0 use your new grouping

@@ -0,0 +1,44 @@
"""Peewee migrations -- 011_update_indexes.py.
Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

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

Title should be updated here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy paste error. Will change it.

@@ -1584,20 +1584,10 @@ def recordings_summary(camera_name):
)
.where(Recordings.camera == camera_name)
.group_by(
fn.strftime(
Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

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

You could perhaps catch the case that minute_modifier is not 0 and use the current grouping in that case or if it is 0 use your new grouping

frigate/http.py Outdated Show resolved Hide resolved
@NickM-27
Copy link
Sponsor Collaborator

NickM-27 commented Nov 7, 2023

I think it would be interesting to know data points for the improvements you are seeing, for me looks like about 100ms average on the recordings page

before

Screen Shot 2023-11-07 at 12 40 32 PM

after

Screen Shot 2023-11-07 at 12 58 17 PM

@tpjanssen
Copy link
Contributor Author

I think it would be interesting to know data points for the improvements you are seeing, for me looks like about 100ms average on the recordings page

before

Screen Shot 2023-11-07 at 12 40 32 PM

after

Screen Shot 2023-11-07 at 12 58 17 PM

The difference on my side was even bigger. All depends on the number of recordings of course. Visiting the storage page on the frontend is also a lot quicker, refreshes are nearly instant at my side.

@tpjanssen tpjanssen closed this Nov 7, 2023
@tpjanssen tpjanssen reopened this Nov 7, 2023
@blakeblackshear blakeblackshear merged commit 3359123 into blakeblackshear:dev Nov 7, 2023
16 checks passed
@tpjanssen tpjanssen deleted the api-db-changes branch November 19, 2023 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants