From daf853eed7eb550493e004989d9dca779e95fb44 Mon Sep 17 00:00:00 2001 From: Artem Fomiuk <88630083+Artemka374@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:04:09 +0300 Subject: [PATCH] feat: Add blob size metrics (#2411) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Add metrics for witness input data blob sizes ## Why ❔ To have deeper understanding of what is right and what is wrong ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. --- Cargo.lock | 1 + core/node/proof_data_handler/Cargo.toml | 1 + core/node/proof_data_handler/src/lib.rs | 1 + core/node/proof_data_handler/src/metrics.rs | 41 +++++++++++++++++++ .../src/request_processor.rs | 4 +- 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 core/node/proof_data_handler/src/metrics.rs diff --git a/Cargo.lock b/Cargo.lock index de8460372bba..aa88c84975ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9219,6 +9219,7 @@ dependencies = [ "tokio", "tower", "tracing", + "vise", "zksync_basic_types", "zksync_config", "zksync_contracts", diff --git a/core/node/proof_data_handler/Cargo.toml b/core/node/proof_data_handler/Cargo.toml index 0ab5d4bb1913..92e6b45f6fa5 100644 --- a/core/node/proof_data_handler/Cargo.toml +++ b/core/node/proof_data_handler/Cargo.toml @@ -10,6 +10,7 @@ keywords.workspace = true categories.workspace = true [dependencies] +vise.workspace = true zksync_config.workspace = true zksync_dal.workspace = true zksync_object_store.workspace = true diff --git a/core/node/proof_data_handler/src/lib.rs b/core/node/proof_data_handler/src/lib.rs index 06b88b395139..618a786ea658 100644 --- a/core/node/proof_data_handler/src/lib.rs +++ b/core/node/proof_data_handler/src/lib.rs @@ -18,6 +18,7 @@ use zksync_types::commitment::L1BatchCommitmentMode; mod tests; mod errors; +mod metrics; mod request_processor; mod tee_request_processor; diff --git a/core/node/proof_data_handler/src/metrics.rs b/core/node/proof_data_handler/src/metrics.rs new file mode 100644 index 000000000000..edccda90dc24 --- /dev/null +++ b/core/node/proof_data_handler/src/metrics.rs @@ -0,0 +1,41 @@ +use vise::{Histogram, Metrics}; +use zksync_object_store::bincode; +use zksync_prover_interface::inputs::WitnessInputData; + +const BYTES_IN_MEGABYTE: u64 = 1024 * 1024; + +#[derive(Debug, Metrics)] +pub(super) struct ProofDataHandlerMetrics { + #[metrics(buckets = vise::Buckets::exponential(1.0..=2_048.0, 2.0))] + pub vm_run_data_blob_size_in_mb: Histogram, + #[metrics(buckets = vise::Buckets::exponential(1.0..=2_048.0, 2.0))] + pub merkle_paths_blob_size_in_mb: Histogram, + #[metrics(buckets = vise::Buckets::exponential(1.0..=2_048.0, 2.0))] + pub eip_4844_blob_size_in_mb: Histogram, + #[metrics(buckets = vise::Buckets::exponential(1.0..=2_048.0, 2.0))] + pub total_blob_size_in_mb: Histogram, +} + +impl ProofDataHandlerMetrics { + pub fn observe_blob_sizes(&self, blob: &WitnessInputData) { + let vm_run_data_blob_size_in_mb = + bincode::serialize(&blob.vm_run_data).unwrap().len() as u64 / BYTES_IN_MEGABYTE; + let merkle_paths_blob_size_in_mb = + bincode::serialize(&blob.merkle_paths).unwrap().len() as u64 / BYTES_IN_MEGABYTE; + let eip_4844_blob_size_in_mb = + bincode::serialize(&blob.eip_4844_blobs).unwrap().len() as u64 / BYTES_IN_MEGABYTE; + let total_blob_size_in_mb = + bincode::serialize(blob).unwrap().len() as u64 / BYTES_IN_MEGABYTE; + + self.vm_run_data_blob_size_in_mb + .observe(vm_run_data_blob_size_in_mb); + self.merkle_paths_blob_size_in_mb + .observe(merkle_paths_blob_size_in_mb); + self.eip_4844_blob_size_in_mb + .observe(eip_4844_blob_size_in_mb); + self.total_blob_size_in_mb.observe(total_blob_size_in_mb); + } +} + +#[vise::register] +pub(super) static METRICS: vise::Global = vise::Global::new(); diff --git a/core/node/proof_data_handler/src/request_processor.rs b/core/node/proof_data_handler/src/request_processor.rs index bdb55237c4b6..a89f9b63a848 100644 --- a/core/node/proof_data_handler/src/request_processor.rs +++ b/core/node/proof_data_handler/src/request_processor.rs @@ -20,7 +20,7 @@ use zksync_types::{ L1BatchNumber, H256, }; -use crate::errors::RequestProcessorError; +use crate::{errors::RequestProcessorError, metrics::METRICS}; #[derive(Clone)] pub(crate) struct RequestProcessor { @@ -147,6 +147,8 @@ impl RequestProcessor { }, }; + METRICS.observe_blob_sizes(&blob); + let proof_gen_data = ProofGenerationData { l1_batch_number, witness_input_data: blob,