mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-26 07:30:54 +00:00
b6655a679d
Summary: While profiling compaction in our service I noticed a lot of CPU (~15% of compaction) being spent in MergingIterator and key comparison. Looking at the code I found MergingIterator was (understandably) using std::priority_queue for the multiway merge. Keys in our dataset include sequence numbers that increase with time. Adjacent keys in an L0 file are very likely to be adjacent in the full database. Consequently, compaction will often pick a chunk of rows from the same L0 file before switching to another one. It would be great to avoid the O(log K) operation per row while compacting. This diff replaces std::priority_queue with a custom binary heap implementation. It has a "replace top" operation that is cheap when the new top is the same as the old one (i.e. the priority of the top entry is decreased but it still stays on top). Test Plan: make check To test the effect on performance, I generated databases with data patterns that mimic what I describe in the summary (rows have a mostly increasing sequence number). I see a 10-15% CPU decrease for compaction (and a matching throughput improvement on tmpfs). The exact improvement depends on the number of L0 files and the amount of locality. Performance on randomly distributed keys seems on par with the old code. Reviewers: kailiu, sdong, igor Reviewed By: igor Subscribers: yoshinorim, dhruba, tnovak Differential Revision: https://reviews.facebook.net/D29133 |
||
---|---|---|
.. | ||
adaptive_table_factory.cc | ||
adaptive_table_factory.h | ||
block.cc | ||
block.h | ||
block_based_filter_block.cc | ||
block_based_filter_block.h | ||
block_based_filter_block_test.cc | ||
block_based_table_builder.cc | ||
block_based_table_builder.h | ||
block_based_table_factory.cc | ||
block_based_table_factory.h | ||
block_based_table_reader.cc | ||
block_based_table_reader.h | ||
block_builder.cc | ||
block_builder.h | ||
block_hash_index.cc | ||
block_hash_index.h | ||
block_hash_index_test.cc | ||
block_prefix_index.cc | ||
block_prefix_index.h | ||
block_test.cc | ||
bloom_block.cc | ||
bloom_block.h | ||
cuckoo_table_builder.cc | ||
cuckoo_table_builder.h | ||
cuckoo_table_builder_test.cc | ||
cuckoo_table_factory.cc | ||
cuckoo_table_factory.h | ||
cuckoo_table_reader.cc | ||
cuckoo_table_reader.h | ||
cuckoo_table_reader_test.cc | ||
filter_block.h | ||
flush_block_policy.cc | ||
format.cc | ||
format.h | ||
full_filter_block.cc | ||
full_filter_block.h | ||
full_filter_block_test.cc | ||
get_context.cc | ||
get_context.h | ||
iter_heap.h | ||
iterator.cc | ||
iterator_wrapper.h | ||
merger.cc | ||
merger.h | ||
merger_test.cc | ||
meta_blocks.cc | ||
meta_blocks.h | ||
mock_table.cc | ||
mock_table.h | ||
plain_table_builder.cc | ||
plain_table_builder.h | ||
plain_table_factory.cc | ||
plain_table_factory.h | ||
plain_table_index.cc | ||
plain_table_index.h | ||
plain_table_key_coding.cc | ||
plain_table_key_coding.h | ||
plain_table_reader.cc | ||
plain_table_reader.h | ||
table_builder.h | ||
table_properties.cc | ||
table_properties_internal.h | ||
table_reader.h | ||
table_reader_bench.cc | ||
table_test.cc | ||
two_level_iterator.cc | ||
two_level_iterator.h |