From fbda5ccc155e1adaee9b12bdd445bdccf585b679 Mon Sep 17 00:00:00 2001 From: Valentin Balaschenko <13349202+vlntb@users.noreply.github.com> Date: Thu, 22 May 2025 17:16:38 +0100 Subject: [PATCH] Ledger master duration --- src/xrpld/app/ledger/detail/LedgerMaster.cpp | 76 +++++++++++++------ .../app/ledger/detail/TimeoutCounter.cpp | 15 +++- .../app/ledger/detail/TransactionAcquire.cpp | 13 +++- 3 files changed, 75 insertions(+), 29 deletions(-) diff --git a/src/xrpld/app/ledger/detail/LedgerMaster.cpp b/src/xrpld/app/ledger/detail/LedgerMaster.cpp index 78f0375b16..3bef6cb453 100644 --- a/src/xrpld/app/ledger/detail/LedgerMaster.cpp +++ b/src/xrpld/app/ledger/detail/LedgerMaster.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -56,6 +57,8 @@ #include #include +using namespace std::chrono_literals; + namespace ripple { // Don't catch up more than 100 ledgers (cannot exceed 256) @@ -1361,27 +1364,36 @@ LedgerMaster::tryAdvance() if (!mAdvanceThread && !mValidLedger.empty()) { mAdvanceThread = true; - app_.getJobQueue().addJob(jtADVANCE, "advanceLedger", [this]() { - std::unique_lock sl(m_mutex); + app_.getJobQueue().addJob( + jtADVANCE, "advanceLedger", [this, journal = m_journal]() { + perf::measureDurationAndLog( + [&]() { + std::unique_lock sl(m_mutex); - XRPL_ASSERT( - !mValidLedger.empty() && mAdvanceThread, - "ripple::LedgerMaster::tryAdvance : has valid ledger"); + XRPL_ASSERT( + !mValidLedger.empty() && mAdvanceThread, + "ripple::LedgerMaster::tryAdvance : has valid " + "ledger"); - JLOG(m_journal.trace()) << "advanceThread<"; + JLOG(m_journal.trace()) << "advanceThread<"; - try - { - doAdvance(sl); - } - catch (std::exception const& ex) - { - JLOG(m_journal.fatal()) << "doAdvance throws: " << ex.what(); - } + try + { + doAdvance(sl); + } + catch (std::exception const& ex) + { + JLOG(m_journal.fatal()) + << "doAdvance throws: " << ex.what(); + } - mAdvanceThread = false; - JLOG(m_journal.trace()) << "advanceThread>"; - }); + mAdvanceThread = false; + JLOG(m_journal.trace()) << "advanceThread>"; + }, + "advanceLedger", + 1s, + journal); + }); } } @@ -1536,7 +1548,13 @@ LedgerMaster::newPFWork( << "newPFWork: Creating job. path find threads: " << mPathFindThread; if (app_.getJobQueue().addJob( - jtUPDATE_PF, name, [this]() { updatePaths(); })) + jtUPDATE_PF, name, [this, journal = m_journal]() { + perf::measureDurationAndLog( + [&]() { updatePaths(); }, + "newPFWork: Creating job. path find threads:", + 1s, + journal); + })) { ++mPathFindThread; } @@ -1857,8 +1875,11 @@ LedgerMaster::fetchForHistory( mFillInProgress = seq; } app_.getJobQueue().addJob( - jtADVANCE, "tryFill", [this, ledger]() { - tryFill(ledger); + jtADVANCE, + "tryFill", + [this, ledger, journal = m_journal]() { + perf::measureDurationAndLog( + [&]() { tryFill(ledger); }, "tryFill", 1s, journal); }); } progress = true; @@ -2027,10 +2048,17 @@ LedgerMaster::gotFetchPack(bool progress, std::uint32_t seq) { if (!mGotFetchPackThread.test_and_set(std::memory_order_acquire)) { - app_.getJobQueue().addJob(jtLEDGER_DATA, "gotFetchPack", [&]() { - app_.getInboundLedgers().gotFetchPack(); - mGotFetchPackThread.clear(std::memory_order_release); - }); + app_.getJobQueue().addJob( + jtLEDGER_DATA, "gotFetchPack", [this, journal = m_journal]() { + perf::measureDurationAndLog( + [&]() { + app_.getInboundLedgers().gotFetchPack(); + mGotFetchPackThread.clear(std::memory_order_release); + }, + "gotFetchPack", + 1s, + journal); + }); } } diff --git a/src/xrpld/app/ledger/detail/TimeoutCounter.cpp b/src/xrpld/app/ledger/detail/TimeoutCounter.cpp index e81ec6574d..3e96d52523 100644 --- a/src/xrpld/app/ledger/detail/TimeoutCounter.cpp +++ b/src/xrpld/app/ledger/detail/TimeoutCounter.cpp @@ -19,6 +19,9 @@ #include #include +#include + +using namespace std::chrono_literals; namespace ripple { @@ -83,9 +86,15 @@ TimeoutCounter::queueJob(ScopedLockType& sl) app_.getJobQueue().addJob( queueJobParameter_.jobType, queueJobParameter_.jobName, - [wptr = pmDowncast()]() { - if (auto sptr = wptr.lock(); sptr) - sptr->invokeOnTimer(); + [wptr = pmDowncast(), journal = journal_]() { + perf::measureDurationAndLog( + [&]() { + if (auto sptr = wptr.lock(); sptr) + sptr->invokeOnTimer(); + }, + "TimeoutCounter::queueJob", + 1s, + journal); }); } diff --git a/src/xrpld/app/ledger/detail/TransactionAcquire.cpp b/src/xrpld/app/ledger/detail/TransactionAcquire.cpp index 23694b3cb6..b365f1a19e 100644 --- a/src/xrpld/app/ledger/detail/TransactionAcquire.cpp +++ b/src/xrpld/app/ledger/detail/TransactionAcquire.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -79,8 +80,16 @@ TransactionAcquire::done() // just updates the consensus and related structures when we acquire // a transaction set. No need to update them if we're shutting down. app_.getJobQueue().addJob( - jtTXN_DATA, "completeAcquire", [pap, hash, map]() { - pap->getInboundTransactions().giveSet(hash, map, true); + jtTXN_DATA, + "completeAcquire", + [pap, hash, map, journal = journal_]() { + perf::measureDurationAndLog( + [&]() { + pap->getInboundTransactions().giveSet(hash, map, true); + }, + "completeAcquire", + 1s, + journal); }); } }