Closed bdraco closed 1 week ago
Hey there @thomdietrich, mind taking a look at this pull request as it has been labeled with an integration (statistics
) you are listed as a code owner for? Thanks!
Tagged since a handful of users have confirmed this fixes the race between tasks that was cause the system to get slower and slower over time
@bdraco did you eventually figure out what caused this development?
@bdraco did you eventually figure out what caused this development?
There were multiple tasks racing against each other, creating more tasks. By making everything callbacks the flow is synchronous so it can't happen anymore.
Okay, thanks for resolving this!!
Proposed change
Refactor statistics to avoid creating tasks. Everything here was scheduling timer handles or events and can avoid creating tasks. Having the tasks in play made this integration much harder to debug.
The only task we need to create is the one time task to init from the database
We have been seeing increased cpu usage with statistics since at least 2024.2.x https://github.com/home-assistant/core/issues/110433 and it seems to have gotten worse in 2024.5.x https://github.com/home-assistant/core/issues/116650 https://github.com/home-assistant/core/issues/116731 as there is potential for tasks to race
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: