Try
↑ ↓ move↵ openesc close
In this lesson · topic 4 of 7
  1. 1. Random writes are the expensive kind
  2. 2. Memtable, SSTables and compaction
  3. 3. Run leveled and tiered on the same writes
  4. 4. What each policy costs you
  5. 5. Why reads cost more here
  6. 6. When compaction cannot keep up
  7. 7. Memtables, runs and amplification

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

A store keeps a small set of hot keys and rewrites them constantly, and disk space is tight. Which policy is the safer choice?

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms