Add a timeout to each of the periodic tick functions, with Future cancellation. Set interval behavior to "skip" rather than hammering a burst by default.

This commit is contained in:
Herbert Wolverson 2024-07-08 16:38:06 -05:00
parent 1ff24fe684
commit 0e893cd0e5

View File

@ -12,32 +12,35 @@ mod queue_stats_total;
mod network_tree;
use std::sync::Arc;
use std::time::Duration;
use tokio::time::timeout;
use crate::node_manager::ws::publish_subscribe::PubSub;
/// Runs a periodic tick to feed data to the node manager.
pub(super) async fn channel_ticker(channels: Arc<PubSub>) {
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(1));
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
loop {
interval.tick().await; // Once per second
tokio::join!(
cadence::cadence(channels.clone()),
throughput::throughput(channels.clone()),
rtt_histogram::rtt_histo(channels.clone()),
flow_counter::flow_count(channels.clone()),
top_10::top_10_downloaders(channels.clone()),
top_10::worst_10_downloaders(channels.clone()),
top_10::worst_10_retransmit(channels.clone()),
top_flows::top_flows_bytes(channels.clone()),
top_flows::top_flows_rate(channels.clone()),
flow_endpoints::endpoints_by_country(channels.clone()),
flow_endpoints::ether_protocols(channels.clone()),
flow_endpoints::ip_protocols(channels.clone()),
system_info::cpu_info(channels.clone()),
system_info::ram_info(channels.clone()),
tree_summary::tree_summary(channels.clone()),
queue_stats_total::queue_stats_totals(channels.clone()),
network_tree::network_tree(channels.clone()),
let _ = tokio::join!(
timeout(Duration::from_secs_f32(0.9), cadence::cadence(channels.clone())),
timeout(Duration::from_secs_f32(0.9), throughput::throughput(channels.clone())),
timeout(Duration::from_secs_f32(0.9), rtt_histogram::rtt_histo(channels.clone())),
timeout(Duration::from_secs_f32(0.9), flow_counter::flow_count(channels.clone())),
timeout(Duration::from_secs_f32(0.9), top_10::top_10_downloaders(channels.clone())),
timeout(Duration::from_secs_f32(0.9), top_10::worst_10_downloaders(channels.clone())),
timeout(Duration::from_secs_f32(0.9), top_10::worst_10_retransmit(channels.clone())),
timeout(Duration::from_secs_f32(0.9), top_flows::top_flows_bytes(channels.clone())),
timeout(Duration::from_secs_f32(0.9), top_flows::top_flows_rate(channels.clone())),
timeout(Duration::from_secs_f32(0.9), flow_endpoints::endpoints_by_country(channels.clone())),
timeout(Duration::from_secs_f32(0.9), flow_endpoints::ether_protocols(channels.clone())),
timeout(Duration::from_secs_f32(0.9), flow_endpoints::ip_protocols(channels.clone())),
timeout(Duration::from_secs_f32(0.9), system_info::cpu_info(channels.clone())),
timeout(Duration::from_secs_f32(0.9), system_info::ram_info(channels.clone())),
timeout(Duration::from_secs_f32(0.9), tree_summary::tree_summary(channels.clone())),
timeout(Duration::from_secs_f32(0.9), queue_stats_total::queue_stats_totals(channels.clone())),
timeout(Duration::from_secs_f32(0.9), network_tree::network_tree(channels.clone())),
);
}
}