diff --git a/conf/pika.conf b/conf/pika.conf index c50271b92d..502ec2f831 100644 --- a/conf/pika.conf +++ b/conf/pika.conf @@ -142,6 +142,10 @@ max-bytes-for-level-multiplier : 10 # block-size: 4096 # block LRU cache, default 8M, 0 to disable # block-cache: 8388608 +# num-shard-bits default -1, the number of bits from cache keys to be use as shard id. +# The cache will be sharded into 2^num_shard_bits shards. +# /~https://github.com/EighteenZi/rocksdb_wiki/blob/master/Block-Cache.md#lru-cache +# num-shard-bits: -1 # whether the block cache is shared among the RocksDB instances, default is per CF # share-block-cache: no # whether or not index and filter blocks is stored in block cache diff --git a/include/pika_conf.h b/include/pika_conf.h index 3e48f8c352..ec4dcf8ea0 100644 --- a/include/pika_conf.h +++ b/include/pika_conf.h @@ -73,6 +73,7 @@ class PikaConf : public slash::BaseConf { int max_bytes_for_level_multiplier() { RWLock l(&rwlock_, false); return max_bytes_for_level_multiplier_; } int64_t block_size() { RWLock l(&rwlock_, false); return block_size_; } int64_t block_cache() { RWLock l(&rwlock_, false); return block_cache_; } + int64_t num_shard_bits() { RWLock l(&rwlock_, false); return num_shard_bits_; } bool share_block_cache() { RWLock l(&rwlock_, false); return share_block_cache_; } bool cache_index_and_filter_blocks() { RWLock l(&rwlock_, false); return cache_index_and_filter_blocks_; } bool pin_l0_filter_and_index_blocks_in_cache() { RWLock l(&rwlock_, false); return pin_l0_filter_and_index_blocks_in_cache_; } @@ -342,6 +343,7 @@ class PikaConf : public slash::BaseConf { int max_bytes_for_level_multiplier_; int64_t block_size_; int64_t block_cache_; + int64_t num_shard_bits_; bool share_block_cache_; bool cache_index_and_filter_blocks_; bool pin_l0_filter_and_index_blocks_in_cache_; diff --git a/src/pika_conf.cc b/src/pika_conf.cc index dc48881a5d..16ad536a15 100644 --- a/src/pika_conf.cc +++ b/src/pika_conf.cc @@ -448,6 +448,9 @@ int PikaConf::Load() block_cache_ = 8 * 1024 * 1024; } + num_shard_bits_ = -1; + GetConfInt64("num-shard-bits", &num_shard_bits_); + std::string sbc; GetConfStr("share-block-cache", &sbc); share_block_cache_ = (sbc == "yes") ? true : false; diff --git a/src/pika_server.cc b/src/pika_server.cc index 07c2d62165..6b14df3474 100644 --- a/src/pika_server.cc +++ b/src/pika_server.cc @@ -1657,7 +1657,7 @@ void PikaServer::InitBlackwidowOptions() { bw_options_.table_options.no_block_cache = true; } else if (bw_options_.share_block_cache) { bw_options_.table_options.block_cache = - rocksdb::NewLRUCache(bw_options_.block_cache_size); + rocksdb::NewLRUCache(bw_options_.block_cache_size, g_pika_conf->num_shard_bits()); } // For Blackwidow small compaction