]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
kv/RocksDBStore: make rocksdb_cache_type tunable (lru or clock)
authorSage Weil <sage@redhat.com>
Thu, 8 Jun 2017 16:07:14 +0000 (12:07 -0400)
committerSage Weil <sage@redhat.com>
Fri, 9 Jun 2017 13:30:42 +0000 (09:30 -0400)
"[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 <sage@redhat.com>
src/common/config_opts.h
src/kv/RocksDBStore.cc

index 611574471d306ad954e55221f5bf2b098eb7555a..c5806f86294318822eb8b5e873fa52e27601849a 100644 (file)
@@ -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.
index 49d2334161ff5851fe493278f7f4a9ffc3875585..c6d3e5e553fc238a60921621bd78d34ad0cb49a1 100644 (file)
@@ -297,18 +297,32 @@ int RocksDBStore::do_open(ostream &out, bool create_if_missing)
     opt.env = static_cast<rocksdb::Env*>(priv);
   }
 
-  auto cache = rocksdb::NewLRUCache(g_conf->rocksdb_cache_size, g_conf->rocksdb_cache_shard_bits);
+  std::shared_ptr<rocksdb::Cache> 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);