fix(memory): cap SQLite pools and shrink the event cache periodically #159

Merged
jlxq0 merged 3 commits from fix/memory-growth into main 2026-11-09 02:46:27 +00:00
Owner

v0.10.17 already frees replaced clients (#158), but the pod (limit 1Gi) still climbed from about 10Mi to 1Gi in steps within 1–2 days, and was OOMKilled 5 times in 6 days. One Matrix client is active, syncing about 500–900 responses an hour.

Two remaining contributors, both in how matrix-sdk 0.19 is configured:

  1. SQLite pools. SqliteStoreConfig::new gives each store 4 x physical CPUs connections with a 2 MB page cache, and a client has four stores. Connections keep their cache once opened, which fits the step-shaped growth. This switches to the SDK's with_low_memory_config preset (one connection per physical CPU, 500 KB cache), with the same passphrase. A test proves the store still refuses a wrong passphrase.
  2. Event cache. Each room's in-memory linked chunk is only unloaded when the room's last subscriber drops (Subscriber::drop → auto_shrink_if_no_subscribers), and nothing here subscribes to rooms (#158 notes the same). A 15-minute task per client now takes and drops a subscriber for each joined room. It holds only a Weak<Client> and is aborted in CachedClient::drop next to the sync task, so #158's freed-client test still holds.

Plus fix(deps): vodozemac 0.11.2 and ctutils 0.4.8 for RUSTSEC-2026-0445/0451/0385, which were published after v0.10.17 and fail cargo audit on main.

On toolchain 1.98.0 (CI's): fmt, clippy -D warnings and cargo test --all-features all pass (389 + 6 tests), and cargo audit is clean apart from the 2 allowed warnings.

Note: v0.10.18 was tagged by mistake on eccda5d, the same commit as v0.10.17. This change ships as v0.10.19.

🤖 Generated with Claude Code

https://claude.ai/code/session_01E2xQRZnoBbY9SEC5nF6J4U

`v0.10.17` already frees replaced clients (#158), but the pod (limit 1Gi) still climbed from about 10Mi to 1Gi in steps within 1–2 days, and was OOMKilled 5 times in 6 days. One Matrix client is active, syncing about 500–900 responses an hour. Two remaining contributors, both in how matrix-sdk 0.19 is configured: 1. **SQLite pools.** `SqliteStoreConfig::new` gives each store `4 x physical CPUs` connections with a 2 MB page cache, and a client has four stores. Connections keep their cache once opened, which fits the step-shaped growth. This switches to the SDK's `with_low_memory_config` preset (one connection per physical CPU, 500 KB cache), with the same passphrase. A test proves the store still refuses a wrong passphrase. 2. **Event cache.** Each room's in-memory linked chunk is only unloaded when the room's last subscriber drops (`Subscriber::drop` → `auto_shrink_if_no_subscribers`), and nothing here subscribes to rooms (#158 notes the same). A 15-minute task per client now takes and drops a subscriber for each joined room. It holds only a `Weak<Client>` and is aborted in `CachedClient::drop` next to the sync task, so #158's freed-client test still holds. Plus `fix(deps)`: vodozemac 0.11.2 and ctutils 0.4.8 for RUSTSEC-2026-0445/0451/0385, which were published after v0.10.17 and fail `cargo audit` on main. On toolchain 1.98.0 (CI's): fmt, clippy `-D warnings` and `cargo test --all-features` all pass (389 + 6 tests), and `cargo audit` is clean apart from the 2 allowed warnings. Note: `v0.10.18` was tagged by mistake on `eccda5d`, the same commit as `v0.10.17`. This change ships as `v0.10.19`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01E2xQRZnoBbY9SEC5nF6J4U
fix(memory): cap SQLite pools and shrink the event cache periodically
Some checks failed
CI / cargo (pull_request) Failing after 3m12s
CI / docker (pull_request) Has been skipped
2819ca4dc5
The pod climbed from about 10 MiB to its 1 GiB limit in steps and was
OOM-killed five times in six days. Two contributors, both matrix-sdk
configuration:

- SqliteStoreConfig defaults to 4 x physical CPUs connections per store
  with a 2 MB page cache each, across four stores, each connection keeping
  its cache once opened. Use the SDK's low-memory preset (one connection
  per physical CPU, 500 KB cache), same passphrase.
- The event cache keeps every synced event of a room in memory until its
  last subscriber drops, and nothing here subscribes to rooms. Every 15
  minutes take and drop a subscriber per joined room, the SDK's own
  trigger to unload all but the last chunk. Events stay in SQLite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2xQRZnoBbY9SEC5nF6J4U
fix(deps): clear 17 RUSTSEC advisories with lockfile updates
All checks were successful
CI / cargo (pull_request) Successful in 5m3s
CI / docker (pull_request) Has been skipped
4156f4ea44
rustls 0.23.46, rustls-webpki 0.103.16, vodozemac 0.11.2, quinn-proto
0.11.19, webpki-roots and webpki-root-certs 1.0.11, pulldown-cmark 0.13.6,
ctutils 0.4.8. cargo audit now reports only the three allowed warnings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2xQRZnoBbY9SEC5nF6J4U
jlxq0 force-pushed fix/memory-growth from 4156f4ea44
All checks were successful
CI / cargo (pull_request) Successful in 5m3s
CI / docker (pull_request) Has been skipped
to 0c4fc04f95
Some checks failed
CI / cargo (pull_request) Has been cancelled
CI / docker (pull_request) Has been cancelled
2026-11-09 02:38:27 +00:00
Compare
release: v0.10.19
All checks were successful
CI / cargo (pull_request) Successful in 4m41s
CI / docker (pull_request) Has been skipped
cdc1a07b11
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2xQRZnoBbY9SEC5nF6J4U
jlxq0 merged commit 8d38e9b4ca into main 2026-11-09 02:46:27 +00:00
jlxq0 deleted branch fix/memory-growth 2026-11-09 02:46:28 +00:00
Sign in to join this conversation.
No description provided.