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

Optimize logbook SQL query #12608

Merged
merged 1 commit into from
Feb 22, 2018
Merged

Conversation

amelchio
Copy link
Contributor

Description:

The logbook will load a lot of events that it ends up discarding. This change moves some of that filtering to SQL and thus avoids a lot of useless Python objects to be created.

The performance impact depends on the database content but my production setup has about a 50% improvement in logbook loading time (on top of #12566). Nevertheless, the logbook is still very slow :-/

The potential speedup depends on #12580.

Related issue (if applicable): fixes #12572

Checklist:

  • The code change is tested and works locally.

If the code does not interact with devices:

  • Local tests with tox run successfully.
  • Tests have been added to verify that the new code works.

@balloob balloob added this to the 0.64.0 milestone Feb 22, 2018
@balloob balloob merged commit 7dcb2ae into home-assistant:dev Feb 22, 2018
balloob pushed a commit that referenced this pull request Feb 25, 2018
@balloob balloob mentioned this pull request Feb 25, 2018
@JudgeDreddKLC
Copy link
Contributor

I've been very lazy about getting the correct environment set up to help with the DB, that's going to change. In the meantime, @amelchio, I'm assuming you already have the correct enviro set up to test changes, would you be bale to add indexes on states.entity_id and states_last_changed and see how that affects performance. If not, no worries, I'm going to start setting stuff up on my end tonight and hopefully will have a dev environment ready this week. I see a lot of room for improvement and I think we can piggy back on the vast improvements made by @OverloadUT a few months back. I'm new to github and formal development infrastructure, so perhaps there's already an easy way for the HASS db folk to communicate, if so, please share.

@OverloadUT
Copy link
Contributor

@JudgeDreddKLC: You should start a discussion in a separate GHI to discuss this, as this is a Merged PR.

My only feedback about that idea is that the logbook does not use the states table, so adding that index will not help logbook issues. (I am very confident that the current states indexes are configured ideally for all current state table queries, but please do challenge this if you find anything specific.)

@home-assistant home-assistant locked as resolved and limited conversation to collaborators Feb 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Logbook Speedup
5 participants