Skip to content

Level 1 Sub Compaction

ZengJingtao edited this page Jan 30, 2023 · 2 revisions

In RocksDB, there is a configuration item max_subcompactions. In Level Compaction Style, max_subcompactions takes effect in two situations:

  1. L0 + L1 -> L1 compaction (More precisely, output is not necessarily L1, but input must have L0)
  2. Manual Compaction

When num_subcompact > 1, different subcompactions will be executed concurrently in multiple threads. For an SST file that covers multiple subcompactions, the corresponding parts will be read in these multiple sub-compaction threads. If it occurs on the DB node There is no problem with compacting hot data, because reading files must go through the PageCache of the operating system. Even if multiple threads access, there is a high probability that the PageCache will be hit.

However, if the input sst of compaction is cold data, the utilization rate of PageCache will be reduced!

This is because: Compaction accesses SST files sequentially. For SST files on the subcompaction boundary, the file accessed first by the subsequent subcompaction is the last accessed by the previous subcompaction. At this time, the data loaded into PageCache may have been deleted. evict is out! Especially for Topling SST, the proportion of preloaded file content is large (unlike BlockBasedTable, which only needs to load BlockIndex).

Compaction input sst is cold data in two cases:

  1. Compaction of cold data on the DB node
  2. Distributed Compaction. For Compaction nodes, all SSTs are cold data.

So, in RocksDB, the decision to enable subcompact rules is very reasonable, because Manual Compaction users can set CompactRangeOptions.max_subcompactions with a non-zero value to override DBOptions.max_subcompactions.

max_level1_subcompactions

In ToplingDB Distributed Compaction, even if it is manual compaction, we don't want to enable sub-compaction, so we can only set CompactRangeOptions.max_subcompactions = 1 in the user code, and we hope that the user code should not be modified as much as possible, so we added a new one Options: DBOptions.max_level1_subcompactions.

It is equal to DBOptions.max_subcompactions by default, but it only affects Compaction with start_level = 0 in any case