mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Add log debounce to work processor (#3045)
## Issue Addressed #3010 ## Proposed Changes - move log debounce time latch to `./common/logging` - add timelatch to limit logging for `attestations_delay_queue` and `queued_block_roots` ## Additional Info - Is a separate crate for the time latch preferred? - `elapsed()` could take `LOG_DEBOUNCE_INTERVAL ` as an argument to allow for different granularity.
This commit is contained in:
@@ -47,13 +47,14 @@ use lighthouse_network::{
|
||||
rpc::{BlocksByRangeRequest, BlocksByRootRequest, StatusMessage},
|
||||
Client, MessageId, NetworkGlobals, PeerId, PeerRequestId,
|
||||
};
|
||||
use logging::TimeLatch;
|
||||
use slog::{crit, debug, error, trace, warn, Logger};
|
||||
use std::collections::VecDeque;
|
||||
use std::fmt;
|
||||
use std::pin::Pin;
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::task::Context;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::Duration;
|
||||
use std::{cmp, collections::HashSet};
|
||||
use task_executor::TaskExecutor;
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
@@ -159,9 +160,6 @@ const MANAGER_TASK_NAME: &str = "beacon_processor_manager";
|
||||
/// The name of the worker tokio tasks.
|
||||
const WORKER_TASK_NAME: &str = "beacon_processor_worker";
|
||||
|
||||
/// The minimum interval between log messages indicating that a queue is full.
|
||||
const LOG_DEBOUNCE_INTERVAL: Duration = Duration::from_secs(30);
|
||||
|
||||
/// The `MAX_..._BATCH_SIZE` variables define how many attestations can be included in a single
|
||||
/// batch.
|
||||
///
|
||||
@@ -742,25 +740,6 @@ impl<T: BeaconChainTypes> Work<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Provides de-bounce functionality for logging.
|
||||
#[derive(Default)]
|
||||
struct TimeLatch(Option<Instant>);
|
||||
|
||||
impl TimeLatch {
|
||||
/// Only returns true once every `LOG_DEBOUNCE_INTERVAL`.
|
||||
fn elapsed(&mut self) -> bool {
|
||||
let now = Instant::now();
|
||||
|
||||
let is_elapsed = self.0.map_or(false, |elapse_time| now > elapse_time);
|
||||
|
||||
if is_elapsed || self.0.is_none() {
|
||||
self.0 = Some(now + LOG_DEBOUNCE_INTERVAL);
|
||||
}
|
||||
|
||||
is_elapsed
|
||||
}
|
||||
}
|
||||
|
||||
/// Unifies all the messages processed by the `BeaconProcessor`.
|
||||
enum InboundEvent<T: BeaconChainTypes> {
|
||||
/// A worker has completed a task and is free.
|
||||
|
||||
Reference in New Issue
Block a user