Skip to content

Commit 25933b6

Browse files
committed
Add SimpleTimer class and registry for measuring point loads
1 parent af0d3d6 commit 25933b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+332
-157
lines changed

docs/metrics.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ bucketlistDB-live.bulk.eviction | timer | time to load for evictio
4949
bucketlistDB-live.bulk.query | timer | time to load for query server
5050
bucketlistDB-<X>.<Y>.sum | counter | sum of time (microseconds) to load single entry of type <Y> on BucketList <X> (live/hotArchive)
5151
bucketlistDB-<X>.<Y>.count | counter | number of times single entry of type <Y> on BucketList <X> (live/hotArchive) is loaded
52+
bucketlistDB-<X>.<Y>.max | counter | max (since last metrics call) of time (microseconds) to load single entry of type <Y> on BucketList <X> (live/hotArchive)
5253
bucketlistDB-cache.hit | meter | number of cache hits on Live BucketList Disk random eviction cache
5354
bucketlistDB-cache.miss | meter | number of cache misses on Live BucketList Disk random eviction cache
5455
bucketlistDB.cache.entries | counter | number of entries currently in Live BucketList index cache
@@ -65,8 +66,10 @@ herder.pending[-soroban]-txs.age3 | counter | number of gen3 pending t
6566
herder.pending[-soroban]-txs.banned | counter | number of transactions that got banned
6667
herder.pending[-soroban]-txs.sum | counter | sum of time (milliseconds) for transactions to be included in a ledger
6768
herder.pending[-soroban]-txs.count | counter | number of transactions to be included in a ledger
69+
herder.pending[-soroban]-txs.max | counter | largest time (milliseconds) for a transaction to be included in a ledger since last metrics call
6870
herder.pending[-soroban]-txs.self-sum | counter | sum of time (milliseconds) for transactions submitted from this node to be included in a ledger
6971
herder.pending[-soroban]-txs.self-count | counter | number of transactions submitted from this node to be included in a ledger
72+
herder.pending[-soroban]-txs.self-max | counter | largest time (milliseconds) for a transaction submitted from this node to be included in a ledger since last metrics call
7073
herder.pending[-soroban]-txs.evicted-due-to-low-fee-count | counter | Count of transactions evicted by higher fee txs when queue is near its capacity.
7174
herder.pending[-soroban]-txs.evicted-due-to-age-count | counter | Count of transactions that had low fee for too long and have not been included into several ledgers in a row.
7275
herder.pending[-soroban]-txs.not-included-due-to-low-fee-count | counter | Count of transactions that were not included into queue because it is at capacity and the fee is too low to replace other txs.
@@ -163,6 +166,7 @@ overlay.outbound.establish | meter | outbound connection esta
163166
overlay.recv.<X> | timer | received message <X> (except transaction)
164167
overlay.recv-transaction.sum | counter | sum of time (microseconds) to receive transaction message
165168
overlay.recv-transaction.count | counter | number of transaction messages received
169+
overlay.recv-transaction.max | counter | maximum time (microseconds) to receive transaction message since last metrics call
166170
overlay.send.<X> | meter | sent message <X>
167171
overlay.timeout.idle | meter | idle peer timeout
168172
overlay.timeout.straggler | meter | straggler peer timeout
@@ -273,4 +277,4 @@ soroban.module-cache.rebuild-bytes | counter | bytes of WASM bytecod
273277
soroban.in-memory-state.contract-code-size | counter | size in bytes of non-evicted ContractCode entries according to memory cost model
274278
soroban.in-memory-state.contract-data-size | counter | size in bytes of ContractData entries in memory
275279
soroban.in-memory-state.contract-code-entries | counter | number of ContractCode entries in memory
276-
soroban.in-memory-state.contract-data-entries | counter | number of ContractData entries in memory
280+
soroban.in-memory-state.contract-data-entries | counter | number of ContractData entries in memory

src/bucket/BucketListSnapshotBase.cpp

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "main/AppConnector.h"
1111

1212
#include "util/GlobalChecks.h"
13-
#include <medida/metrics_registry.h>
13+
#include "util/MetricsRegistry.h"
1414
#include <optional>
1515
#include <vector>
1616

@@ -89,7 +89,9 @@ SearchableBucketListSnapshotBase<BucketT>::load(LedgerKey const& k) const
8989
ZoneScoped;
9090

9191
std::shared_ptr<typename BucketT::LoadT const> result{};
92-
auto startTime = mAppConnector.now();
92+
auto timerIter = mPointTimers.find(k.type());
93+
releaseAssert(timerIter != mPointTimers.end());
94+
auto timer = timerIter->second.TimeScope();
9395

9496
// Search function called on each Bucket in BucketList until we find the key
9597
auto loadKeyBucketLoop = [&](auto const& b) {
@@ -98,7 +100,7 @@ SearchableBucketListSnapshotBase<BucketT>::load(LedgerKey const& k) const
98100
{
99101
// Reset timer on bloom miss to avoid outlier metrics, since we
100102
// really only want to measure disk performance
101-
startTime = mAppConnector.now();
103+
timer.Reset();
102104
}
103105

104106
if (be)
@@ -113,17 +115,6 @@ SearchableBucketListSnapshotBase<BucketT>::load(LedgerKey const& k) const
113115
};
114116

115117
loopAllBuckets(loadKeyBucketLoop, *mSnapshot);
116-
auto endTime = mAppConnector.now();
117-
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
118-
endTime - startTime);
119-
120-
auto accumulatorIter = mPointAccumulators.find(k.type());
121-
releaseAssert(accumulatorIter != mPointAccumulators.end());
122-
accumulatorIter->second.inc(duration.count());
123-
124-
auto counterIter = mPointCounters.find(k.type());
125-
releaseAssert(counterIter != mPointCounters.end());
126-
counterIter->second.inc();
127118

128119
return result;
129120
}
@@ -200,12 +191,10 @@ SearchableBucketListSnapshotBase<BucketT>::SearchableBucketListSnapshotBase(
200191
{
201192
auto const& label = xdr::xdr_traits<LedgerEntryType>::enum_name(
202193
static_cast<LedgerEntryType>(t));
203-
auto& metric =
204-
app.getMetrics().NewCounter({BucketT::METRIC_STRING, label, "sum"});
205-
mPointAccumulators.emplace(static_cast<LedgerEntryType>(t), metric);
206-
auto& counter = app.getMetrics().NewCounter(
207-
{BucketT::METRIC_STRING, label, "count"});
208-
mPointCounters.emplace(static_cast<LedgerEntryType>(t), counter);
194+
auto& metric = app.getMetrics().NewSimpleTimer(
195+
{BucketT::METRIC_STRING, label, "sum"},
196+
std::chrono::microseconds{1});
197+
mPointTimers.emplace(static_cast<LedgerEntryType>(t), metric);
209198
}
210199
}
211200

@@ -241,4 +230,4 @@ template class BucketListSnapshot<LiveBucket>;
241230
template class BucketListSnapshot<HotArchiveBucket>;
242231
template class SearchableBucketListSnapshotBase<LiveBucket>;
243232
template class SearchableBucketListSnapshotBase<HotArchiveBucket>;
244-
}
233+
}

src/bucket/BucketListSnapshotBase.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "bucket/BucketUtils.h"
1212
#include "bucket/HotArchiveBucket.h"
1313
#include "bucket/LiveBucket.h"
14+
#include "util/SimpleTimer.h"
1415

1516
namespace medida
1617
{
@@ -91,9 +92,8 @@ class SearchableBucketListSnapshotBase : public NonMovableOrCopyable
9192

9293
// Tracks the sum of point load times for each LedgerEntryType, in
9394
// microseconds. For point loads, Timers are too expensive to maintain, so
94-
// we use a Counter to keep track of the total trend instead.
95-
UnorderedMap<LedgerEntryType, medida::Counter&> mPointAccumulators{};
96-
UnorderedMap<LedgerEntryType, medida::Counter&> mPointCounters{};
95+
// we use SimpleTimer.
96+
UnorderedMap<LedgerEntryType, SimpleTimer&> mPointTimers{};
9797

9898
// Bulk load timers take significantly longer, so the timer overhead is
9999
// comparatively negligible.
@@ -150,4 +150,4 @@ class SearchableBucketListSnapshotBase : public NonMovableOrCopyable
150150
std::shared_ptr<typename BucketT::LoadT const>
151151
load(LedgerKey const& k) const;
152152
};
153-
}
153+
}

src/bucket/BucketManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "util/GlobalChecks.h"
2828
#include "util/LogSlowExecution.h"
2929
#include "util/Logging.h"
30+
#include "util/MetricsRegistry.h"
3031
#include "util/ProtocolVersion.h"
3132
#include "util/TmpDir.h"
3233
#include "util/UnorderedMap.h"
@@ -44,7 +45,6 @@
4445
#include "history/FileTransferInfo.h"
4546
#include "medida/counter.h"
4647
#include "medida/meter.h"
47-
#include "medida/metrics_registry.h"
4848
#include "medida/timer.h"
4949
#include "work/WorkScheduler.h"
5050
#include "xdrpp/printer.h"

src/bucket/BucketUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
#include "ledger/LedgerTypeUtils.h"
99
#include "main/AppConnector.h"
1010
#include "main/Application.h"
11+
#include "util/MetricsRegistry.h"
1112
#include "util/types.h"
1213
#include "xdr/Stellar-ledger-entries.h"
1314
#include <fmt/format.h>
1415
#include <medida/counter.h>
15-
#include <medida/metrics_registry.h>
1616

1717
namespace stellar
1818
{

src/bucket/FutureBucket.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
#include "util/GlobalChecks.h"
2121
#include "util/LogSlowExecution.h"
2222
#include "util/Logging.h"
23+
#include "util/MetricsRegistry.h"
2324
#include "util/ProtocolVersion.h"
2425
#include "util/Thread.h"
2526
#include <Tracy.hpp>
2627
#include <fmt/format.h>
2728

28-
#include "medida/metrics_registry.h"
29-
3029
#include <chrono>
3130
#include <memory>
3231
#include <type_traits>

src/catchup/LedgerApplyManagerImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#include "ledger/LedgerManager.h"
1414
#include "main/Application.h"
1515
#include "medida/meter.h"
16-
#include "medida/metrics_registry.h"
1716
#include "util/GlobalChecks.h"
1817
#include "util/Logging.h"
18+
#include "util/MetricsRegistry.h"
1919
#include "util/StatusManager.h"
2020
#include "work/WorkScheduler.h"
2121
#include <Tracy.hpp>

src/database/Database.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "util/Fs.h"
1414
#include "util/GlobalChecks.h"
1515
#include "util/Logging.h"
16+
#include "util/MetricsRegistry.h"
1617
#include "util/Timer.h"
1718
#include "util/types.h"
1819
#include <error.h>
@@ -31,7 +32,6 @@
3132
#include "transactions/TransactionSQL.h"
3233

3334
#include "medida/counter.h"
34-
#include "medida/metrics_registry.h"
3535
#include "medida/timer.h"
3636
#include "xdr/Stellar-ledger-entries.h"
3737

src/herder/HerderImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "main/PersistentState.h"
2929
#include "medida/counter.h"
3030
#include "medida/meter.h"
31-
#include "medida/metrics_registry.h"
3231
#include "overlay/OverlayManager.h"
3332
#include "process/ProcessManager.h"
3433
#include "scp/LocalNode.h"
@@ -40,6 +39,7 @@
4039
#include "util/LogSlowExecution.h"
4140
#include "util/Logging.h"
4241
#include "util/Math.h"
42+
#include "util/MetricsRegistry.h"
4343
#include "util/StatusManager.h"
4444
#include "util/Timer.h"
4545
#include "util/XDRStream.h"

src/herder/HerderSCPDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "scp/Slot.h"
2020
#include "util/Logging.h"
2121
#include "util/Math.h"
22+
#include "util/MetricsRegistry.h"
2223
#include "util/ProtocolVersion.h"
2324
#include "xdr/Stellar-SCP.h"
2425
#include "xdr/Stellar-ledger-entries.h"
@@ -27,7 +28,6 @@
2728
#include <algorithm>
2829
#include <cmath>
2930
#include <fmt/format.h>
30-
#include <medida/metrics_registry.h>
3131
#include <numeric>
3232
#include <optional>
3333
#include <stdexcept>

0 commit comments

Comments
 (0)