From bba7209cafb49d0f441735a5ff3ebd8f3c9e7ac3 Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Mon, 20 Nov 2023 08:59:53 -0600 Subject: [PATCH] Change the semantics of the stats gathering thread. If "gather stats" is set to false, don't spawn any of the collation tasks at all. Instead, just setup a null channel recipient to silently drop stats messages. This should allow for close-to-zero CPU overhead if you are a non-stats using luddite. --- .../src/collector/collection_manager.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/rust/lts_client/src/collector/collection_manager.rs b/src/rust/lts_client/src/collector/collection_manager.rs index 2383d80e..59e74c15 100644 --- a/src/rust/lts_client/src/collector/collection_manager.rs +++ b/src/rust/lts_client/src/collector/collection_manager.rs @@ -22,9 +22,24 @@ pub(crate) static DEVICE_ID_LIST: Lazy> = Lazy::new(DashSet::new /// /// Returns a channel that may be used to notify of data availability. pub async fn start_long_term_stats() -> Sender { - let (update_tx, update_rx): (Sender, Receiver) = mpsc::channel(10); + let (update_tx, mut update_rx): (Sender, Receiver) = mpsc::channel(10); let (comm_tx, comm_rx): (Sender, Receiver) = mpsc::channel(10); + if let Ok(cfg) = lqos_config::EtcLqos::load() { + if let Some(lts) = cfg.long_term_stats { + if !lts.gather_stats { + // Wire up a null recipient to the channel, so it receives messages + // but doesn't do anything with them. + tokio::spawn(async move { + while let Some(_msg) = update_rx.recv().await { + // Do nothing + } + }); + return update_tx; + } + } + } + tokio::spawn(lts_manager(update_rx, comm_tx)); tokio::spawn(collation_scheduler(update_tx.clone())); tokio::spawn(uisp_collection_manager(update_tx.clone()));