LSM compaction lab
Write to an in-memory table that flushes to sorted files, and compact those files either by levels or by tiers. Read write, read and space amplification as the files merge.
writes 20,000 of 40,000Leveled ratio 410,000 distinct keys
Sorted runs on disk
- Level 1: 1 run of 779 entries.
- Level 2: 1 run of 2,622 entries.
- Level 3: 1 run of 7,997 entries.
Each bar is one sorted file, drawn in proportion to its entries. Newer data sits in the upper levels.
- write amplification
- 7.1x
- read amplification
- 2.5 runs
- worst miss
- 3 runs
- space amplification
- 1.31x
- compactions
- 122
- flushes
- 99
| Series | Latest | Lowest | Highest |
|---|---|---|---|
| write amplification | 7x | 0x | 8x |
| Series | Latest | Lowest | Highest |
|---|---|---|---|
| runs | 3.0 | 0.0 | 3.0 |
| space amplification | 1.3 | 1.0 | 1.3 |
What to try
Each one sets up a starting point. Then make the change it describes.
Leveled against tiered
Read the three amplification numbers with leveled compaction, then switch to tiered.
Look for. Tiered rewrites each entry far fewer times, so write amplification drops. It leaves more runs on disk, so reads check more files and old versions pile up. You are choosing which amplification to pay.
A bigger ratio
Switch to tiered and raise the size ratio from 4 to 8.
Look for. More runs wait for each merge, so writes get cheaper still and reads have more files to check.
Lots of overwrites
Set distinct keys to 2000 with tiered compaction and read space amplification.
Look for. The same keys are written again and again. Old versions stay on disk until a merge drops them, so tiered storage holds several times more entries than there are live keys.
Overwrites with levels
Keep distinct keys at 2000 and switch to leveled.
Look for. Leveled merges drop old versions soon after they are replaced, so space amplification stays low. Write amplification is the cost.
New to the idea? Read the lesson first. Every number here comes from a seeded simulator, so the same seed gives the same run.
Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms