Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
feat: Add blob size metrics (matter-labs#2411)
Browse files Browse the repository at this point in the history
## What ❔

Add metrics for witness input data blob sizes

## Why ❔

To have deeper understanding of what is right and what is wrong

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [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`.
  • Loading branch information
Artemka374 authored and irnb committed Jul 12, 2024
1 parent 79ebde5 commit daf853e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/node/proof_data_handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions core/node/proof_data_handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use zksync_types::commitment::L1BatchCommitmentMode;
mod tests;

mod errors;
mod metrics;
mod request_processor;
mod tee_request_processor;

Expand Down
41 changes: 41 additions & 0 deletions core/node/proof_data_handler/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -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<u64>,
#[metrics(buckets = vise::Buckets::exponential(1.0..=2_048.0, 2.0))]
pub merkle_paths_blob_size_in_mb: Histogram<u64>,
#[metrics(buckets = vise::Buckets::exponential(1.0..=2_048.0, 2.0))]
pub eip_4844_blob_size_in_mb: Histogram<u64>,
#[metrics(buckets = vise::Buckets::exponential(1.0..=2_048.0, 2.0))]
pub total_blob_size_in_mb: Histogram<u64>,
}

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<ProofDataHandlerMetrics> = vise::Global::new();
4 changes: 3 additions & 1 deletion core/node/proof_data_handler/src/request_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -147,6 +147,8 @@ impl RequestProcessor {
},
};

METRICS.observe_blob_sizes(&blob);

let proof_gen_data = ProofGenerationData {
l1_batch_number,
witness_input_data: blob,
Expand Down

0 comments on commit daf853e

Please sign in to comment.