Skip to content

Commit 1f0d129

Browse files
authored
Add time metrics to aquire fork-choice lock (#6204)
* Add time metrics to aquire fork-choice lock * Apply suggestions from code review Co-authored-by: Michael Sproul <[email protected]> * Merge remote-tracking branch 'sigp/unstable' into fork-choice-lock-metrics * fix merge issue
1 parent 32f2e05 commit 1f0d129

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

beacon_node/beacon_chain/src/canonical_head.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ impl<E: EthSpec> CachedHead<E> {
236236
pub struct CanonicalHead<T: BeaconChainTypes> {
237237
/// Provides an in-memory representation of the non-finalized block tree and is used to run the
238238
/// fork choice algorithm and determine the canonical head.
239-
pub fork_choice: CanonicalHeadRwLock<BeaconForkChoice<T>>,
239+
fork_choice: CanonicalHeadRwLock<BeaconForkChoice<T>>,
240240
/// Provides values cached from a previous execution of `self.fork_choice.get_head`.
241241
///
242242
/// Although `self.fork_choice` might be slightly more advanced that this value, it is safe to
243243
/// consider that these values represent the "canonical head" of the beacon chain.
244-
pub cached_head: CanonicalHeadRwLock<CachedHead<T::EthSpec>>,
244+
cached_head: CanonicalHeadRwLock<CachedHead<T::EthSpec>>,
245245
/// A lock used to prevent concurrent runs of `BeaconChain::recompute_head`.
246246
///
247247
/// This lock **should not be made public**, it should only be used inside this module.
@@ -383,11 +383,13 @@ impl<T: BeaconChainTypes> CanonicalHead<T> {
383383

384384
/// Access a read-lock for fork choice.
385385
pub fn fork_choice_read_lock(&self) -> RwLockReadGuard<BeaconForkChoice<T>> {
386+
let _timer = metrics::start_timer(&metrics::FORK_CHOICE_READ_LOCK_AQUIRE_TIMES);
386387
self.fork_choice.read()
387388
}
388389

389390
/// Access a write-lock for fork choice.
390391
pub fn fork_choice_write_lock(&self) -> RwLockWriteGuard<BeaconForkChoice<T>> {
392+
let _timer = metrics::start_timer(&metrics::FORK_CHOICE_WRITE_LOCK_AQUIRE_TIMES);
391393
self.fork_choice.write()
392394
}
393395
}

beacon_node/beacon_chain/src/metrics.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,20 @@ pub static FORK_CHOICE_AFTER_FINALIZATION_TIMES: LazyLock<Result<Histogram>> =
569569
exponential_buckets(1e-3, 2.0, 10),
570570
)
571571
});
572+
pub static FORK_CHOICE_READ_LOCK_AQUIRE_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
573+
try_create_histogram_with_buckets(
574+
"beacon_fork_choice_read_lock_aquire_seconds",
575+
"Time taken to aquire the fork-choice read lock",
576+
exponential_buckets(1e-4, 4.0, 7),
577+
)
578+
});
579+
pub static FORK_CHOICE_WRITE_LOCK_AQUIRE_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
580+
try_create_histogram_with_buckets(
581+
"beacon_fork_choice_write_lock_aquire_seconds",
582+
"Time taken to aquire the fork-choice write lock",
583+
exponential_buckets(1e-3, 4.0, 7),
584+
)
585+
});
572586
pub static FORK_CHOICE_SET_HEAD_LAG_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
573587
try_create_histogram(
574588
"beacon_fork_choice_set_head_lag_times",

0 commit comments

Comments
 (0)