Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lintanghui opened this issue Sep 20, 2022 · 7 comments
Open

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

lintanghui opened this issue Sep 20, 2022 · 7 comments
Assignees

Comments

@lintanghui
Copy link

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。
image
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

@riversand963
Copy link
Contributor

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().

@lintanghui
Copy link
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.

@lintanghui
Copy link
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.
image
image
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.

@dkarpas
Copy link

dkarpas commented Oct 22, 2022

Shared this issue with the Speedb hive on Discourse and this is the answer we got:
"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."
You can join the conversation in the hive on Discourse and Discord for follow up questions, comments or other help

@dkarpas
Copy link

dkarpas commented Oct 22, 2022

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

@ajkr ajkr added enhancement waiting Waiting for a response from the issue creator. labels Oct 24, 2022
@ajkr ajkr removed the waiting Waiting for a response from the issue creator. label May 28, 2023
@lintanghui
Copy link
Author

@ajkr PTAL of this pr #10865

@lintanghui
Copy link
Author

any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants