Repository navigation
Tune RocksDB compaction for desktop app — WAL bloat causes 10x oversized database - #994
Conversation
…rs (#992) SurrealDB's default RocksDB settings are tuned for server workloads with large write buffers and lazy compaction. On a desktop app, a 210-doc import produces ~147 MiB of WAL logs with zero SST files — 10x the expected post-compaction size. Set desktop-appropriate SURREAL_ROCKSDB_* env vars before SurrealDB opens the store: - WAL size limit: 64 MiB (forces earlier flushing) - Write buffer: 8 MiB (down from 32-128 MiB default) - Max write buffers: 3 (bounded memory) - Min buffers to merge: 1 (flush immediately) - Target file size: 16 MiB (smaller SSTs for desktop datasets) - L0 compaction trigger: 2 (compact sooner) - Background flush interval: 100ms (more frequent WAL→SST) - Log file retention: 5 (bounded info logs) Env vars are only set when not already present, so users can override any value. Uses std::sync::Once to apply exactly once per process. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add a comment to graceful_shutdown() explaining that SurrealDB 3.0 has no close() or flush() API for the embedded RocksDB backend, with a pointer to upstream issue surrealdb/surrealdb#2399. Committed WAL data is safe on normal shutdown via OS page cache flush on drop. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Pragmatic Code Review -- PR #994Reviewer: Claude Opus 4.6 (Principal Engineer) Overall AssessmentThis is a well-motivated, targeted fix for a real problem (147 MiB WAL for 210 docs). The approach of using SurrealDB's documented Verdict: Approve with one blocker to fix. FindingsCritical Issues[Critical/Blocker]
("SURREAL_ROCKSDB_BACKGROUND_FLUSH_INTERVAL", "100"),I verified the complete list of The background WAL flush interval in SurrealDB is controlled via the Action required: Remove Suggested Improvements[Improvement]
env::set_var(key, value);This compiles fine under edition 2021 (current), but Since this code runs early in No immediate action needed -- just noting for awareness. When upgrading editions, you will need an [Improvement] Setting this to 1 (down from default 2) means every single memtable is flushed individually rather than being merged with another memtable first. This maximizes WAL-to-SST conversion speed but produces more L0 files and more compaction work. Combined with the L0 compaction trigger of 2, this could cause write stalls during sustained bulk imports because the compaction pipeline may not keep up with the flush rate. For 210-doc imports this is likely fine, but for the stated goal of supporting 2K+ docs, consider keeping this at the default of 2 or testing with a larger import to verify no write stalls occur. NitpicksNit: Nit: Nit: Verified Environment VariablesCross-referenced against
Summary7 of 8 env vars are correctly named and valued. One ( |
malibio
left a comment
There was a problem hiding this comment.
One blocker: SURREAL_ROCKSDB_BACKGROUND_FLUSH_INTERVAL does not exist in SurrealDB 3.0.x (verified against surrealdb-core-3.0.4/src/kvs/rocksdb/cnf.rs). It is silently ignored at runtime. Remove it from the defaults array and its doc-comment bullet. If periodic WAL flushing is desired, use the sync query parameter on the connection URL or the SURREAL_DATASTORE_SYNC_DATA env var instead. See full review in PR comment.
…992) - Remove SURREAL_ROCKSDB_BACKGROUND_FLUSH_INTERVAL: does not exist in SurrealDB 3.0.x (flush interval is controlled via the connection URL sync parameter, not an env var). Was silently ignored at runtime. - Change MIN_WRITE_BUFFER_NUMBER_TO_MERGE from 1 back to 2: merging pairs before flushing reduces L0 file count and avoids potential write stalls during sustained bulk imports. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Review Feedback Addressed✅ Addressed (3)
⏭️ Skipped (2)
Commit: 4a502de |
…992) After initial tuning, 210-doc import still produced 105 MiB (vs 147 MiB before). Two culprits: - BlobDB (.blob files): ~31 MiB of overhead from separating large values into separate files. Disabled — inline SST storage compacts better at desktop scale (~200-10K docs). - Target file size multiplier: default of 2 meant L1=32 MiB, L2=64 MiB. Set to 1 for uniform 16 MiB files across all levels, producing tighter compaction for small datasets. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…zed database (#994) * fix: tune RocksDB compaction for desktop — cap WAL size, shrink buffers (#992) SurrealDB's default RocksDB settings are tuned for server workloads with large write buffers and lazy compaction. On a desktop app, a 210-doc import produces ~147 MiB of WAL logs with zero SST files — 10x the expected post-compaction size. Set desktop-appropriate SURREAL_ROCKSDB_* env vars before SurrealDB opens the store: - WAL size limit: 64 MiB (forces earlier flushing) - Write buffer: 8 MiB (down from 32-128 MiB default) - Max write buffers: 3 (bounded memory) - Min buffers to merge: 1 (flush immediately) - Target file size: 16 MiB (smaller SSTs for desktop datasets) - L0 compaction trigger: 2 (compact sooner) - Background flush interval: 100ms (more frequent WAL→SST) - Log file retention: 5 (bounded info logs) Env vars are only set when not already present, so users can override any value. Uses std::sync::Once to apply exactly once per process. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * docs: note SurrealDB lacks explicit close/flush for RocksDB (#992) Add a comment to graceful_shutdown() explaining that SurrealDB 3.0 has no close() or flush() API for the embedded RocksDB backend, with a pointer to upstream issue surrealdb/surrealdb#2399. Committed WAL data is safe on normal shutdown via OS page cache flush on drop. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: address review — remove phantom env var, safer merge threshold (#992) - Remove SURREAL_ROCKSDB_BACKGROUND_FLUSH_INTERVAL: does not exist in SurrealDB 3.0.x (flush interval is controlled via the connection URL sync parameter, not an env var). Was silently ignored at runtime. - Change MIN_WRITE_BUFFER_NUMBER_TO_MERGE from 1 back to 2: merging pairs before flushing reduces L0 file count and avoids potential write stalls during sustained bulk imports. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: disable blob files and flatten compaction levels for smaller DB (#992) After initial tuning, 210-doc import still produced 105 MiB (vs 147 MiB before). Two culprits: - BlobDB (.blob files): ~31 MiB of overhead from separating large values into separate files. Disabled — inline SST storage compacts better at desktop scale (~200-10K docs). - Target file size multiplier: default of 2 meant L1=32 MiB, L2=64 MiB. Set to 1 for uniform 16 MiB files across all levels, producing tighter compaction for small datasets. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Closes #992