rocksdb/table
Peter Dillinger a92bd0a183 Optimize memory and CPU for building new Bloom filter (#6175)
Summary:
The filter bits builder collects all the hashes to add in memory before adding them (because the number of keys is not known until we've walked over all the keys). Existing code uses a std::vector for this, which can mean up to 2x than necessary space allocated (and not freed) and up to ~2x write amplification in memory. Using std::deque uses close to minimal space (for large filters, the only time it matters), no write amplification, frees memory while building, and no need for large contiguous memory area. The only cost is more calls to allocator, which does not appear to matter, at least in benchmark test.

For now, this change only applies to the new (format_version=5) Bloom filter implementation, to ease before-and-after comparison downstream.

Temporary memory use during build is about the only way the new Bloom filter could regress vs. the old (because of upgrade to 64-bit hash) and that should only matter for full filters. This change should largely mitigate that potential regression.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6175

Test Plan:
Using filter_bench with -new_builder option and 6M keys per filter is like large full filter (improvement). 10k keys and no -new_builder is like partitioned filters (about the same). (Corresponding configurations run simultaneously on devserver.)

std::vector impl (before)

    $ /usr/bin/time -v ./filter_bench -impl=2 -quick -new_builder -working_mem_size_mb=1000 -
    average_keys_per_filter=6000000
    Build avg ns/key: 52.2027
    Maximum resident set size (kbytes): 1105016
    $ /usr/bin/time -v ./filter_bench -impl=2 -quick -working_mem_size_mb=1000 -
    average_keys_per_filter=10000
    Build avg ns/key: 30.5694
    Maximum resident set size (kbytes): 1208152

std::deque impl (after)

    $ /usr/bin/time -v ./filter_bench -impl=2 -quick -new_builder -working_mem_size_mb=1000 -
    average_keys_per_filter=6000000
    Build avg ns/key: 39.0697
    Maximum resident set size (kbytes): 1087196
    $ /usr/bin/time -v ./filter_bench -impl=2 -quick -working_mem_size_mb=1000 -
    average_keys_per_filter=10000
    Build avg ns/key: 30.9348
    Maximum resident set size (kbytes): 1207980

Differential Revision: D19053431

Pulled By: pdillinger

fbshipit-source-id: 2888e748723a19d9ea40403934f13cbb8483430c
2019-12-15 21:31:08 -08:00
..
adaptive Organizing rocksdb/table directory by format 2019-05-30 14:51:11 -07:00
block_based Optimize memory and CPU for building new Bloom filter (#6175) 2019-12-15 21:31:08 -08:00
cuckoo Introduce a new storage specific Env API (#5761) 2019-12-13 14:48:41 -08:00
plain Remove a few unnecessary includes 2019-11-19 08:20:42 -08:00
block_fetcher.cc Divide file_reader_writer.h and .cc (#5803) 2019-09-16 10:33:51 -07:00
block_fetcher.h Combine the read-ahead logic for user reads and compaction reads (#5431) 2019-06-19 14:10:46 -07:00
cleanable_test.cc Move test related files under util/ to test_util/ (#5377) 2019-05-30 11:25:51 -07:00
format.cc Add new persistent 64-bit hash (#5984) 2019-10-31 16:36:35 -07:00
format.h New Bloom filter implementation for full and partitioned filters (#6007) 2019-11-13 16:44:01 -08:00
get_context.cc New API to get all merge operands for a Key (#5604) 2019-08-06 14:26:44 -07:00
get_context.h Fix local includes 2019-08-22 16:21:47 -07:00
internal_iterator.h Revert "Merging iterator to avoid child iterator reseek for some cases (#5286)" (#5871) 2019-10-01 11:22:41 -07:00
iter_heap.h
iterator_wrapper.h Revert "Merging iterator to avoid child iterator reseek for some cases (#5286)" (#5871) 2019-10-01 11:22:41 -07:00
iterator.cc Add an option to put first key of each sst block in the index (#5289) 2019-06-24 20:54:04 -07:00
merger_test.cc Move test related files under util/ to test_util/ (#5377) 2019-05-30 11:25:51 -07:00
merging_iterator.cc Fix a timer bug in MergingIterator::Seek() caused by #5871 (#5874) 2019-10-01 19:26:18 -07:00
merging_iterator.h Index value delta encoding (#3983) 2018-08-09 16:58:40 -07:00
meta_blocks.cc Divide file_reader_writer.h and .cc (#5803) 2019-09-16 10:33:51 -07:00
meta_blocks.h Fix comment of function NotifyCollectTableCollectorsOnFinish (#5738) 2019-08-29 10:57:01 -07:00
mock_table.cc Introduce a new storage specific Env API (#5761) 2019-12-13 14:48:41 -08:00
mock_table.h Apply formatter to recent 200+ commits. (#5830) 2019-09-20 12:04:26 -07:00
multiget_context.h Batched MultiGet API for multiple column families (#5816) 2019-11-12 13:52:55 -08:00
persistent_cache_helper.cc Organizing rocksdb/table directory by format 2019-05-30 14:51:11 -07:00
persistent_cache_helper.h
persistent_cache_options.h
scoped_arena_iterator.h
sst_file_reader_test.cc simplify include directive involving inttypes (#5402) 2019-06-06 13:56:07 -07:00
sst_file_reader.cc Introduce a new storage specific Env API (#5761) 2019-12-13 14:48:41 -08:00
sst_file_writer_collectors.h Fix SstFileReader not able to open ingested file (#5097) 2019-03-26 10:25:18 -07:00
sst_file_writer.cc Introduce a new storage specific Env API (#5761) 2019-12-13 14:48:41 -08:00
table_builder.h Divide file_reader_writer.h and .cc (#5803) 2019-09-16 10:33:51 -07:00
table_properties_internal.h Index value delta encoding (#3983) 2018-08-09 16:58:40 -07:00
table_properties.cc Organizing rocksdb/table directory by format 2019-05-30 14:51:11 -07:00
table_reader_bench.cc Introduce a new storage specific Env API (#5761) 2019-12-13 14:48:41 -08:00
table_reader_caller.h Add more callers for table reader. (#5454) 2019-06-20 14:31:48 -07:00
table_reader.h Apply formatter to recent 200+ commits. (#5830) 2019-09-20 12:04:26 -07:00
table_test.cc Introduce a new storage specific Env API (#5761) 2019-12-13 14:48:41 -08:00
two_level_iterator.cc Add an option to put first key of each sst block in the index (#5289) 2019-06-24 20:54:04 -07:00
two_level_iterator.h Add an option to put first key of each sst block in the index (#5289) 2019-06-24 20:54:04 -07:00