Skip to content
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

emit warning if bl merge slower than 50 seconds #4345

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/bucket/FutureBucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,10 @@ FutureBucket::startMerge(Application& app, uint32_t maxProtocolVersion,
std::shared_ptr<task_t> task = std::make_shared<task_t>(
[curr, snap, &bm, shadows, maxProtocolVersion, countMergeEvents, level,
&timer, &ctx, doFsync, availableTime]() mutable {
auto timeScope = timer.TimeScope();
auto timeScope = LogSlowExecution(
"Bucket merge", LogSlowExecution::Mode::AUTOMATIC_RAII, "took",
std::chrono::seconds(120), /*warnOnThreshold=*/true,
/*logEveryExecution=*/true);
CLOG_TRACE(Bucket, "Worker merging curr={} with snap={}",
hexAbbrev(curr->getHash()), hexAbbrev(snap->getHash()));

Expand All @@ -372,14 +375,6 @@ FutureBucket::startMerge(Application& app, uint32_t maxProtocolVersion,
CLOG_TRACE(
Bucket, "Worker finished merging curr={} with snap={}",
hexAbbrev(curr->getHash()), hexAbbrev(snap->getHash()));

std::chrono::duration<double> time(timeScope.Stop());
double timePct = time.count() / availableTime.count() * 100;
CLOG_DEBUG(
Perf,
"Bucket merge on level {} finished in {} seconds "
"({}% of available time)",
level, time.count(), timePct);
}

return res;
Expand Down
15 changes: 10 additions & 5 deletions src/util/LogSlowExecution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ namespace stellar
{
LogSlowExecution::LogSlowExecution(std::string eventName, Mode mode,
std::string message,
std::chrono::milliseconds threshold)
std::chrono::milliseconds threshold,
bool warnOnThreshold, bool logEveryExecution)
: mStart(std::chrono::system_clock::now())
, mName(std::move(eventName))
, mMode(mode)
, mMessage(std::move(message))
, mThreshold(threshold){};
, mThreshold(threshold)
, mWarnOnThreshold(warnOnThreshold)
, mLogEveryExecution(logEveryExecution){};

LogSlowExecution::~LogSlowExecution()
{
Expand All @@ -44,13 +47,15 @@ LogSlowExecution::checkElapsedTime() const
auto elapsed =
std::chrono::duration_cast<std::chrono::milliseconds>(finish - mStart);

if (!mThreshold.count() || elapsed > mThreshold)
if (!mThreshold.count() || elapsed > mThreshold || mLogEveryExecution)
{
std::lock_guard<std::mutex> guard(gLogSlowExecMutex);

// Check whether we're 10 times over the threshold to decide the log
// level.
LogLevel ll = (elapsed > mThreshold * 10 || !mThreshold.count())
// level. If warnOnThreshold is set, log as warning if we're over the
// threshold.
LogLevel ll = (elapsed > mThreshold * 10 || !mThreshold.count() ||
(elapsed > mThreshold && mWarnOnThreshold))
? LogLevel::LVL_WARNING
: LogLevel::LVL_DEBUG;

Expand Down
5 changes: 4 additions & 1 deletion src/util/LogSlowExecution.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class LogSlowExecution
LogSlowExecution(
std::string eventName, Mode mode = Mode::AUTOMATIC_RAII,
std::string message = "took",
std::chrono::milliseconds threshold = std::chrono::seconds(1));
std::chrono::milliseconds threshold = std::chrono::seconds(1),
bool warnOnThreshold = false, bool logEveryExecution = false);
~LogSlowExecution();
std::chrono::milliseconds checkElapsedTime() const;

Expand All @@ -32,6 +33,8 @@ class LogSlowExecution
Mode mMode;
std::string mMessage;
std::chrono::milliseconds mThreshold;
bool mWarnOnThreshold;
bool mLogEveryExecution;
};

// Helper class to emit rate-limited log messages without any threshold
Expand Down
Loading