From 02d3fd025d3d9008c58838dce87e1e868ccb4e2f Mon Sep 17 00:00:00 2001 From: Andrei Sandu <54316454+sandreim@users.noreply.github.com> Date: Wed, 21 Jun 2023 17:02:57 +0300 Subject: [PATCH] availability recovery: measure re-encoding time (#7409) * Measure re-encoding time Signed-off-by: Andrei Sandu * fix build Signed-off-by: Andrei Sandu --------- Signed-off-by: Andrei Sandu --- .../network/availability-recovery/src/lib.rs | 5 +++++ .../network/availability-recovery/src/metrics.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/polkadot/node/network/availability-recovery/src/lib.rs b/polkadot/node/network/availability-recovery/src/lib.rs index e4d76dcfda..c771e31a6c 100644 --- a/polkadot/node/network/availability-recovery/src/lib.rs +++ b/polkadot/node/network/availability-recovery/src/lib.rs @@ -255,6 +255,7 @@ impl RequestFromBackers { params.validators.len(), ¶ms.erasure_root, &data, + ¶ms.metrics, ) { gum::trace!( target: LOG_TARGET, @@ -586,6 +587,7 @@ impl RequestChunksFromValidators { params.validators.len(), ¶ms.erasure_root, &data, + &metrics, ) { gum::trace!( target: LOG_TARGET, @@ -685,7 +687,10 @@ fn reconstructed_data_matches_root( n_validators: usize, expected_root: &Hash, data: &AvailableData, + metrics: &Metrics, ) -> bool { + let _timer = metrics.time_reencode_chunks(); + let chunks = match obtain_chunks_v1(n_validators, data) { Ok(chunks) => chunks, Err(e) => { diff --git a/polkadot/node/network/availability-recovery/src/metrics.rs b/polkadot/node/network/availability-recovery/src/metrics.rs index 255d708e69..aa72167395 100644 --- a/polkadot/node/network/availability-recovery/src/metrics.rs +++ b/polkadot/node/network/availability-recovery/src/metrics.rs @@ -46,6 +46,10 @@ struct MetricsInner { /// The duration between the pure recovery and verification. time_erasure_recovery: Histogram, + /// How much time it takes to re-encode the data into erasure chunks in order to verify + /// the root hash of the provided Merkle tree. See `reconstructed_data_matches_root`. + time_reencode_chunks: Histogram, + /// Time of a full recovery, including erasure decoding or until we gave /// up. time_full_recovery: Histogram, @@ -118,6 +122,11 @@ impl Metrics { self.0.as_ref().map(|metrics| metrics.time_erasure_recovery.start_timer()) } + /// Get a timer to time chunk encoding. + pub fn time_reencode_chunks(&self) -> Option { + self.0.as_ref().map(|metrics| metrics.time_reencode_chunks.start_timer()) + } + /// Get a timer to measure the time of the complete recovery process. pub fn time_full_recovery(&self) -> Option { self.0.as_ref().map(|metrics| metrics.time_full_recovery.start_timer()) @@ -186,6 +195,13 @@ impl metrics::Metrics for Metrics { ))?, registry, )?, + time_reencode_chunks: prometheus::register( + prometheus::Histogram::with_opts(prometheus::HistogramOpts::new( + "polkadot_parachain_availability_reencode_chunks", + "Time spent re-encoding the data as erasure chunks", + ))?, + registry, + )?, time_full_recovery: prometheus::register( prometheus::Histogram::with_opts(prometheus::HistogramOpts::new( "polkadot_parachain_availability_recovery_time_total",