Skip to content

Commit 618f660

Browse files
cbi42facebook-github-bot
authored andcommitted
Configurable multiscan IO coalescing threshold (facebook#13886)
Summary: Add a new filed `io_coalesce_threshold` to MultiScanArgs to make IO coalescing threshold configurable. Pull Request resolved: facebook#13886 Test Plan: db_bench showing less IO requests with higher io_coalesce_threshold ``` Single L0 file, iterator uses BlockBasedTableIterator directly, skipping LevelIterator DB Set up: ./db_bench --benchmarks="fillseq,compact" --disable_wal=1 --threads=1 --num_levels=1 --compaction_style=2 --fifo_compaction_max_table_files_size_mb=1000 --write_buffer_size=268435456 ./db_bench --db="/tmp/rocksdbtest-543376/dbbench" --use_existing_db=1 --benchmarks=multiscan --disable_auto_compactions=1 --seek_nexts=100 --threads=32 --duration=10 --statistics=1 --use_direct_reads=1 .. --multiscan_coalesce_threshold=0 rocksdb.non.last.level.read.bytes COUNT : 54591304136 rocksdb.non.last.level.read.count COUNT : 7680204 multiscan : 397.197 micros/op 79401 ops/sec 10.377 seconds 823968 operations; (multscans:24999) --multiscan_coalesce_threshold=16384 rocksdb.non.last.level.read.bytes COUNT : 95960989272 rocksdb.non.last.level.read.count COUNT : 912008 multiscan : 389.099 micros/op 81064 ops/sec 10.312 seconds 835968 operations; (multscans:25999) --multiscan_coalesce_threshold=163840 rocksdb.non.last.level.read.bytes COUNT : 98805008718 rocksdb.non.last.level.read.count COUNT : 827893 multiscan : 392.831 micros/op 80357 ops/sec 10.353 seconds 831968 operations; (multscans:25999) DB with multiple files in a level, iterator will use LevelIterator ./db_bench --benchmarks="fillseq,compact" --disable_wal=1 --threads=1 --num_levels=6 --num=10000000 ./db_bench --db="/tmp/rocksdbtest-543376/dbbench" --use_existing_db=1 --benchmarks=multiscan --disable_auto_compactions=1 --seek_nexts=100 --threads=32 --duration=10 --statistics=1 --use_direct_reads=1 --num=10000000 --multiscan_coalesce_threshold=0 multiscan : 1161.734 micros/op 26995 ops/sec 10.667 seconds 287968 operations; (multscans:8999) rocksdb.non.last.level.read.bytes COUNT : 23917753523 rocksdb.non.last.level.read.count COUNT : 2868907 --multiscan_coalesce_threshold=16384 rocksdb.non.last.level.read.bytes COUNT : 35022281853 rocksdb.non.last.level.read.count COUNT : 287375 multiscan : 1195.336 micros/op 26265 ops/sec 10.850 seconds 284968 operations; (multscans:8999) ``` Reviewed By: anand1976 Differential Revision: D80381441 Pulled By: cbi42 fbshipit-source-id: 57cc67df4a808e27c3a48ddf3ef6907bec131ee9
1 parent 84f8144 commit 618f660

5 files changed

Lines changed: 21 additions & 6 deletions

File tree

db/version_set.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,10 @@ class LevelIterator final : public InternalIterator {
11441144
}
11451145
}
11461146
}
1147+
// Propagate io colaescing threshold
1148+
for (auto& file_to_arg : *file_to_scan_opts_) {
1149+
file_to_arg.second.io_coalesce_threshold = so->io_coalesce_threshold;
1150+
}
11471151
}
11481152

11491153
private:
@@ -6491,7 +6495,7 @@ Status VersionSet::ReduceNumberOfLevels(const std::string& dbname,
64916495
nullptr /*BlockCacheTracer*/, nullptr /*IOTracer*/,
64926496
/*db_id*/ "",
64936497
/*db_session_id*/ "", options->daily_offpeak_time_utc,
6494-
/*error_handler_*/ nullptr, /*read_only=*/false);
6498+
/*error_handler_*/ nullptr, /*unchanging=*/false);
64956499
Status status;
64966500

