EN
返回档案库

案例库 · 工程与运营 · 技术决策 · 1996

这条还没译成中文,下面是英文原文。

The LSM-tree turned random database writes into sequential ones

LSM-trees buffer writes in memory, flush them as sorted immutable runs, then merge in the background, so a disk sees sequential I/O.

University of Massachusetts Boston / Informix

那一手

On a disk, a random update to a B-tree page is a seek plus a small write, and an application that keeps updating the same keys pays that cost many times. Throughput collapses because the disk is doing tiny scattered I/O.

The LSM-tree recasts the problem. Writes first go into a sorted in-memory structure and are flushed as ordered immutable files, so the disk sees a stream of large, sequential writes. Older runs are later merged and compacted in the background.

This trade of occasional expensive merges for cheap sequential writes is also why the structure is called log-structured: the write path is an append-only log, and the real sorting happens on the read and compact side.

为什么管用

  • Sequential disk I/O is orders of magnitude faster than random seeks.
  • Writes are batched into big immutable runs rather than small in-place updates.
  • Background merging hides the compaction cost from the write path.
值了多少Buffer writes, flush sequential runs, merge later神来之笔

可以搬走什么

If a workload does many tiny random writes, restructure so it commits sequentially and compensates later; the expensive work becomes a batch you can schedule, not a cost you pay per write.

后来呢

The LSM architecture became the basis of high-write storage systems including LevelDB, RocksDB, Cassandra, HBase and LevelDB-like engines in many data stores.

资料来源

发现哪里写错了?告诉我们。

同一路聪明