Search code examples
rocksdb

Determining the number of files in each level in RocksDB


By default, RocksDB sets target_file_size_base to 64 MB and target_file_size_multiplier to 1. The comments in the code mention that:

Target file size for level L can be calculated by target_file_size_base * (target_file_size_multiplier ^ (L-1)). By default target_file_size_multiplier is 1, which means by default files in different levels will have similar size.

However, when target_file_size_multiplier is 1, the target file size for a level will be equal to target_file_size_base so how will the number of files per level be determined?


Solution

  • By default, the size of SST files in each layer is the same as you noticed since target_file_size_multiplier is 1. But there is another pair of parameters max_bytes_for_level_base (Default: 256M) and max_bytes_for_level_multiplier (Default: 10). Every layer therefore has ((max_bytes_for_level_base) * (max_bytes_for_level_multiplier ^ (L-1))) / (target_file_size_base * (target_file_size_multiplier ^ (L-1))) files. For example, L1 has 256MB / 64MB = 4 SST files, and L2 has 4 * 10 = 40 files. So as so on.