64976501
std::vector<ColumnFamilyDescriptor> dummy;

include/rocksdb/options.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1789,21 +1789,25 @@ class MultiScanArgs {
17891789
MultiScanArgs(const MultiScanArgs& other) {
17901790
comp_ = other.comp_;
17911791
original_ranges_ = other.original_ranges_;
1792+
io_coalesce_threshold = other.io_coalesce_threshold;
17921793
}
17931794
MultiScanArgs(MultiScanArgs&& other) noexcept
1794-
: comp_(other.comp_),
1795+
: io_coalesce_threshold(other.io_coalesce_threshold),
1796+
comp_(other.comp_),
17951797
original_ranges_(std::move(other.original_ranges_)) {}
17961798

17971799
MultiScanArgs& operator=(const MultiScanArgs& other) {
17981800
comp_ = other.comp_;
17991801
original_ranges_ = other.original_ranges_;
1802+
io_coalesce_threshold = other.io_coalesce_threshold;
18001803
return *this;
18011804
}
18021805

18031806
MultiScanArgs& operator=(MultiScanArgs&& other) noexcept {
18041807
if (this != &other) {
18051808
comp_ = other.comp_;
18061809
original_ranges_ = std::move(other.original_ranges_);
1810+
io_coalesce_threshold = other.io_coalesce_threshold;
18071811
}
18081812
return *this;
18091813
}
@@ -1843,6 +1847,8 @@ class MultiScanArgs {
18431847
return original_ranges_;
18441848
}
18451849

1850+
uint64_t io_coalesce_threshold = 16 << 10; // 16KB by default
1851+
18461852
private:
18471853
// The comparator used for ordering ranges
18481854
const Comparator* comp_;

table/block_based/block_based_table_iterator.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,9 +1067,6 @@ void BlockBasedTableIterator::Prepare(const MultiScanArgs* multiscan_opts) {
10671067
// Each member in the vector is an index into blocks_to_prepare.
10681068
std::vector<std::vector<size_t>> collapsed_blocks_to_read(1);
10691069

1070-
// TODO: make this threshold configurable
1071-
constexpr size_t kCoalesceThreshold = 16 << 10; // 16KB
1072-
10731070
for (const auto& block_idx : blocks_to_read) {
10741071
if (!collapsed_blocks_to_read.back().empty()) {
10751072
// Check if we can coalesce.
@@ -1080,7 +1077,8 @@ void BlockBasedTableIterator::Prepare(const MultiScanArgs* multiscan_opts) {
10801077
BlockBasedTable::BlockSizeWithTrailer(last_block);
10811078
uint64_t current_start = blocks_to_prepare[block_idx].offset();
10821079

1083-
if (current_start > last_block_end + kCoalesceThreshold) {
1080+
if (current_start >
1081+
last_block_end + multiscan_opts->io_coalesce_threshold) {
10841082
// new IO
10851083
collapsed_blocks_to_read.emplace_back();
10861084
}

tools/db_bench_tool.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,10 @@ DEFINE_bool(universal_reduce_file_locking,
18471847
.compaction_options_universal.reduce_file_locking,
18481848
"See Options().compaction_options_universal.reduce_file_locking");
18491849

1850+
DEFINE_uint64(multiscan_coalesce_threshold,
1851+
ROCKSDB_NAMESPACE::MultiScanArgs().io_coalesce_threshold,
1852+
"Configures io coalescing threshold for multiscans");
1853+
18501854
namespace ROCKSDB_NAMESPACE {
18511855
namespace {
18521856
static Status CreateMemTableRepFactory(
@@ -6413,6 +6417,7 @@ class Benchmark {
64136417
while (!duration.Done(1)) {
64146418
DB* db = SelectDB(thread);
64156419
MultiScanArgs opts;
6420+
opts.io_coalesce_threshold = FLAGS_multiscan_coalesce_threshold;
64166421
std::vector<std::unique_ptr<const char[]>> guards;
64176422
opts.reserve(multiscan_size);
64186423
// We create 1 random start, and then multiscan will start from that
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* Introduce `MultiScanArgs::io_coalesce_threshold` to allow a configurable IO coalescing threshold.
2+

0 commit comments

Comments
 (0)