In this lesson · topic 4 of 7
Topic 4
What each policy costs you
5 min read
The three numbers
With the lab’s default settings, the two policies land in different places.
| Leveled | Tiered | |
|---|---|---|
| Write amplification | 7.7xmeasured | 3.3xmeasured |
| Files a read checks, on average | 2.6measured | 4.0measured |
| Files a miss checks | 3measured | 6measured |
| Space amplification | 1.32xmeasured | 2.34xmeasured |
Leveled merges eagerly. A new file is folded into the level below it, so the files stay few and sorted by level, and old versions disappear soon. The cost is that merging into a big level rewrites a lot of data already there.
Tiered waits. Files pile up until enough of them can be merged in one go, so each entry is rewritten about once per level. Writes get cheaper. Reads must check every file that might hold the key, and until a merge happens the stale copies stay on disk.
Overwrites make the space bill bigger
Space amplification depends on the workload. If every key is written once, there are no stale versions to hold. If a small set of keys is rewritten again and again, most of what is on disk is stale. With 2000 distinct keys, tiered compaction stores 5.7xmeasured as many entries as there are live keys. Leveled stores 1.35xmeasured, because it merges the old copies away. The price of that is higher write amplification: 5.2xmeasured against 2.3xmeasured.
Make tiered lazier
Raise the tiered ratio to 8 and write amplification drops to 2.4xmeasured. A miss now checks 9measured files. A lazier policy is cheaper for writes, and the files for reads grow.
Predict