Skip to content

Commit 2e98be2

Browse files
Adding rocksdb bloom filter knobs.
1 parent c3ad9b5 commit 2e98be2

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

fdbclient/ServerKnobs.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ void ServerKnobs::initialize(Randomize randomize, ClientKnobs* clientKnobs, IsSi
377377
init( ROCKSDB_UNSAFE_AUTO_FSYNC, false );
378378
init( ROCKSDB_PERIODIC_COMPACTION_SECONDS, 0 );
379379
init( ROCKSDB_PREFIX_LEN, 0 );
380+
init( ROCKSDB_MEMTABLE_PREFIX_BLOOM_SIZE_RATIO, 0.1 );
381+
init( ROCKSDB_BLOOM_BITS_PER_KEY, 10 );
382+
init( ROCKSDB_BLOOM_WHOLE_KEY_FILTERING, false );
383+
init( ROCKSDB_MAX_AUTO_READAHEAD_SIZE, 0 );
380384
// If rocksdb block cache size is 0, the default 8MB is used.
381385
int64_t blockCacheSize = isSimulated ? 16 * 1024 * 1024 : 2147483648 /* 2GB */;
382386
init( ROCKSDB_BLOCK_CACHE_SIZE, blockCacheSize );

fdbclient/ServerKnobs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ class ServerKnobs : public KnobsImpl<ServerKnobs> {
306306
bool ROCKSDB_UNSAFE_AUTO_FSYNC;
307307
int64_t ROCKSDB_PERIODIC_COMPACTION_SECONDS;
308308
int ROCKSDB_PREFIX_LEN;
309+
double ROCKSDB_MEMTABLE_PREFIX_BLOOM_SIZE_RATIO;
310+
int ROCKSDB_BLOOM_BITS_PER_KEY;
311+
bool ROCKSDB_BLOOM_WHOLE_KEY_FILTERING;
312+
int ROCKSDB_MAX_AUTO_READAHEAD_SIZE;
309313
int64_t ROCKSDB_BLOCK_CACHE_SIZE;
310314
double ROCKSDB_METRICS_DELAY;
311315
double ROCKSDB_READ_VALUE_TIMEOUT;

fdbserver/KeyValueStoreRocksDB.actor.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,7 @@ rocksdb::ColumnFamilyOptions getCFOptions() {
340340
options.prefix_extractor.reset(rocksdb::NewFixedPrefixTransform(SERVER_KNOBS->ROCKSDB_PREFIX_LEN));
341341

342342
// Also turn on bloom filters in the memtable.
343-
// TODO: Make a knob for this as well.
344-
options.memtable_prefix_bloom_size_ratio = 0.1;
343+
options.memtable_prefix_bloom_size_ratio = SERVER_KNOBS->ROCKSDB_MEMTABLE_PREFIX_BLOOM_SIZE_RATIO;
345344

346345
// 5 -- Can be read by RocksDB's versions since 6.6.0. Full and partitioned
347346
// filters use a generally faster and more accurate Bloom filter
@@ -352,11 +351,11 @@ rocksdb::ColumnFamilyOptions getCFOptions() {
352351
// Create and apply a bloom filter using the 10 bits
353352
// which should yield a ~1% false positive rate:
354353
// https://github.com/facebook/rocksdb/wiki/RocksDB-Bloom-Filter#full-filters-new-format
355-
bbOpts.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10));
354+
bbOpts.filter_policy.reset(rocksdb::NewBloomFilterPolicy(SERVER_KNOBS->ROCKSDB_BLOOM_BITS_PER_KEY));
356355

357356
// The whole key blooms are only used for point lookups.
358357
// https://github.com/facebook/rocksdb/wiki/RocksDB-Bloom-Filter#prefix-vs-whole-key
359-
bbOpts.whole_key_filtering = false;
358+
bbOpts.whole_key_filtering = SERVER_KNOBS->ROCKSDB_BLOOM_WHOLE_KEY_FILTERING;
360359
}
361360

362361
if (SERVER_KNOBS->ROCKSDB_BLOCK_CACHE_SIZE > 0) {
@@ -369,6 +368,12 @@ rocksdb::ColumnFamilyOptions getCFOptions() {
369368
bbOpts.block_size = SERVER_KNOBS->ROCKSDB_BLOCK_SIZE;
370369
}
371370

371+
// The readahead size starts with 8KB and is exponentially increased on each additional sequential IO,
372+
// up to a max of BlockBasedTableOptions.max_auto_readahead_size (default 256 KB)
373+
if (SERVER_KNOBS->ROCKSDB_MAX_AUTO_READAHEAD_SIZE > 0) {
374+
bbOpts.max_auto_readahead_size = SERVER_KNOBS->ROCKSDB_MAX_AUTO_READAHEAD_SIZE;
375+
}
376+
372377
options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(bbOpts));
373378

374379
return options;
@@ -411,13 +416,14 @@ struct Counters {
411416
Counter convertedDeleteKeyReqs;
412417
Counter convertedDeleteRangeReqs;
413418
Counter rocksdbReadRangeQueries;
419+
Counter commitDelayed;
414420

415421
Counters()
416422
: cc("RocksDBThrottle"), immediateThrottle("ImmediateThrottle", cc), failedToAcquire("FailedToAcquire", cc),
417423
deleteKeyReqs("DeleteKeyRequests", cc), deleteRangeReqs("DeleteRangeRequests", cc),
418424
convertedDeleteKeyReqs("ConvertedDeleteKeyRequests", cc),
419425
convertedDeleteRangeReqs("ConvertedDeleteRangeRequests", cc),
420-
rocksdbReadRangeQueries("RocksdbReadRangeQueries", cc) {}
426+
rocksdbReadRangeQueries("RocksdbReadRangeQueries", cc), commitDelayed("CommitDelayed", cc) {}
421427
};
422428

423429
struct ReadIterator {
@@ -935,6 +941,8 @@ ACTOR Future<Void> rocksDBMetricLogger(UID id,
935941
{ "RowCacheHit", rocksdb::ROW_CACHE_HIT, 0 },
936942
{ "RowCacheMiss", rocksdb::ROW_CACHE_MISS, 0 },
937943
{ "CountIterSkippedKeys", rocksdb::NUMBER_ITER_SKIP, 0 },
944+
{ "NoIteratorCreated", rocksdb::NO_ITERATOR_CREATED, 0 },
945+
{ "NoIteratorDeleted", rocksdb::NO_ITERATOR_DELETED, 0 },
938946
};
939947

940948
// To control the rocksdb::StatsLevel, use ROCKSDB_STATS_LEVEL knob.
@@ -2119,9 +2127,12 @@ struct RocksDBKeyValueStore : IKeyValueStore {
21192127
&estPendCompactBytes);
21202128
while (count && estPendCompactBytes > SERVER_KNOBS->ROCKSDB_CAN_COMMIT_COMPACT_BYTES_LIMIT) {
21212129
wait(delay(SERVER_KNOBS->ROCKSDB_CAN_COMMIT_DELAY_ON_OVERLOAD));
2130+
++self->counters.commitDelayed;
21222131
count--;
21232132
self->db->GetAggregatedIntProperty(rocksdb::DB::Properties::kEstimatePendingCompactionBytes,
21242133
&estPendCompactBytes);
2134+
if (deterministicRandom()->random01() < 0.001)
2135+
TraceEvent(SevWarn, "RocksDBCommitsDelayed1000x", self->id);
21252136
}
21262137

21272138
return Void();

0 commit comments

Comments
 (0)