Add a commit interval setting to recorder (#32596)
* Add a commit interval setting to recorder * Make the default every 1s instead of immediate * See attached py-spy flamegraphs for why 1s * This avoids disk thrashing during event storms * Make Home Assistant significantly more responsive on busy systems * remove debug * Add commit forces for tests that expect commits to be immediate * Add commit forces for tests that expect commits to be immediate * make sure _trigger_db_commit is in the right place (all effective "wait_recording_done" calls) * De-duplicate wait_recording_done code
This commit is contained in:
1 parent
8a46d93be4
commit
3a680bf7b7
5 files changed
+124
-63
No files matched your search
@@ -13,6 +13,8 @@ from homeassistant.const import MATCH_ALL
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import wait_recording_done
|
||||
|
||||
from tests.common import get_test_home_assistant, init_recorder_component
|
||||
|
||||
|
||||
@@ -37,8 +39,7 @@ class TestRecorder(unittest.TestCase):
|
||||
|
||||
self.hass.states.set(entity_id, state, attributes)
|
||||
|
||||
self.hass.block_till_done()
|
||||
self.hass.data[DATA_INSTANCE].block_till_done()
|
||||
wait_recording_done(self.hass)
|
||||
|
||||
with session_scope(hass=self.hass) as session:
|
||||
db_states = list(session.query(States))
|
||||
@@ -65,7 +66,7 @@ class TestRecorder(unittest.TestCase):
|
||||
|
||||
self.hass.bus.fire(event_type, event_data)
|
||||
|
||||
self.hass.block_till_done()
|
||||
wait_recording_done(self.hass)
|
||||
|
||||
assert len(events) == 1
|
||||
event = events[0]
|
||||
@@ -109,8 +110,7 @@ def _add_entities(hass, entity_ids):
|
||||
attributes = {"test_attr": 5, "test_attr_10": "nice"}
|
||||
for idx, entity_id in enumerate(entity_ids):
|
||||
hass.states.set(entity_id, "state{}".format(idx), attributes)
|
||||
hass.block_till_done()
|
||||
hass.data[DATA_INSTANCE].block_till_done()
|
||||
wait_recording_done(hass)
|
||||
|
||||
with session_scope(hass=hass) as session:
|
||||
return [st.to_native() for st in session.query(States)]
|
||||
@@ -121,8 +121,7 @@ def _add_events(hass, events):
|
||||
session.query(Events).delete(synchronize_session=False)
|
||||
for event_type in events:
|
||||
hass.bus.fire(event_type)
|
||||
hass.block_till_done()
|
||||
hass.data[DATA_INSTANCE].block_till_done()
|
||||
wait_recording_done(hass)
|
||||
|
||||
with session_scope(hass=hass) as session:
|
||||
return [ev.to_native() for ev in session.query(Events)]
|
||||
@@ -201,6 +200,7 @@ def test_recorder_setup_failure():
|
||||
hass,
|
||||
keep_days=7,
|
||||
purge_interval=2,
|
||||
commit_interval=1,
|
||||
uri="sqlite://",
|
||||
db_max_retries=10,
|
||||
db_retry_wait=3,
|
||||
|
||||
Reference in new issue
Block a user