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 <micsproul@gmail.com>

* Merge remote-tracking branch 'sigp/unstable' into fork-choice-lock-metrics

* fix merge issue
This commit is contained in:
Lion - dapplion
2024-08-20 04:03:43 +02:00
committed by GitHub
parent 32f2e059c5
commit 1f0d129707
2 changed files with 18 additions and 2 deletions

View File

@@ -236,12 +236,12 @@ impl<E: EthSpec> CachedHead<E> {
pub struct CanonicalHead<T: BeaconChainTypes> {
/// Provides an in-memory representation of the non-finalized block tree and is used to run the
/// fork choice algorithm and determine the canonical head.
pub fork_choice: CanonicalHeadRwLock<BeaconForkChoice<T>>,
fork_choice: CanonicalHeadRwLock<BeaconForkChoice<T>>,
/// Provides values cached from a previous execution of `self.fork_choice.get_head`.
///
/// Although `self.fork_choice` might be slightly more advanced that this value, it is safe to
/// consider that these values represent the "canonical head" of the beacon chain.
pub cached_head: CanonicalHeadRwLock<CachedHead<T::EthSpec>>,
cached_head: CanonicalHeadRwLock<CachedHead<T::EthSpec>>,
/// A lock used to prevent concurrent runs of `BeaconChain::recompute_head`.
///
/// This lock **should not be made public**, it should only be used inside this module.
@@ -383,11 +383,13 @@ impl<T: BeaconChainTypes> CanonicalHead<T> {
/// Access a read-lock for fork choice.
pub fn fork_choice_read_lock(&self) -> RwLockReadGuard<BeaconForkChoice<T>> {
let _timer = metrics::start_timer(&metrics::FORK_CHOICE_READ_LOCK_AQUIRE_TIMES);
self.fork_choice.read()
}
/// Access a write-lock for fork choice.
pub fn fork_choice_write_lock(&self) -> RwLockWriteGuard<BeaconForkChoice<T>> {
let _timer = metrics::start_timer(&metrics::FORK_CHOICE_WRITE_LOCK_AQUIRE_TIMES);
self.fork_choice.write()
}
}

View File

@@ -569,6 +569,20 @@ pub static FORK_CHOICE_AFTER_FINALIZATION_TIMES: LazyLock<Result<Histogram>> =
exponential_buckets(1e-3, 2.0, 10),
)
});
pub static FORK_CHOICE_READ_LOCK_AQUIRE_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
try_create_histogram_with_buckets(
"beacon_fork_choice_read_lock_aquire_seconds",
"Time taken to aquire the fork-choice read lock",
exponential_buckets(1e-4, 4.0, 7),
)
});
pub static FORK_CHOICE_WRITE_LOCK_AQUIRE_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
try_create_histogram_with_buckets(
"beacon_fork_choice_write_lock_aquire_seconds",
"Time taken to aquire the fork-choice write lock",
exponential_buckets(1e-3, 4.0, 7),
)
});
pub static FORK_CHOICE_SET_HEAD_LAG_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
try_create_histogram(
"beacon_fork_choice_set_head_lag_times",