From c996907e55109ce58a09c0e86d6e13b19c957413 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Wed, 13 Feb 2019 07:28:38 +1000 Subject: [PATCH] Add metrics to world state downloader to track number of pending requests, total requests completed and total requests retried. (#837) Signed-off-by: Adrian Sutton --- .../eth/sync/DefaultSynchronizer.java | 3 ++- .../sync/worldstate/WorldStateDownloader.java | 26 ++++++++++++++++++- .../worldstate/WorldStateDownloaderTest.java | 18 ++++++++----- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java index c673282d8f..0f86efc21f 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java @@ -105,7 +105,8 @@ public class DefaultSynchronizer implements Synchronizer { stateQueue, syncConfig.getWorldStateHashCountPerRequest(), syncConfig.getWorldStateRequestParallelism(), - ethTasksTimer); + ethTasksTimer, + metricsSystem); this.fastSyncDownloader = Optional.of( new FastSyncDownloader<>( diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloader.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloader.java index bdac05bb2b..1d560e68a1 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloader.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloader.java @@ -22,7 +22,10 @@ import tech.pegasys.pantheon.ethereum.eth.sync.tasks.WaitForPeerTask; import tech.pegasys.pantheon.ethereum.trie.MerklePatriciaTrie; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage.Updater; +import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; +import tech.pegasys.pantheon.metrics.MetricCategory; +import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.OperationTimer; import tech.pegasys.pantheon.services.queue.BigQueue; import tech.pegasys.pantheon.util.bytes.BytesValue; @@ -43,6 +46,8 @@ import org.apache.logging.log4j.Logger; public class WorldStateDownloader { private static final Logger LOG = LogManager.getLogger(); + private final Counter completedRequestsCounter; + private final Counter retriedRequestsTotal; private enum Status { IDLE, @@ -67,13 +72,30 @@ public class WorldStateDownloader { final BigQueue pendingRequests, final int hashCountPerRequest, final int maxOutstandingRequests, - final LabelledMetric ethTasksTimer) { + final LabelledMetric ethTasksTimer, + final MetricsSystem metricsSystem) { this.ethContext = ethContext; this.worldStateStorage = worldStateStorage; this.pendingRequests = pendingRequests; this.hashCountPerRequest = hashCountPerRequest; this.maxOutstandingRequests = maxOutstandingRequests; this.ethTasksTimer = ethTasksTimer; + metricsSystem.createGauge( + MetricCategory.SYNCHRONIZER, + "world_state_pending_requests_current", + "Number of pending requests for fast sync world state download", + () -> (double) pendingRequests.size()); + + completedRequestsCounter = + metricsSystem.createCounter( + MetricCategory.SYNCHRONIZER, + "world_state_completed_requests_total", + "Total number of node data requests completed as part of fast sync world state download"); + retriedRequestsTotal = + metricsSystem.createCounter( + MetricCategory.SYNCHRONIZER, + "world_state_retried_requests_total", + "Total number of node data requests repeated as part of fast sync world state download"); } public CompletableFuture run(final BlockHeader header) { @@ -184,8 +206,10 @@ public class WorldStateDownloader { for (NodeDataRequest request : requests) { BytesValue matchingData = requestFailed ? null : data.get(request.getHash()); if (matchingData == null) { + retriedRequestsTotal.inc(); pendingRequests.enqueue(request); } else { + completedRequestsCounter.inc(); // Persist request data request.setData(matchingData); request.persist(storageUpdater); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloaderTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloaderTest.java index adc7be9adc..f6cca31be8 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloaderTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloaderTest.java @@ -123,7 +123,8 @@ public class WorldStateDownloaderTest { queue, 10, 10, - NoOpMetricsSystem.NO_OP_LABELLED_TIMER); + NoOpMetricsSystem.NO_OP_LABELLED_TIMER, + new NoOpMetricsSystem()); CompletableFuture future = downloader.run(header); assertThat(future).isDone(); @@ -170,7 +171,8 @@ public class WorldStateDownloaderTest { queue, 10, 10, - NoOpMetricsSystem.NO_OP_LABELLED_TIMER); + NoOpMetricsSystem.NO_OP_LABELLED_TIMER, + new NoOpMetricsSystem()); CompletableFuture result = downloader.run(header); @@ -238,7 +240,8 @@ public class WorldStateDownloaderTest { queue, 10, 10, - NoOpMetricsSystem.NO_OP_LABELLED_TIMER); + NoOpMetricsSystem.NO_OP_LABELLED_TIMER, + new NoOpMetricsSystem()); CompletableFuture result = downloader.run(header); @@ -316,7 +319,8 @@ public class WorldStateDownloaderTest { queue, 10, 10, - NoOpMetricsSystem.NO_OP_LABELLED_TIMER); + NoOpMetricsSystem.NO_OP_LABELLED_TIMER, + new NoOpMetricsSystem()); CompletableFuture result = downloader.run(header); @@ -407,7 +411,8 @@ public class WorldStateDownloaderTest { queue, 10, 10, - NoOpMetricsSystem.NO_OP_LABELLED_TIMER); + NoOpMetricsSystem.NO_OP_LABELLED_TIMER, + new NoOpMetricsSystem()); CompletableFuture result = downloader.run(header); @@ -532,7 +537,8 @@ public class WorldStateDownloaderTest { queue, hashesPerRequest, maxOutstandingRequests, - NoOpMetricsSystem.NO_OP_LABELLED_TIMER); + NoOpMetricsSystem.NO_OP_LABELLED_TIMER, + new NoOpMetricsSystem()); // Create some peers that can respond List usefulPeers =