Damus
Alex Gleason profile picture
Alex Gleason
@Alex Gleason
At 750 GB/day the four drives last about 17 years against their rating, and it was 2.4 years on ZFS.
…The relay isn't holding 6 TB. **The 6 TB was writes, not storage.** - The new database uses **540 GB on disk**: 462 GB of event data (`bodies`) and 71 GB of indexes. - The old ZFS copy uses 2.0 TB, including a test snapshot. It goes away once the backfill is done and you approve deleting it. The problem you're pointing at is real, though: **the relay writes far more to disk than it stores.** It adds a few GB of events a day and writes about 750 GB a day to do it. **Why that happens:** - Each event adds about 16 index entries: its id, author, kind, time, and every indexed tag. - Most of those keys are effectively random, so each entry lands on a different 4 KB page somewhere in a 71 GB index. - LMDB writes a full new copy of every page it changes. So each event costs about 16 page writes, roughly 64 KB, to store about 40 bytes of index data. **Batching more won't fix it.** The backfill already committed about 6,000 events at a time, and it still wrote about 66 KB per event. That's within about 2.5× of what live traffic writes at 5 events per commit. Even a batch of thousands of events rarely puts two random keys on the same page. So a longer commit window, or the in-memory store we discussed, tops out at about 2.5× fewer writes, roughly 300 GB/day. **What actually fixes it:** an index format built for random inserts, such as an LSM tree (RocksDB, or fjall in Rust). New entries are buffered in memory and written out sequentially, and are merged in large sorted runs later. Each event would then write a few KB instead of about 64 KB. That should mean around 10× less, but it's an estimate until I measure it. It also fits what you described: data in memory is readable straight away, and a power cut loses the last few seconds but always reopens cleanly. The cost: it replaces the storage layer that every query, the writer, repack, compact and the backfill tools are built on, so it's a big project. The way to find out whether it's worth it is a prototype: replay a day of real events into it and compare bytes written against LMDB. **Your options:** 1. **Prototype the LSM index** and measure it before committing to anything. Production stays as it is meanwhile. 2. **Accept the current rate.** At 750 GB/day the four drives last about 17 years against their rating, and it was 2.4 years on ZFS. 3. **Index fewer tags.** Each indexed tag value costs a page write, so dropping tags nobody queries cuts writes in proportion. I'd need to know which tags Ditto actually queries. I'd do option 1, with option 3 alongside if there are tags Ditto never queries. Which do you want?…