In this lesson · topic 6 of 7
Topic 6
When compaction cannot keep up
4 min read
A queue with a deadline
Every flush adds a file. Every compaction removes some and writes others. The store is stable only if the merge work keeps up with the flushes.
The work per flush is the write amplification. In the lab, with leveled compaction at a ratio of 4, each user write costs 7.7xmeasured entry writes in the background. If the disk can write entries faster than the ingest rate times that factor, the store keeps up. If it cannot, files gather without limit.
A real store cannot let that go on. Read cost grows with every file and the disk fills with stale data. So it slows down or stops the writer for a while, to let compaction catch up. The application sees this as latency spikes in an otherwise fast store.
What to do about it
There are four levers.
- Give compaction more disk bandwidth or more threads.
- Pick a policy that rewrites less, accepting more reads and space. Tiered writes 3.3xmeasured here, against 7.7xmeasured.
- Smooth the ingest upstream with a queue, so bursts do not outrun the merge.
- Leave headroom. A store run at the edge of what compaction can do has no room for a burst.
The cost of the second lever shows up in the reads, so the answer depends on what the store is for. A log ingest store with rare reads can accept tiered compaction. A user-facing lookup store usually cannot.
Predict