Skip to content

Commit 665fd5f

Browse files
xuguruogudangleptr
andauthored
compaction threads/rate limiter (#2251)
Co-authored-by: trippli <trippli@tencent.com> Co-authored-by: dangleptr <37216992+dangleptr@users.noreply.github.com>
1 parent 8200df1 commit 665fd5f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/kvstore/RocksEngineConfig.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "rocksdb/slice_transform.h"
1515
#include "rocksdb/filter_policy.h"
1616
#include "base/Configuration.h"
17+
#include "rocksdb/concurrent_task_limiter.h"
18+
#include "rocksdb/rate_limiter.h"
1719

1820
// [WAL]
1921
DEFINE_bool(rocksdb_disable_wal,
@@ -63,6 +65,12 @@ DEFINE_string(rocksdb_compression_per_level, "", "Specify per level compression
6365
DEFINE_bool(enable_rocksdb_statistics, false, "Whether or not to enable rocksdb's statistics");
6466
DEFINE_string(rocksdb_stats_level, "kExceptHistogramOrTimers", "rocksdb statistics level");
6567

68+
DEFINE_int32(num_compaction_threads, 0,
69+
"Number of total compaction threads. 0 means unlimited.");
70+
71+
DEFINE_int32(rate_limit, 0,
72+
"write limit in bytes per sec. The unit is MB. 0 means unlimited.");
73+
6674
namespace nebula {
6775
namespace kvstore {
6876

@@ -165,6 +173,16 @@ rocksdb::Status initRocksdbOptions(rocksdb::Options &baseOpts) {
165173
= rocksdb::NewLRUCache(FLAGS_rocksdb_block_cache * 1024 * 1024, 8/*shard bits*/);
166174
bbtOpts.block_cache = blockCache;
167175
}
176+
if (FLAGS_num_compaction_threads > 0) {
177+
static std::shared_ptr<rocksdb::ConcurrentTaskLimiter> compaction_thread_limiter{
178+
rocksdb::NewConcurrentTaskLimiter("compaction", FLAGS_num_compaction_threads)};
179+
baseOpts.compaction_thread_limiter = compaction_thread_limiter;
180+
}
181+
if (FLAGS_rate_limit > 0) {
182+
static std::shared_ptr<rocksdb::RateLimiter> rate_limiter{
183+
rocksdb::NewGenericRateLimiter(FLAGS_rate_limit * 1024 * 1024)};
184+
baseOpts.rate_limiter = rate_limiter;
185+
}
168186

169187
bbtOpts.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, false));
170188
if (FLAGS_enable_partitioned_index_filter) {

0 commit comments

Comments
 (0)