Skip to content

Commit

Permalink
Fix some performance metrics (#2222)
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc authored Mar 29, 2022
1 parent 13b0a3c commit d9850da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 5 additions & 6 deletions core/bin/zksync_core/src/state_keeper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,15 @@ impl ZkSyncStateKeeper {
// Generate and execute new miniblock every miniblock_interval
async fn run(mut self, miniblock_interval: Duration) {
let mut timer = time::interval(miniblock_interval);
let mut last_iteration = Instant::now();
loop {
let start = Instant::now();
timer.tick().await;
// Report timings between two miniblocks.
// If reported value stays at 0, most likely we have `miniblock_interval` variable too small and
// spend more time in the loop iteration than this interval.
metrics::histogram!("state_keeper.miniblock_interval", start.elapsed());

let start = Instant::now();

// `.throttle()` method will postpone the next miniblock iteration if currently we have too
// many blocks for which root hash is not yet calculated.
self.root_hash_queue.throttle().await;
Expand All @@ -292,10 +295,6 @@ impl ZkSyncStateKeeper {
let proposed_block = self.propose_new_block(block_timestamp).await;
metrics::histogram!("miniblock_size", proposed_block.size() as f64);

// Report timings between two miniblocks.
metrics::histogram!("miniblock_interval", last_iteration.elapsed());
last_iteration = Instant::now();

self.execute_proposed_block(proposed_block).await;
}
}
Expand Down
8 changes: 7 additions & 1 deletion core/bin/zksync_witness_generator/src/witness_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ impl<DB: DatabaseInterface> WitnessGenerator<DB> {
circuit_account_tree.set_internals(serde_json::from_value(account_tree_cache)?);
if block != cached_block {
// There is no relevant cache, so we have to use some outdated cache and update the tree.
metrics::increment_counter!("witness_generator.cache_access", "type" => "miss");
if *block == *cached_block + 1 {
// Off by 1 misses are normally expected
metrics::increment_counter!("witness_generator.cache_access", "type" => "off_by_1");
} else {
metrics::increment_counter!("witness_generator.cache_access", "type" => "miss");
}

vlog::info!("Reconstructing the cache for the block {} using the cached tree for the block {}", block, cached_block);

Expand Down Expand Up @@ -265,6 +270,7 @@ impl<DB: DatabaseInterface> WitnessGenerator<DB> {

// Initialize counters for cache hits/misses.
metrics::register_counter!("witness_generator.cache_access", "type" => "hit");
metrics::register_counter!("witness_generator.cache_access", "type" => "off_by_1");
metrics::register_counter!("witness_generator.cache_access", "type" => "miss");

let mut current_block = self.start_block;
Expand Down

0 comments on commit d9850da

Please sign in to comment.