Skip to content

Commit edc10fc

Browse files
fix: Reduce watch service CPU usage by increasing reload interval
Changed watch_project_reload_interval default from 30s to 300s (5 min) to reduce CPU usage caused by frequent watcher restarts. The watch service was restarting every 30 seconds to reload the project list, causing the watchfiles library to rebuild its internal state. This was especially noticeable on systems with many files. Impact: - Reduces watcher restart frequency by 10x - Should reduce idle CPU usage from 20-30% to 2-3% or less - New projects picked up within 5 min instead of 30 sec - Users can configure lower values if needed Fixes #448 Co-authored-by: Paul Hernandez <phernandez@users.noreply.github.com> Signed-off-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
1 parent 78673d8 commit edc10fc

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

src/basic_memory/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ class BasicMemoryConfig(BaseSettings):
122122
)
123123

124124
watch_project_reload_interval: int = Field(
125-
default=30, description="Seconds between reloading project list in watch service", gt=0
125+
default=300,
126+
description="Seconds between reloading project list in watch service. Higher values reduce CPU usage by minimizing watcher restarts. Default 300s (5 min) balances efficiency with responsiveness to new projects.",
127+
gt=0,
126128
)
127129

128130
# update permalinks on move

tests/sync/test_watch_service_reload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def stop_after_one_call(*args):
8585
with patch.object(watch_service, "write_status", return_value=None):
8686
await watch_service.run()
8787

88-
# Should have slept for 30 seconds when no projects found
89-
mock_sleep.assert_called_with(30)
88+
# Should have slept for the configured reload interval when no projects found
89+
mock_sleep.assert_called_with(config.watch_project_reload_interval)
9090

9191

9292
@pytest.mark.asyncio

0 commit comments

Comments
 (0)