Compact L0 file to L0 when L0 is too small #10706

in our case, we will do checkpoint by period, in some case, with period checkpoint, the L0 file is small, when L0 file number reach 4, it will trigger compaction and pick up L1 file together. which made huge write amplification。
in this case, maybe we can compaction L0 file to L0 instead of L1 ,when total size of L0 files is smaller than target_file_size_base

Reply 1:
RocksDB can perform intra-L0 compaction in certain cases. The logic can be found in LevelCompactionBuilder::PickIntraL0Compaction(). First of all, the number of L0 files need to be greater than or equal to level0_file_num_compaction_trigger + 2. More checking in FindIntraL0Compaction().

Reply 2 (author):
|PickIntraL0Compaction will be perform only when PickFileToCompact fail, this only happen when all L1 file are compacting. in common case, when L0 file reach level0_file_num_compaction_trigger + 2, it will be compact with some L1 file, if L0 are too small , it will make great write amplification. maybe we can add some check , if total size of L0 is too small (each L0 file may be very small if we do checkpoint frequent ) , we should perfrom PickIntraL0Compaction.|

Reply 3 (author):

I had made a patch in my project, which enable L0 innner compaction when total size of L0 files are small than target_file_size_base , and it work well in online service.
when we do L0 inner compaction when total size of L0 is too small , we can reduce a lot write amplification compare to compact L0 with L1. maybe i can push my patch back to rocksdb.

There are several cases in Rocksdb that causes small L0 files: manual flushes, WAL size, atomic flushes etc… The outcome is as you wrote a very large write amp when compacting L0 to L1. We at Speedb understand that this behavior is undesirable and will fix this in the near future using the intraL0 compaction.

1 Like

merging L0 files through the intra L0 compaction when they are too small sounds like a great solution for the increased w-amp. we would like to see your patch and possibly merge it. thanks!

1 Like