feat: record save_cache duration metrics (#14281)

This commit is contained in:
Dan Cline
2025-02-07 12:55:52 -05:00
committed by GitHub
parent b955551f8b
commit da86ff39b9
2 changed files with 5 additions and 1 deletions

View File

@ -72,7 +72,6 @@ pub(crate) struct BlockValidationMetrics {
/// Prewarm spawn duration
pub(crate) prewarm_spawn_duration: Gauge,
/// Cache saving duration
#[allow(dead_code)]
pub(crate) cache_saving_duration: Gauge,
/// State root config creation duration
pub(crate) state_root_config_duration: Gauge,

View File

@ -2601,6 +2601,7 @@ where
debug!(target: "engine::tree", ?root_elapsed, block=?block_num_hash, "Calculated state root");
if self.config.use_caching_and_prewarming() {
let save_cache_start = Instant::now();
// this is the only place / thread a writer is acquired, so we would have already
// crashed if we had a poisoned rwlock
//
@ -2611,6 +2612,10 @@ where
// apply state updates to cache and save it (if saving was successful)
self.most_recent_cache =
state_provider.save_cache(sealed_block.hash(), &output.state).ok();
let elapsed = save_cache_start.elapsed();
// record how long it took to save caches
self.metrics.block_validation.cache_saving_duration.set(elapsed.as_secs_f64());
}
let executed: ExecutedBlockWithTrieUpdates<N> = ExecutedBlockWithTrieUpdates {