diff options
author | Siying Dong <siying.d@fb.com> | 2019-04-11 10:22:07 -0700 |
---|---|---|
committer | Facebook Github Bot <facebook-github-bot@users.noreply.github.com> | 2019-04-11 10:45:36 -0700 |
commit | ed9f5e21aa21d1bba868c975bf111ac6fb2958df (patch) | |
tree | f22fb6dddd3ce9c41b62cf2cab7af400e9fb5876 /options | |
parent | d3d20dcdca9dc79d893a03dfa611fb1055c28f96 (diff) |
Change OptimizeForPointLookup() and OptimizeForSmallDb() (#5165)
Summary:
Change the behavior of OptimizeForSmallDb() so that it is less likely to go out of memory.
Change the behavior of OptimizeForPointLookup() to take advantage of the new memtable whole key filter, and move away from prefix extractor as well as hash-based indexing, as they are prone to misuse.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5165
Differential Revision: D14880709
Pulled By: siying
fbshipit-source-id: 9af30e3c9e151eceea6d6b38701a58f1f9fb692d
Diffstat (limited to 'options')
-rw-r--r-- | options/options.cc | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/options/options.cc b/options/options.cc index aaf8c68ab..bfe3e313d 100644 --- a/options/options.cc +++ b/options/options.cc @@ -413,8 +413,11 @@ Options::PrepareForBulkLoad() } Options* Options::OptimizeForSmallDb() { - ColumnFamilyOptions::OptimizeForSmallDb(); - DBOptions::OptimizeForSmallDb(); + // 16MB block cache + std::shared_ptr<Cache> cache = NewLRUCache(16 << 20); + + ColumnFamilyOptions::OptimizeForSmallDb(&cache); + DBOptions::OptimizeForSmallDb(&cache); return this; } @@ -469,27 +472,44 @@ ColumnFamilyOptions* ColumnFamilyOptions::OldDefaults( } // Optimization functions -DBOptions* DBOptions::OptimizeForSmallDb() { +DBOptions* DBOptions::OptimizeForSmallDb(std::shared_ptr<Cache>* cache) { max_file_opening_threads = 1; max_open_files = 5000; + + // Cost memtable to block cache too. + std::shared_ptr<rocksdb::WriteBufferManager> wbm = + std::make_shared<rocksdb::WriteBufferManager>( + 0, (cache != nullptr) ? *cache : std::shared_ptr<Cache>()); + write_buffer_manager = wbm; + return this; } -ColumnFamilyOptions* ColumnFamilyOptions::OptimizeForSmallDb() { +ColumnFamilyOptions* ColumnFamilyOptions::OptimizeForSmallDb( + std::shared_ptr<Cache>* cache) { write_buffer_size = 2 << 20; target_file_size_base = 2 * 1048576; max_bytes_for_level_base = 10 * 1048576; soft_pending_compaction_bytes_limit = 256 * 1048576; hard_pending_compaction_bytes_limit = 1073741824ul; + + BlockBasedTableOptions table_options; + table_options.block_cache = + (cache != nullptr) ? *cache : std::shared_ptr<Cache>(); + table_options.cache_index_and_filter_blocks = true; + // Two level iterator to avoid LRU cache imbalance + table_options.index_type = + BlockBasedTableOptions::IndexType::kTwoLevelIndexSearch; + table_factory.reset(new BlockBasedTableFactory(table_options)); + + return this; } #ifndef ROCKSDB_LITE ColumnFamilyOptions* ColumnFamilyOptions::OptimizeForPointLookup( uint64_t block_cache_size_mb) { - prefix_extractor.reset(NewNoopTransform()); BlockBasedTableOptions block_based_options; - block_based_options.index_type = BlockBasedTableOptions::kHashSearch; block_based_options.data_block_index_type = BlockBasedTableOptions::kDataBlockBinaryAndHash; block_based_options.data_block_hash_table_util_ratio = 0.75; @@ -498,6 +518,7 @@ ColumnFamilyOptions* ColumnFamilyOptions::OptimizeForPointLookup( NewLRUCache(static_cast<size_t>(block_cache_size_mb * 1024 * 1024)); table_factory.reset(new BlockBasedTableFactory(block_based_options)); memtable_prefix_bloom_size_ratio = 0.02; + memtable_whole_key_filtering = true; return this; } |