mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-28 05:43:50 +00:00
06e593376c
Summary: ## Context/Summary Similar to https://github.com/facebook/rocksdb/pull/11288, https://github.com/facebook/rocksdb/pull/11444, categorizing SST/blob file write according to different io activities allows more insight into the activity. For that, this PR does the following: - Tag different write IOs by passing down and converting WriteOptions to IOOptions - Add new SST_WRITE_MICROS histogram in WritableFileWriter::Append() and breakdown FILE_WRITE_{FLUSH|COMPACTION|DB_OPEN}_MICROS Some related code refactory to make implementation cleaner: - Blob stats - Replace high-level write measurement with low-level WritableFileWriter::Append() measurement for BLOB_DB_BLOB_FILE_WRITE_MICROS. This is to make FILE_WRITE_{FLUSH|COMPACTION|DB_OPEN}_MICROS include blob file. As a consequence, this introduces some behavioral changes on it, see HISTORY and db bench test plan below for more info. - Fix bugs where BLOB_DB_BLOB_FILE_SYNCED/BLOB_DB_BLOB_FILE_BYTES_WRITTEN include file failed to sync and bytes failed to write. - Refactor WriteOptions constructor for easier construction with io_activity and rate_limiter_priority - Refactor DBImpl::~DBImpl()/BlobDBImpl::Close() to bypass thread op verification - Build table - TableBuilderOptions now includes Read/WriteOpitons so BuildTable() do not need to take these two variables - Replace the io_priority passed into BuildTable() with TableBuilderOptions::WriteOpitons::rate_limiter_priority. Similar for BlobFileBuilder. This parameter is used for dynamically changing file io priority for flush, see https://github.com/facebook/rocksdb/pull/9988?fbclid=IwAR1DtKel6c-bRJAdesGo0jsbztRtciByNlvokbxkV6h_L-AE9MACzqRTT5s for more - Update ThreadStatus::FLUSH_BYTES_WRITTEN to use io_activity to track flush IO in flush job and db open instead of io_priority ## Test ### db bench Flush ``` ./db_bench --statistics=1 --benchmarks=fillseq --num=100000 --write_buffer_size=100 rocksdb.sst.write.micros P50 : 1.830863 P95 : 4.094720 P99 : 6.578947 P100 : 26.000000 COUNT : 7875 SUM : 20377 rocksdb.file.write.flush.micros P50 : 1.830863 P95 : 4.094720 P99 : 6.578947 P100 : 26.000000 COUNT : 7875 SUM : 20377 rocksdb.file.write.compaction.micros P50 : 0.000000 P95 : 0.000000 P99 : 0.000000 P100 : 0.000000 COUNT : 0 SUM : 0 rocksdb.file.write.db.open.micros P50 : 0.000000 P95 : 0.000000 P99 : 0.000000 P100 : 0.000000 COUNT : 0 SUM : 0 ``` compaction, db oopen ``` Setup: ./db_bench --statistics=1 --benchmarks=fillseq --num=10000 --disable_auto_compactions=1 -write_buffer_size=100 --db=../db_bench Run:./db_bench --statistics=1 --benchmarks=compact --db=../db_bench --use_existing_db=1 rocksdb.sst.write.micros P50 : 2.675325 P95 : 9.578788 P99 : 18.780000 P100 : 314.000000 COUNT : 638 SUM : 3279 rocksdb.file.write.flush.micros P50 : 0.000000 P95 : 0.000000 P99 : 0.000000 P100 : 0.000000 COUNT : 0 SUM : 0 rocksdb.file.write.compaction.micros P50 : 2.757353 P95 : 9.610687 P99 : 19.316667 P100 : 314.000000 COUNT : 615 SUM : 3213 rocksdb.file.write.db.open.micros P50 : 2.055556 P95 : 3.925000 P99 : 9.000000 P100 : 9.000000 COUNT : 23 SUM : 66 ``` blob stats - just to make sure they aren't broken by this PR ``` Integrated Blob DB Setup: ./db_bench --enable_blob_files=1 --statistics=1 --benchmarks=fillseq --num=10000 --disable_auto_compactions=1 -write_buffer_size=100 --db=../db_bench Run:./db_bench --enable_blob_files=1 --statistics=1 --benchmarks=compact --db=../db_bench --use_existing_db=1 pre-PR: rocksdb.blobdb.blob.file.write.micros P50 : 7.298246 P95 : 9.771930 P99 : 9.991813 P100 : 16.000000 COUNT : 235 SUM : 1600 rocksdb.blobdb.blob.file.synced COUNT : 1 rocksdb.blobdb.blob.file.bytes.written COUNT : 34842 post-PR: rocksdb.blobdb.blob.file.write.micros P50 : 2.000000 P95 : 2.829360 P99 : 2.993779 P100 : 9.000000 COUNT : 707 SUM : 1614 - COUNT is higher and values are smaller as it includes header and footer write - COUNT is 3X higher due to each Append() count as one post-PR, while in pre-PR, 3 Append()s counts as one. See https://github.com/facebook/rocksdb/pull/11910/files#diff-32b811c0a1c000768cfb2532052b44dc0b3bf82253f3eab078e15ff201a0dabfL157-L164 rocksdb.blobdb.blob.file.synced COUNT : 1 (stay the same) rocksdb.blobdb.blob.file.bytes.written COUNT : 34842 (stay the same) ``` ``` Stacked Blob DB Run: ./db_bench --use_blob_db=1 --statistics=1 --benchmarks=fillseq --num=10000 --disable_auto_compactions=1 -write_buffer_size=100 --db=../db_bench pre-PR: rocksdb.blobdb.blob.file.write.micros P50 : 12.808042 P95 : 19.674497 P99 : 28.539683 P100 : 51.000000 COUNT : 10000 SUM : 140876 rocksdb.blobdb.blob.file.synced COUNT : 8 rocksdb.blobdb.blob.file.bytes.written COUNT : 1043445 post-PR: rocksdb.blobdb.blob.file.write.micros P50 : 1.657370 P95 : 2.952175 P99 : 3.877519 P100 : 24.000000 COUNT : 30001 SUM : 67924 - COUNT is higher and values are smaller as it includes header and footer write - COUNT is 3X higher due to each Append() count as one post-PR, while in pre-PR, 3 Append()s counts as one. See https://github.com/facebook/rocksdb/pull/11910/files#diff-32b811c0a1c000768cfb2532052b44dc0b3bf82253f3eab078e15ff201a0dabfL157-L164 rocksdb.blobdb.blob.file.synced COUNT : 8 (stay the same) rocksdb.blobdb.blob.file.bytes.written COUNT : 1043445 (stay the same) ``` ### Rehearsal CI stress test Trigger 3 full runs of all our CI stress tests ### Performance Flush ``` TEST_TMPDIR=/dev/shm ./db_basic_bench_pre_pr --benchmark_filter=ManualFlush/key_num:524288/per_key_size:256 --benchmark_repetitions=1000 -- default: 1 thread is used to run benchmark; enable_statistics = true Pre-pr: avg 507515519.3 ns 497686074,499444327,500862543,501389862,502994471,503744435,504142123,504224056,505724198,506610393,506837742,506955122,507695561,507929036,508307733,508312691,508999120,509963561,510142147,510698091,510743096,510769317,510957074,511053311,511371367,511409911,511432960,511642385,511691964,511730908, Post-pr: avg 511971266.5 ns, regressed 0.88% 502744835,506502498,507735420,507929724,508313335,509548582,509994942,510107257,510715603,511046955,511352639,511458478,512117521,512317380,512766303,512972652,513059586,513804934,513808980,514059409,514187369,514389494,514447762,514616464,514622882,514641763,514666265,514716377,514990179,515502408, ``` Compaction ``` TEST_TMPDIR=/dev/shm ./db_basic_bench_{pre|post}_pr --benchmark_filter=ManualCompaction/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1 --benchmark_repetitions=1000 -- default: 1 thread is used to run benchmark Pre-pr: avg 495346098.30 ns 492118301,493203526,494201411,494336607,495269217,495404950,496402598,497012157,497358370,498153846 Post-pr: avg 504528077.20, regressed 1.85%. "ManualCompaction" include flush so the isolated regression for compaction should be around 1.85-0.88 = 0.97% 502465338,502485945,502541789,502909283,503438601,504143885,506113087,506629423,507160414,507393007 ``` Put with WAL (in case passing WriteOptions slows down this path even without collecting SST write stats) ``` TEST_TMPDIR=/dev/shm ./db_basic_bench_pre_pr --benchmark_filter=DBPut/comp_style:0/max_data:107374182400/per_key_size:256/enable_statistics:1/wal:1 --benchmark_repetitions=1000 -- default: 1 thread is used to run benchmark Pre-pr: avg 3848.10 ns 3814,3838,3839,3848,3854,3854,3854,3860,3860,3860 Post-pr: avg 3874.20 ns, regressed 0.68% 3863,3867,3871,3874,3875,3877,3877,3877,3880,3881 ``` Pull Request resolved: https://github.com/facebook/rocksdb/pull/11910 Reviewed By: ajkr Differential Revision: D49788060 Pulled By: hx235 fbshipit-source-id: 79e73699cda5be3b66461687e5147c2484fc5eff
343 lines
11 KiB
C++
343 lines
11 KiB
C++
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
//
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
#include "rocksdb/db_bench_tool.h"
|
|
|
|
#include "db/db_impl/db_impl.h"
|
|
#include "options/options_parser.h"
|
|
#include "rocksdb/utilities/options_util.h"
|
|
#include "test_util/testharness.h"
|
|
#include "test_util/testutil.h"
|
|
#include "util/random.h"
|
|
|
|
#ifdef GFLAGS
|
|
#include "util/gflags_compat.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
namespace {
|
|
static const int kMaxArgCount = 100;
|
|
static const size_t kArgBufferSize = 100000;
|
|
} // namespace
|
|
|
|
class DBBenchTest : public testing::Test {
|
|
public:
|
|
DBBenchTest() : rnd_(0xFB) {
|
|
test_path_ = test::PerThreadDBPath("db_bench_test");
|
|
Env::Default()->CreateDir(test_path_);
|
|
db_path_ = test_path_ + "/db";
|
|
wal_path_ = test_path_ + "/wal";
|
|
}
|
|
|
|
~DBBenchTest() {
|
|
// DestroyDB(db_path_, Options());
|
|
}
|
|
|
|
void ResetArgs() {
|
|
argc_ = 0;
|
|
cursor_ = 0;
|
|
memset(arg_buffer_, 0, kArgBufferSize);
|
|
}
|
|
|
|
void AppendArgs(const std::vector<std::string>& args) {
|
|
for (const auto& arg : args) {
|
|
ASSERT_LE(cursor_ + arg.size() + 1, kArgBufferSize);
|
|
ASSERT_LE(argc_ + 1, kMaxArgCount);
|
|
snprintf(arg_buffer_ + cursor_, arg.size() + 1, "%s", arg.c_str());
|
|
|
|
argv_[argc_++] = arg_buffer_ + cursor_;
|
|
cursor_ += arg.size() + 1;
|
|
}
|
|
}
|
|
|
|
// Gets the default options for this test/db_bench.
|
|
// Note that db_bench may change some of the default option values and that
|
|
// the database might as well. The options changed by db_bench are
|
|
// specified here; the ones by the DB are set via SanitizeOptions
|
|
Options GetDefaultOptions(CompactionStyle style = kCompactionStyleLevel,
|
|
int levels = 7) const {
|
|
Options opt;
|
|
|
|
opt.create_if_missing = true;
|
|
opt.max_open_files = 256;
|
|
opt.max_background_compactions = 10;
|
|
opt.dump_malloc_stats = true; // db_bench uses a different default
|
|
opt.compaction_style = style;
|
|
opt.num_levels = levels;
|
|
opt.compression = kNoCompression;
|
|
opt.arena_block_size = 8388608;
|
|
|
|
return SanitizeOptions(db_path_, opt);
|
|
}
|
|
|
|
void RunDbBench(const std::string& options_file_name) {
|
|
AppendArgs({"./db_bench", "--benchmarks=fillseq", "--use_existing_db=0",
|
|
"--num=1000", "--compression_type=none",
|
|
std::string(std::string("--db=") + db_path_).c_str(),
|
|
std::string(std::string("--wal_dir=") + wal_path_).c_str(),
|
|
std::string(std::string("--options_file=") + options_file_name)
|
|
.c_str()});
|
|
ASSERT_EQ(0, db_bench_tool(argc(), argv()));
|
|
}
|
|
|
|
void VerifyOptions(const Options& opt) {
|
|
DBOptions loaded_db_opts;
|
|
ConfigOptions config_opts;
|
|
config_opts.ignore_unknown_options = false;
|
|
config_opts.input_strings_escaped = true;
|
|
config_opts.env = Env::Default();
|
|
std::vector<ColumnFamilyDescriptor> cf_descs;
|
|
ASSERT_OK(
|
|
LoadLatestOptions(config_opts, db_path_, &loaded_db_opts, &cf_descs));
|
|
|
|
ConfigOptions exact;
|
|
exact.input_strings_escaped = false;
|
|
exact.sanity_level = ConfigOptions::kSanityLevelExactMatch;
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyDBOptions(exact, DBOptions(opt),
|
|
loaded_db_opts));
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyCFOptions(
|
|
exact, ColumnFamilyOptions(opt), cf_descs[0].options));
|
|
|
|
// check with the default rocksdb options and expect failure
|
|
ASSERT_NOK(RocksDBOptionsParser::VerifyDBOptions(exact, DBOptions(),
|
|
loaded_db_opts));
|
|
ASSERT_NOK(RocksDBOptionsParser::VerifyCFOptions(
|
|
exact, ColumnFamilyOptions(), cf_descs[0].options));
|
|
}
|
|
|
|
char** argv() { return argv_; }
|
|
|
|
int argc() { return argc_; }
|
|
|
|
std::string db_path_;
|
|
std::string test_path_;
|
|
std::string wal_path_;
|
|
|
|
char arg_buffer_[kArgBufferSize];
|
|
char* argv_[kMaxArgCount];
|
|
int argc_ = 0;
|
|
int cursor_ = 0;
|
|
Random rnd_;
|
|
};
|
|
|
|
namespace {} // namespace
|
|
|
|
TEST_F(DBBenchTest, OptionsFile) {
|
|
const std::string kOptionsFileName = test_path_ + "/OPTIONS_test";
|
|
Options opt = GetDefaultOptions();
|
|
ASSERT_OK(PersistRocksDBOptions(WriteOptions(), DBOptions(opt), {"default"},
|
|
{ColumnFamilyOptions(opt)}, kOptionsFileName,
|
|
opt.env->GetFileSystem().get()));
|
|
|
|
// override the following options as db_bench will not take these
|
|
// options from the options file
|
|
opt.wal_dir = wal_path_;
|
|
|
|
RunDbBench(kOptionsFileName);
|
|
opt.delayed_write_rate = 16 * 1024 * 1024; // Set by SanitizeOptions
|
|
|
|
VerifyOptions(opt);
|
|
}
|
|
|
|
TEST_F(DBBenchTest, OptionsFileUniversal) {
|
|
const std::string kOptionsFileName = test_path_ + "/OPTIONS_test";
|
|
|
|
Options opt = GetDefaultOptions(kCompactionStyleUniversal, 1);
|
|
|
|
ASSERT_OK(PersistRocksDBOptions(WriteOptions(), DBOptions(opt), {"default"},
|
|
{ColumnFamilyOptions(opt)}, kOptionsFileName,
|
|
opt.env->GetFileSystem().get()));
|
|
|
|
// override the following options as db_bench will not take these
|
|
// options from the options file
|
|
opt.wal_dir = wal_path_;
|
|
RunDbBench(kOptionsFileName);
|
|
|
|
VerifyOptions(opt);
|
|
}
|
|
|
|
TEST_F(DBBenchTest, OptionsFileMultiLevelUniversal) {
|
|
const std::string kOptionsFileName = test_path_ + "/OPTIONS_test";
|
|
|
|
Options opt = GetDefaultOptions(kCompactionStyleUniversal, 12);
|
|
|
|
ASSERT_OK(PersistRocksDBOptions(WriteOptions(), DBOptions(opt), {"default"},
|
|
{ColumnFamilyOptions(opt)}, kOptionsFileName,
|
|
opt.env->GetFileSystem().get()));
|
|
|
|
// override the following options as db_bench will not take these
|
|
// options from the options file
|
|
opt.wal_dir = wal_path_;
|
|
|
|
RunDbBench(kOptionsFileName);
|
|
VerifyOptions(opt);
|
|
}
|
|
|
|
const std::string options_file_content = R"OPTIONS_FILE(
|
|
[Version]
|
|
rocksdb_version=4.3.1
|
|
options_file_version=1.1
|
|
|
|
[DBOptions]
|
|
wal_bytes_per_sync=1048576
|
|
delete_obsolete_files_period_micros=0
|
|
WAL_ttl_seconds=0
|
|
WAL_size_limit_MB=0
|
|
db_write_buffer_size=0
|
|
max_subcompactions=1
|
|
table_cache_numshardbits=4
|
|
max_open_files=-1
|
|
max_file_opening_threads=10
|
|
max_background_compactions=5
|
|
use_fsync=false
|
|
use_adaptive_mutex=false
|
|
max_total_wal_size=18446744073709551615
|
|
compaction_readahead_size=0
|
|
keep_log_file_num=10
|
|
skip_stats_update_on_db_open=false
|
|
max_manifest_file_size=18446744073709551615
|
|
db_log_dir=
|
|
writable_file_max_buffer_size=1048576
|
|
paranoid_checks=true
|
|
is_fd_close_on_exec=true
|
|
bytes_per_sync=1048576
|
|
enable_thread_tracking=true
|
|
recycle_log_file_num=0
|
|
create_missing_column_families=false
|
|
log_file_time_to_roll=0
|
|
max_background_flushes=1
|
|
create_if_missing=true
|
|
error_if_exists=false
|
|
delayed_write_rate=1048576
|
|
manifest_preallocation_size=4194304
|
|
allow_mmap_reads=false
|
|
allow_mmap_writes=false
|
|
use_direct_reads=false
|
|
use_direct_io_for_flush_and_compaction=false
|
|
stats_dump_period_sec=600
|
|
allow_fallocate=true
|
|
max_log_file_size=83886080
|
|
random_access_max_buffer_size=1048576
|
|
advise_random_on_open=true
|
|
dump_malloc_stats=true
|
|
|
|
[CFOptions "default"]
|
|
compaction_filter_factory=nullptr
|
|
table_factory=BlockBasedTable
|
|
prefix_extractor=nullptr
|
|
comparator=leveldb.BytewiseComparator
|
|
compression_per_level=
|
|
max_bytes_for_level_base=104857600
|
|
bloom_locality=0
|
|
target_file_size_base=10485760
|
|
memtable_huge_page_size=0
|
|
max_successive_merges=1000
|
|
max_sequential_skip_in_iterations=8
|
|
arena_block_size=52428800
|
|
target_file_size_multiplier=1
|
|
source_compaction_factor=1
|
|
min_write_buffer_number_to_merge=1
|
|
max_write_buffer_number=2
|
|
write_buffer_size=419430400
|
|
max_grandparent_overlap_factor=10
|
|
max_bytes_for_level_multiplier=10
|
|
memtable_factory=SkipListFactory
|
|
compression=kNoCompression
|
|
min_partial_merge_operands=2
|
|
level0_stop_writes_trigger=100
|
|
num_levels=1
|
|
level0_slowdown_writes_trigger=50
|
|
level0_file_num_compaction_trigger=10
|
|
expanded_compaction_factor=25
|
|
max_write_buffer_number_to_maintain=0
|
|
max_write_buffer_size_to_maintain=0
|
|
verify_checksums_in_compaction=true
|
|
merge_operator=nullptr
|
|
memtable_prefix_bloom_bits=0
|
|
memtable_whole_key_filtering=true
|
|
paranoid_file_checks=false
|
|
inplace_update_num_locks=10000
|
|
optimize_filters_for_hits=false
|
|
level_compaction_dynamic_level_bytes=false
|
|
inplace_update_support=false
|
|
compaction_style=kCompactionStyleUniversal
|
|
memtable_prefix_bloom_probes=6
|
|
filter_deletes=false
|
|
hard_pending_compaction_bytes_limit=0
|
|
disable_auto_compactions=false
|
|
compaction_measure_io_stats=false
|
|
enable_blob_files=true
|
|
min_blob_size=16
|
|
blob_file_size=10485760
|
|
blob_compression_type=kNoCompression
|
|
enable_blob_garbage_collection=true
|
|
blob_garbage_collection_age_cutoff=0.5
|
|
blob_garbage_collection_force_threshold=0.75
|
|
blob_compaction_readahead_size=262144
|
|
blob_file_starting_level=0
|
|
prepopulate_blob_cache=kDisable;
|
|
|
|
[TableOptions/BlockBasedTable "default"]
|
|
format_version=0
|
|
skip_table_builder_flush=false
|
|
cache_index_and_filter_blocks=false
|
|
flush_block_policy_factory=FlushBlockBySizePolicyFactory
|
|
index_type=kBinarySearch
|
|
whole_key_filtering=true
|
|
checksum=kCRC32c
|
|
no_block_cache=false
|
|
block_size=32768
|
|
block_size_deviation=10
|
|
block_restart_interval=16
|
|
filter_policy=rocksdb.BuiltinBloomFilter
|
|
)OPTIONS_FILE";
|
|
|
|
TEST_F(DBBenchTest, OptionsFileFromFile) {
|
|
const std::string kOptionsFileName = test_path_ + "/OPTIONS_flash";
|
|
std::unique_ptr<WritableFile> writable;
|
|
ASSERT_OK(Env::Default()->NewWritableFile(kOptionsFileName, &writable,
|
|
EnvOptions()));
|
|
ASSERT_OK(writable->Append(options_file_content));
|
|
ASSERT_OK(writable->Close());
|
|
|
|
DBOptions db_opt;
|
|
ConfigOptions config_opt;
|
|
config_opt.ignore_unknown_options = false;
|
|
config_opt.input_strings_escaped = true;
|
|
config_opt.env = Env::Default();
|
|
std::vector<ColumnFamilyDescriptor> cf_descs;
|
|
ASSERT_OK(
|
|
LoadOptionsFromFile(config_opt, kOptionsFileName, &db_opt, &cf_descs));
|
|
Options opt(db_opt, cf_descs[0].options);
|
|
opt.create_if_missing = true;
|
|
|
|
// override the following options as db_bench will not take these
|
|
// options from the options file
|
|
opt.wal_dir = wal_path_;
|
|
|
|
RunDbBench(kOptionsFileName);
|
|
|
|
VerifyOptions(SanitizeOptions(db_path_, opt));
|
|
}
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
|
|
|
int main(int argc, char** argv) {
|
|
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
|
|
return RUN_ALL_TESTS();
|
|
}
|
|
|
|
#else
|
|
|
|
int main(int argc, char** argv) {
|
|
printf("Skip db_bench_tool_test as the required library GFLAG is missing.");
|
|
}
|
|
#endif // #ifdef GFLAGS
|