-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Address performance issues reported with 1.9.0 #4152
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,8 @@ Database::Database( | |
, earliestLedgerSeq_( | ||
get<std::uint32_t>(config, "earliest_seq", XRP_LEDGER_EARLIEST_SEQ)) | ||
, earliestShardIndex_((earliestLedgerSeq_ - 1) / ledgersPerShard_) | ||
, readThreads_(std::min(1, readThreads)) | ||
, requestBundle_(get<int>(config, "rq_bundle", 4)) | ||
, readThreads_(std::max(1, readThreads)) | ||
{ | ||
assert(readThreads != 0); | ||
|
||
|
@@ -53,10 +54,15 @@ Database::Database( | |
if (earliestLedgerSeq_ < 1) | ||
Throw<std::runtime_error>("Invalid earliest_seq"); | ||
|
||
for (int i = 0; i != readThreads_.load(); ++i) | ||
if (requestBundle_ < 1 || requestBundle_ > 64) | ||
Throw<std::runtime_error>("Invalid rq_bundle"); | ||
|
||
for (int i = readThreads_.load(); i != 0; --i) | ||
{ | ||
std::thread t( | ||
[this](int i) { | ||
runningThreads_++; | ||
|
||
beast::setCurrentThreadName( | ||
"db prefetch #" + std::to_string(i)); | ||
|
||
|
@@ -68,14 +74,20 @@ Database::Database( | |
std::unique_lock<std::mutex> lock(readLock_); | ||
|
||
if (read_.empty()) | ||
{ | ||
runningThreads_--; | ||
readCondVar_.wait(lock); | ||
runningThreads_++; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I see a potential deadlock. Suppose one of the threads is interrupted right after checking When the thread resumes, it will wait forever on This could be addressed by checking |
||
|
||
if (isStopping()) | ||
continue; | ||
|
||
// We extract up to 64 objects to minimize the overhead | ||
// of acquiring the mutex. | ||
for (int cnt = 0; !read_.empty() && cnt != 64; ++cnt) | ||
// If configured, extract multiple object at a time to | ||
// minimize the overhead of acquiring the mutex. | ||
for (int cnt = 0; | ||
!read_.empty() && cnt != requestBundle_; | ||
++cnt) | ||
read.insert(read_.extract(read_.begin())); | ||
} | ||
|
||
|
@@ -84,7 +96,7 @@ Database::Database( | |
assert(!it->second.empty()); | ||
|
||
auto const& hash = it->first; | ||
auto const& data = std::move(it->second); | ||
auto const& data = it->second; | ||
auto const seqn = data[0].first; | ||
|
||
auto obj = | ||
|
@@ -340,6 +352,16 @@ void | |
Database::getCountsJson(Json::Value& obj) | ||
{ | ||
assert(obj.isObject()); | ||
|
||
{ | ||
std::unique_lock<std::mutex> lock(readLock_); | ||
obj["read_queue"] = static_cast<Json::UInt>(read_.size()); | ||
} | ||
|
||
obj["read_threads_total"] = readThreads_.load(); | ||
obj["read_threads_running"] = runningThreads_.load(); | ||
obj["read_request_bundle"] = requestBundle_; | ||
|
||
obj[jss::node_writes] = std::to_string(storeCount_); | ||
obj[jss::node_reads_total] = std::to_string(fetchTotalCount_); | ||
obj[jss::node_reads_hit] = std::to_string(fetchHitCount_); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.