Skip to content

fix(cache): synchronous=NORMAL on the persistent HTTP cache (fsync tolerance)#266

Open
cubehouse wants to merge 1 commit into
mainfrom
fix/cache-synchronous-normal
Open

fix(cache): synchronous=NORMAL on the persistent HTTP cache (fsync tolerance)#266
cubehouse wants to merge 1 commit into
mainfrom
fix/cache-synchronous-normal

Conversation

@cubehouse

Copy link
Copy Markdown
Member

Why

Companion to collector PR #81. The on-disk HTTP cache (cache.sqlite) runs WAL but synchronous=FULL, so DatabaseSync fsyncs on every commit. During a park's entity/sync sweep the cache is written hard, and because the call is synchronous, on a slow/saturated disk each write stalls the caller's event loop on a full fsync. (Concretely: a collector agent on a consumer SATA SSD was fsyncing ~30ms under load, wedging the loop and starving live pushes.)

WAL + synchronous=NORMAL fsyncs only at checkpoints, not per commit. This is the biggest single burst-writer of the SQLite DBs involved.

Safety

The only durability change is losing the last uncheckpointed cache rows on a hard crash — a cache miss that re-fetches. No correctness impact.

Test

cachePragmas.test.ts re-imports the module against a real on-disk path (the shared vitest.setup.ts forces :memory:, where journal_mode is 'memory') and asserts journal_mode=wal + synchronous=1 (NORMAL). Existing cache.test.ts unaffected (81/81).

🤖 Generated with Claude Code

https://claude.ai/code/session_01KPNw8f4pE63C9hE2Xy4ykt

…lerance)

The on-disk cache runs WAL but synchronous=FULL, so DatabaseSync fsyncs on every
commit. During a park's entity/sync sweep the cache is written heavily, and on a
slow or saturated disk (a consumer SATA SSD under sustained O_DSYNC load) each
synchronous write stalls the caller's event loop on a full fsync. WAL +
synchronous=NORMAL fsyncs only at checkpoints; the only risk is losing the last
uncheckpointed cache rows on a hard crash, which are simply re-fetched.

Test (cachePragmas.test.ts) re-imports the module against a real on-disk path
(the shared setup forces :memory:) and asserts journal_mode=wal + synchronous=1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPNw8f4pE63C9hE2Xy4ykt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant