All simulators

B-tree vs LSM tree

Insert the same keys into both structures and compare the writes.

B-tree: update pages in place

empty

Each box is a disk page holding up to 3 keys. Pages on the last search path are outlined in blue.

Height
1
Pages written, last insert
0
Pages written, total
0

LSM tree: append, then merge later

Memtable (in memory, up to 4 keys)

empty

Level 0 (sorted files on disk)

no files
Log appends
0
Flushes
0
Compactions
0
Write amplification
0.0x

Insert random keys and compare. The B-tree pays on every write: it finds the right page and rewrites it where it lives, and sometimes splits. The LSM tree makes each write a cheap append, then pays later, in bulk, when it flushes and compacts. Write amplification is how many times each key has been written to disk so far.

What just happened

Nothing yet. Use the controls above.