Pre-calculate whether to slow down for too many level 0 files
Summary: Currently in DBImpl::MakeRoomForWrite(), we do "versions_->NumLevelFiles(0) >= options_.level0_slowdown_writes_trigger" to check whether the writer thread needs to slow down. However, versions_->NumLevelFiles(0) is slightly more expensive than we expected. By caching the result of the comparison when installing a new version, we can avoid this function call every time. Test Plan: make all check Manually trigger this behavior by applying universal compaction style and make sure inserts are made slow after there are certain number of files. Reviewers: haobo, kailiu, igor Reviewed By: kailiu CC: nkg-, leveldb Differential Revision: https://reviews.facebook.net/D15141
This commit is contained in:
parent
51dd21926c
commit
fbbf0d1456
@ -3166,8 +3166,7 @@ Status DBImpl::MakeRoomForWrite(bool force,
|
|||||||
break;
|
break;
|
||||||
} else if (
|
} else if (
|
||||||
allow_delay &&
|
allow_delay &&
|
||||||
versions_->NumLevelFiles(0) >=
|
versions_->NeedSlowdownForNumLevel0Files()) {
|
||||||
options_.level0_slowdown_writes_trigger) {
|
|
||||||
// We are getting close to hitting a hard limit on the number of
|
// We are getting close to hitting a hard limit on the number of
|
||||||
// L0 files. Rather than delaying a single write by several
|
// L0 files. Rather than delaying a single write by several
|
||||||
// seconds when we hit the hard limit, start delaying each
|
// seconds when we hit the hard limit, start delaying each
|
||||||
|
@ -1148,6 +1148,7 @@ VersionSet::VersionSet(const std::string& dbname,
|
|||||||
num_levels_(options_->num_levels),
|
num_levels_(options_->num_levels),
|
||||||
dummy_versions_(this),
|
dummy_versions_(this),
|
||||||
current_(nullptr),
|
current_(nullptr),
|
||||||
|
need_slowdown_for_num_level0_files(false),
|
||||||
compactions_in_progress_(options_->num_levels),
|
compactions_in_progress_(options_->num_levels),
|
||||||
current_version_number_(0),
|
current_version_number_(0),
|
||||||
last_observed_manifest_size_(0),
|
last_observed_manifest_size_(0),
|
||||||
@ -1199,6 +1200,9 @@ void VersionSet::AppendVersion(Version* v) {
|
|||||||
current_->Unref();
|
current_->Unref();
|
||||||
}
|
}
|
||||||
current_ = v;
|
current_ = v;
|
||||||
|
need_slowdown_for_num_level0_files =
|
||||||
|
(options_->level0_slowdown_writes_trigger >= 0 && current_ != nullptr &&
|
||||||
|
NumLevelFiles(0) >= options_->level0_slowdown_writes_trigger);
|
||||||
v->Ref();
|
v->Ref();
|
||||||
|
|
||||||
// Append to linked list
|
// Append to linked list
|
||||||
|
@ -250,6 +250,12 @@ class VersionSet {
|
|||||||
// Return the current version.
|
// Return the current version.
|
||||||
Version* current() const { return current_; }
|
Version* current() const { return current_; }
|
||||||
|
|
||||||
|
// A Flag indicating whether write needs to slowdown because of there are
|
||||||
|
// too many number of level0 files.
|
||||||
|
bool NeedSlowdownForNumLevel0Files() const {
|
||||||
|
return need_slowdown_for_num_level0_files;
|
||||||
|
}
|
||||||
|
|
||||||
// Return the current manifest file number
|
// Return the current manifest file number
|
||||||
uint64_t ManifestFileNumber() const { return manifest_file_number_; }
|
uint64_t ManifestFileNumber() const { return manifest_file_number_; }
|
||||||
|
|
||||||
@ -489,6 +495,8 @@ class VersionSet {
|
|||||||
Version dummy_versions_; // Head of circular doubly-linked list of versions.
|
Version dummy_versions_; // Head of circular doubly-linked list of versions.
|
||||||
Version* current_; // == dummy_versions_.prev_
|
Version* current_; // == dummy_versions_.prev_
|
||||||
|
|
||||||
|
bool need_slowdown_for_num_level0_files;
|
||||||
|
|
||||||
// Per-level key at which the next compaction at that level should start.
|
// Per-level key at which the next compaction at that level should start.
|
||||||
// Either an empty string, or a valid InternalKey.
|
// Either an empty string, or a valid InternalKey.
|
||||||
std::string* compact_pointer_;
|
std::string* compact_pointer_;
|
||||||
|
Loading…
Reference in New Issue
Block a user