measureDurationAndLog wip 2

This commit is contained in:
Valentin Balaschenko
2025-05-22 17:49:52 +01:00
parent 8a5f95c223
commit aa14097b02
4 changed files with 70 additions and 29 deletions

View File

@@ -37,6 +37,7 @@
#include <xrpld/consensus/LedgerTiming.h>
#include <xrpld/overlay/Overlay.h>
#include <xrpld/overlay/predicates.h>
#include <xrpld/perflog/PerfLog.h>
#include <xrpl/basics/random.h>
#include <xrpl/beast/core/LexicalCast.h>
@@ -49,6 +50,8 @@
#include <iomanip>
#include <mutex>
using namespace std::chrono_literals;
namespace ripple {
RCLConsensus::RCLConsensus(
@@ -140,11 +143,17 @@ RCLConsensus::Adaptor::acquireLedger(LedgerHash const& hash)
app_.getJobQueue().addJob(
jtADVANCE,
"getConsensusLedger1",
[id = hash, &app = app_, this]() {
JLOG(j_.debug())
<< "JOB advanceLedger getConsensusLedger1 started";
app.getInboundLedgers().acquireAsync(
id, 0, InboundLedger::Reason::CONSENSUS);
[id = hash, &app = app_, this, journal = j_]() {
perf::measureDurationAndLog(
[&]() {
JLOG(j_.debug()) << "JOB advanceLedger "
"getConsensusLedger1 started";
app.getInboundLedgers().acquireAsync(
id, 0, InboundLedger::Reason::CONSENSUS);
},
"getConsensusLedger1",
1s,
journal);
});
}
return std::nullopt;
@@ -442,21 +451,27 @@ RCLConsensus::Adaptor::onAccept(
app_.getJobQueue().addJob(
jtACCEPT,
"acceptLedger",
[=, this, cj = std::move(consensusJson)]() mutable {
// Note that no lock is held or acquired during this job.
// This is because generic Consensus guarantees that once a ledger
// is accepted, the consensus results and capture by reference state
// will not change until startRound is called (which happens via
// endConsensus).
RclConsensusLogger clog("onAccept", validating, j_);
this->doAccept(
result,
prevLedger,
closeResolution,
rawCloseTimes,
mode,
std::move(cj));
this->app_.getOPs().endConsensus(clog.ss());
[=, this, cj = std::move(consensusJson), journal = j_]() mutable {
perf::measureDurationAndLog(
[&]() {
// Note that no lock is held or acquired during this job.
// This is because generic Consensus guarantees that once a
// ledger is accepted, the consensus results and capture by
// reference state will not change until startRound is
// called (which happens via endConsensus).
RclConsensusLogger clog("onAccept", validating, j_);
this->doAccept(
result,
prevLedger,
closeResolution,
rawCloseTimes,
mode,
std::move(cj));
this->app_.getOPs().endConsensus(clog.ss());
},
"acceptLedger",
1s,
journal);
});
}

View File

@@ -32,6 +32,8 @@
#include <memory>
using namespace std::chrono_literals;
namespace ripple {
RCLValidatedLedger::RCLValidatedLedger(MakeGenesis)
@@ -142,11 +144,19 @@ RCLValidationsAdaptor::acquire(LedgerHash const& hash)
Application* pApp = &app_;
app_.getJobQueue().addJob(
jtADVANCE, "getConsensusLedger2", [pApp, hash, this]() {
JLOG(j_.debug())
<< "JOB advanceLedger getConsensusLedger2 started";
pApp->getInboundLedgers().acquireAsync(
hash, 0, InboundLedger::Reason::CONSENSUS);
jtADVANCE,
"getConsensusLedger2",
[pApp, hash, this, journal = j_]() {
perf::measureDurationAndLog(
[&]() {
JLOG(j_.debug())
<< "JOB advanceLedger getConsensusLedger2 started";
pApp->getInboundLedgers().acquireAsync(
hash, 0, InboundLedger::Reason::CONSENSUS);
},
"getConsensusLedger2",
1s,
journal);
});
return std::nullopt;
}

View File

@@ -23,11 +23,14 @@
#include <xrpld/app/misc/Transaction.h>
#include <xrpld/core/JobQueue.h>
#include <xrpld/nodestore/Database.h>
#include <xrpld/perflog/PerfLog.h>
#include <xrpl/basics/Log.h>
#include <xrpl/protocol/HashPrefix.h>
#include <xrpl/protocol/digest.h>
using namespace std::chrono_literals;
namespace ripple {
ConsensusTransSetSF::ConsensusTransSetSF(Application& app, NodeCache& nodeCache)
@@ -65,9 +68,14 @@ ConsensusTransSetSF::gotNode(
"ripple::ConsensusTransSetSF::gotNode : transaction hash "
"match");
auto const pap = &app_;
app_.getJobQueue().addJob(jtTRANSACTION, "TXS->TXN", [pap, stx]() {
pap->getOPs().submitTransaction(stx);
});
app_.getJobQueue().addJob(
jtTRANSACTION, "TXS->TXN", [pap, stx, journal = j_]() {
perf::measureDurationAndLog(
[&]() { pap->getOPs().submitTransaction(stx); },
"TXS->TXN",
1s,
journal);
});
}
catch (std::exception const& ex)
{

View File

@@ -30,6 +30,7 @@
#include <xrpld/core/SociDB.h>
#include <xrpld/nodestore/Database.h>
#include <xrpld/nodestore/detail/DatabaseNodeImp.h>
#include <xrpld/perflog/PerfLog.h>
#include <xrpl/basics/Log.h>
#include <xrpl/basics/contract.h>
@@ -46,6 +47,8 @@
#include <utility>
#include <vector>
using namespace std::chrono_literals;
namespace ripple {
create_genesis_t const create_genesis{};
@@ -1028,7 +1031,12 @@ pendSaveValidated(
isCurrent ? jtPUBLEDGER : jtPUBOLDLEDGER,
std::to_string(ledger->seq()),
[&app, ledger, isCurrent]() {
saveValidatedLedger(app, ledger, isCurrent);
beast::Journal journal = app.journal("Ledger");
perf::measureDurationAndLog(
[&]() { saveValidatedLedger(app, ledger, isCurrent); },
"OrderBookDB::update:",
1s,
journal);
}))
{
return true;