From c7464183ea2bd3969a56c9511c8fc15e3cf5ba92 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 8 Jun 2017 12:07:14 -0400 Subject: [PATCH] kv/RocksDBStore: make rocksdb_cache_type tunable (lru or clock) "[Clock is] Similar to NewLRUCache, but create a cache based on CLOCK algorithm with better concurrent performance in some cases. See [cache]/clock_cache.cc for more detail." Signed-off-by: Sage Weil --- src/common/config_opts.h | 1 + src/kv/RocksDBStore.cc | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 611574471d306..c5806f8629431 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -946,6 +946,7 @@ SAFE_OPTION(rocksdb_db_paths, OPT_STR, "") // path,size( path,size)* OPTION(rocksdb_log_to_ceph_log, OPT_BOOL, true) // log to ceph log OPTION(rocksdb_cache_size, OPT_U64, 128*1024*1024) // default rocksdb cache size OPTION(rocksdb_cache_shard_bits, OPT_INT, 4) // rocksdb block cache shard bits, 4 bit -> 16 shards +OPTION(rocksdb_cache_type, OPT_STR, "lru") // 'lru' or 'clock' OPTION(rocksdb_block_size, OPT_INT, 4*1024) // default rocksdb block size OPTION(rocksdb_perf, OPT_BOOL, false) // Enabling this will have 5-10% impact on performance for the stats collection OPTION(rocksdb_collect_compaction_stats, OPT_BOOL, false) //For rocksdb, this behavior will be an overhead of 5%~10%, collected only rocksdb_perf is enabled. diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index 49d2334161ff5..c6d3e5e553fc2 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -297,18 +297,32 @@ int RocksDBStore::do_open(ostream &out, bool create_if_missing) opt.env = static_cast(priv); } - auto cache = rocksdb::NewLRUCache(g_conf->rocksdb_cache_size, g_conf->rocksdb_cache_shard_bits); + std::shared_ptr cache; + if (g_conf->rocksdb_cache_type == "lru") { + cache = rocksdb::NewLRUCache(g_conf->rocksdb_cache_size, + g_conf->rocksdb_cache_shard_bits); + } else if (g_conf->rocksdb_cache_type == "clock") { + cache = rocksdb::NewClockCache(g_conf->rocksdb_cache_size, + g_conf->rocksdb_cache_shard_bits); + } else { + derr << "unrecognized rocksdb_cache_type '" << g_conf->rocksdb_cache_type + << "'" << dendl; + return -EINVAL; + } + bbt_opts.block_size = g_conf->rocksdb_block_size; bbt_opts.block_cache = cache; if (g_conf->kstore_rocksdb_bloom_bits_per_key > 0) { dout(10) << __func__ << " set bloom filter bits per key to " << g_conf->kstore_rocksdb_bloom_bits_per_key << dendl; - bbt_opts.filter_policy.reset(rocksdb::NewBloomFilterPolicy(g_conf->kstore_rocksdb_bloom_bits_per_key)); + bbt_opts.filter_policy.reset(rocksdb::NewBloomFilterPolicy( + g_conf->kstore_rocksdb_bloom_bits_per_key)); } opt.table_factory.reset(rocksdb::NewBlockBasedTableFactory(bbt_opts)); dout(10) << __func__ << " set block size to " << g_conf->rocksdb_block_size << " cache size to " << g_conf->rocksdb_cache_size - << " num of cache shards to " << (1 << g_conf->rocksdb_cache_shard_bits) << dendl; + << " num of cache shards to " + << (1 << g_conf->rocksdb_cache_shard_bits) << dendl; opt.merge_operator.reset(new MergeOperatorRouter(*this)); status = rocksdb::DB::Open(opt, path, &db); -- 2.39.5