Skip to content

Commit b024755

Browse files
committed
Clean up e2e measurement
1 parent 1b628ab commit b024755

3 files changed

Lines changed: 26 additions & 40 deletions

File tree

src/ledger/LedgerManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,11 @@ class LedgerManager
302302

303303
// Records the submission time of a self-submitted transaction for the
304304
// tx-latency metrics. No-op unless
305-
// Config::LOADGEN_MEASURE_TX_LATENCY_FOR_TESTING is set.
305+
// Config::LOADGEN_MEASURE_TX_E2E_LATENCY_FOR_TESTING is set.
306306
virtual void recordTxSubmission(Hash const& contentsHash) = 0;
307307

308308
// Begins/ends a load-generation latency measurement window. No-op unless
309-
// Config::LOADGEN_MEASURE_TX_LATENCY_FOR_TESTING is set.
309+
// Config::LOADGEN_MEASURE_TX_E2E_LATENCY_FOR_TESTING is set.
310310
virtual void beginTxLatencyMeasurement(uint32_t expectedTxCount) = 0;
311311
virtual void finalizeTxLatencyMeasurement() = 0;
312312
#endif

src/ledger/LedgerManagerImpl.cpp

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,47 +1362,33 @@ LedgerManagerImpl::recordTxSubmission(Hash const& contentsHash)
13621362
}
13631363

13641364
void
1365-
LedgerManagerImpl::recordTxMetaEmissionLatency(LedgerCloseMeta const& lcm)
1365+
LedgerManagerImpl::recordTxE2eLatency(ApplicableTxSetFrame const& txSet)
13661366
{
13671367
if (!mApp.getConfig().LOADGEN_MEASURE_TX_E2E_LATENCY_FOR_TESTING)
13681368
{
13691369
return;
13701370
}
1371-
VirtualClock::time_point const emitTime = mApp.getClock().now();
1371+
VirtualClock::time_point const applyEndTime = mApp.getClock().now();
13721372
MutexLocker guard(mTxLatencyMetrics.mMutex);
1373-
auto probe =
1374-
[&](auto const& txProcessing) REQUIRES(mTxLatencyMetrics.mMutex) {
1375-
for (auto const& txp : txProcessing)
1373+
for (auto const& phase : txSet.getPhases())
1374+
{
1375+
for (auto const& tx : phase)
1376+
{
1377+
if (auto submitted = mTxLatencyMetrics.mTxSubmitTimes.find(
1378+
tx->getContentsHash());
1379+
submitted != mTxLatencyMetrics.mTxSubmitTimes.end())
13761380
{
1377-
if (auto submitted = mTxLatencyMetrics.mTxSubmitTimes.find(
1378-
txp.result.transactionHash);
1379-
submitted != mTxLatencyMetrics.mTxSubmitTimes.end())
1380-
{
1381-
auto const latency = emitTime - submitted->second;
1382-
mTxLatencyMetrics.mTxsExternalized.inc();
1383-
int64_t const ms =
1384-
std::chrono::duration_cast<std::chrono::milliseconds>(
1385-
latency)
1386-
.count();
1387-
mTxLatencyMetrics.mSamples.push_back(std::clamp<int64_t>(
1388-
ms, 0, std::numeric_limits<uint32_t>::max()));
1389-
mTxLatencyMetrics.mTxSubmitTimes.erase(submitted);
1390-
}
1381+
auto const latency = applyEndTime - submitted->second;
1382+
mTxLatencyMetrics.mTxsExternalized.inc();
1383+
int64_t const ms =
1384+
std::chrono::duration_cast<std::chrono::milliseconds>(
1385+
latency)
1386+
.count();
1387+
mTxLatencyMetrics.mSamples.push_back(std::clamp<int64_t>(
1388+
ms, 0, std::numeric_limits<uint32_t>::max()));
1389+
mTxLatencyMetrics.mTxSubmitTimes.erase(submitted);
13911390
}
1392-
};
1393-
switch (lcm.v())
1394-
{
1395-
case 0:
1396-
probe(lcm.v0().txProcessing);
1397-
break;
1398-
case 1:
1399-
probe(lcm.v1().txProcessing);
1400-
break;
1401-
case 2:
1402-
probe(lcm.v2().txProcessing);
1403-
break;
1404-
default:
1405-
releaseAssert(false);
1391+
}
14061392
}
14071393
}
14081394

@@ -1941,7 +1927,6 @@ LedgerManagerImpl::applyLedger(LedgerCloseData const& ledgerData,
19411927
appliedLedgerState->getLastClosedLedgerHeader();
19421928
// Copy this before we move it into mNextMetaToEmit below
19431929
mLastLedgerCloseMeta = *ledgerCloseMeta;
1944-
recordTxMetaEmissionLatency(ledgerCloseMeta->getXDR());
19451930
}
19461931
#endif
19471932

@@ -2046,6 +2031,7 @@ LedgerManagerImpl::applyLedger(LedgerCloseData const& ledgerData,
20462031
#ifdef BUILD_TESTS
20472032
maybeSimulateSleep(mApp.getConfig(), txSet->sizeOpTotalForLogging(),
20482033
applyLedgerTime, mApplySleepRng);
2034+
recordTxE2eLatency(*applicableTxSet);
20492035
#endif
20502036

20512037
// Steps 6, 7, 8 are done in `advanceLedgerStateAndPublish`

src/ledger/LedgerManagerImpl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,15 +451,15 @@ class LedgerManagerImpl : public LedgerManager
451451
ANNOTATED_MUTEX(mMutex);
452452
UnorderedMap<Hash, VirtualClock::time_point>
453453
mTxSubmitTimes GUARDED_BY(mMutex);
454-
// Each recorded submission -> meta-emission latency in ms
454+
// Each recorded submission -> post-apply latency in ms
455455
std::vector<uint32_t> mSamples GUARDED_BY(mMutex);
456456

457457
TxLatencyMetrics(MetricsRegistry& registry);
458458
} mTxLatencyMetrics;
459459

460-
// End point of the tx-latency metric: matches the ledger-close meta's
461-
// txProcessing entries against mTxSubmitTimes and records each latency.
462-
void recordTxMetaEmissionLatency(LedgerCloseMeta const& lcm);
460+
// End point of the tx-latency metric: records the submission to post-apply
461+
// latency for each externalized transaction.
462+
void recordTxE2eLatency(ApplicableTxSetFrame const& txSet);
463463
#endif
464464

465465
void setState(State s);

0 commit comments

Comments
 (0)