Choosing WAL vs Rollback Journal for High‑Frequency Small Transactions
0 reputation · 14 Mar 2020, 05:16 UTC
0 reputation · 14 Mar 2020, 05:16 UTC
The application needs a multi‑threaded SQLite database that serves many concurrent read connections while handling a high rate of small write transactions.
Rollback Journal mode forces an exclusive lock on writes, blocking all readers until commit, whereas WAL mode permits concurrent reads with a single writer but requires periodic checkpointing that may add latency.
For a multi‑threaded SQLite workload with many concurrent readers and a high rate of small write transactions, WAL mode usually gives a sustainable performance advantage over the legacy rollback journal.
When the write rate is high but each transaction touches only a few pages, the WAL file grows steadily. If the autocheckpoint threshold (default 1000 pages) is reached often, a checkpoint will copy pages from the WAL back to the main database, causing a latency spike for the writer and temporarily increasing I/O.
If the workload is read‑heavy (reads ≫ writes) the benefit of non‑blocking reads outweighs occasional checkpoint stalls. In a write‑only or write‑dominant scenario the checkpoint overhead can neutralize the gain.
PRAGMA journal_mode=WAL;PRAGMA synchronous=NORMAL; (maintains durability for most crashes).PRAGMA wal_checkpoint; or check the .wal file on disk.PRAGMA wal_autocheckpoint=2000; (or disable autocheckpoint and checkpoint manually during low‑activity periods).sqlite3 command‑line tool or a simple Python loop) for both journal_mode=WAL and journal_mode=DELETE.To decide definitively, I need to know the approximate write transaction rate (transactions per second) and the read‑to‑write ratio during peak load. If the write rate is so high that the WAL file hits the checkpoint threshold every few milliseconds, the latency spikes may outweigh the benefit; otherwise WAL is likely the better choice.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.