mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-30 03:03:45 +00:00
Do not compute metrics in the network service if the cli flag is not set (#2765)
## Issue Addressed The computation of metrics in the network service can be expensive. This disables the computation unless the cli flag `metrics` is set. ## Additional Info Metrics in other parts of the network are still updated, since most are simple metrics and checking if metrics are enabled each time each metric is updated doesn't seem like a gain.
This commit is contained in:
@@ -137,6 +137,8 @@ pub struct NetworkService<T: BeaconChainTypes> {
|
||||
subscribe_all_subnets: bool,
|
||||
/// Shutdown beacon node after sync is complete.
|
||||
shutdown_after_sync: bool,
|
||||
/// Whether metrics are enabled or not.
|
||||
metrics_enabled: bool,
|
||||
/// A timer for updating various network metrics.
|
||||
metrics_update: tokio::time::Interval,
|
||||
/// gossipsub_parameter_update timer
|
||||
@@ -263,6 +265,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
next_unsubscribe,
|
||||
subscribe_all_subnets: config.subscribe_all_subnets,
|
||||
shutdown_after_sync: config.shutdown_after_sync,
|
||||
metrics_enabled: config.metrics_enabled,
|
||||
metrics_update,
|
||||
gossipsub_parameter_update,
|
||||
fork_context,
|
||||
@@ -325,7 +328,7 @@ fn spawn_service<T: BeaconChainTypes>(
|
||||
loop {
|
||||
// build the futures to check simultaneously
|
||||
tokio::select! {
|
||||
_ = service.metrics_update.tick() => {
|
||||
_ = service.metrics_update.tick(), if service.metrics_enabled => {
|
||||
// update various network metrics
|
||||
metric_update_counter +=1;
|
||||
if metric_update_counter % T::EthSpec::default_spec().seconds_per_slot == 0 {
|
||||
|
||||
Reference in New Issue
Block a user