From 5d0074c471c6ff9a7d8c5330d02b9e6557504e5c Mon Sep 17 00:00:00 2001 From: Lei Jin Date: Tue, 12 Aug 2014 16:42:18 -0700 Subject: [PATCH] set bytes_per_sync to 1MB if rate limiter is enabled Summary: as title Test Plan: make all check Reviewers: igor, yhchiang, sdong Reviewed By: sdong Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D21201 --- db/db_impl.cc | 6 ++++++ include/rocksdb/options.h | 17 +++++++++++------ util/options.cc | 10 ++++++---- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index eaa26de36..4b5200390 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -271,6 +271,12 @@ DBOptions SanitizeOptions(const std::string& dbname, const DBOptions& src) { } } + if (!result.rate_limiter) { + if (result.bytes_per_sync == 0) { + result.bytes_per_sync = 1024 * 1024; + } + } + if (result.wal_dir.empty()) { // Use dbname as default result.wal_dir = dbname; diff --git a/include/rocksdb/options.h b/include/rocksdb/options.h index 5a82c574c..ef7972489 100644 --- a/include/rocksdb/options.h +++ b/include/rocksdb/options.h @@ -636,6 +636,7 @@ struct DBOptions { // Use to control write rate of flush and compaction. Flush has higher // priority than compaction. Rate limiting is disabled if nullptr. + // If rate limiter is enabled, bytes_per_sync is set to 1MB by default. // Default: nullptr std::shared_ptr rate_limiter; @@ -857,12 +858,6 @@ struct DBOptions { // Default: false bool use_adaptive_mutex; - // Allows OS to incrementally sync files to disk while they are being - // written, asynchronously, in the background. - // Issue one request for every bytes_per_sync written. 0 turns it off. - // Default: 0 - uint64_t bytes_per_sync; - // Allow RocksDB to use thread local storage to optimize performance. // Default: true bool allow_thread_local; @@ -873,6 +868,16 @@ struct DBOptions { explicit DBOptions(const Options& options); void Dump(Logger* log) const; + + // Allows OS to incrementally sync files to disk while they are being + // written, asynchronously, in the background. + // Issue one request for every bytes_per_sync written. 0 turns it off. + // Default: 0 + // + // You may consider using rate_limiter to regulate write rate to device. + // When rate limiter is enabled, it automatically enables bytes_per_sync + // to 1MB. + uint64_t bytes_per_sync; }; // Options to control the behavior of a database (passed to DB::Open) diff --git a/util/options.cc b/util/options.cc index 1bc5a01d9..89061b97f 100644 --- a/util/options.cc +++ b/util/options.cc @@ -199,8 +199,8 @@ DBOptions::DBOptions() advise_random_on_open(true), access_hint_on_compaction_start(NORMAL), use_adaptive_mutex(false), - bytes_per_sync(0), - allow_thread_local(true) {} + allow_thread_local(true), + bytes_per_sync(0) {} DBOptions::DBOptions(const Options& options) : create_if_missing(options.create_if_missing), @@ -243,8 +243,8 @@ DBOptions::DBOptions(const Options& options) advise_random_on_open(options.advise_random_on_open), access_hint_on_compaction_start(options.access_hint_on_compaction_start), use_adaptive_mutex(options.use_adaptive_mutex), - bytes_per_sync(options.bytes_per_sync), - allow_thread_local(options.allow_thread_local) {} + allow_thread_local(options.allow_thread_local), + bytes_per_sync(options.bytes_per_sync) {} static const char* const access_hints[] = { "NONE", "NORMAL", "SEQUENTIAL", "WILLNEED" @@ -308,6 +308,8 @@ void DBOptions::Dump(Logger* log) const { access_hints[access_hint_on_compaction_start]); Log(log, " Options.use_adaptive_mutex: %d", use_adaptive_mutex); + Log(log, " Options.rate_limiter: %p", + rate_limiter.get()); Log(log, " Options.bytes_per_sync: %lu", (unsigned long)bytes_per_sync); } // DBOptions::Dump -- GitLab