Try
↑ ↓ move↵ openesc close

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 1level 2level 3

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
Entries written to disk per user write
Entries written to disk per user write. Text version available below the chart.0x3x5x8x10x10010,10020,000writesx
Runs on disk, and stored entries per live key
Runs on disk, and stored entries per live key. Text version available below the chart.0.01.32.53.85.010010,10020,000writesruns, x

What to try

Each one sets up a starting point. Then make the change it describes.

  1. 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.

  2. 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.

  3. 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.

  4. 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