Worst 10 stats are no longer stored globally in lqos_node_manager. Instead, they are only calculated when requested. Slightly higher utilization with lots of people using the node manager, and no bus traffic during the 99% of the time when its idle.

This commit is contained in:
Herbert Wolverson 2023-03-08 16:38:19 +00:00
parent 9f8bf22ff9
commit 67c8f9dec0
3 changed files with 15 additions and 12 deletions

View File

@ -1,12 +1,11 @@
use lqos_bus::IpStats;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::sync::RwLock; use std::sync::RwLock;
//pub static TOP_10_DOWNLOADERS: Lazy<RwLock<Vec<IpStats>>> = //pub static TOP_10_DOWNLOADERS: Lazy<RwLock<Vec<IpStats>>> =
// Lazy::new(|| RwLock::new(Vec::with_capacity(10))); // Lazy::new(|| RwLock::new(Vec::with_capacity(10)));
pub static WORST_10_RTT: Lazy<RwLock<Vec<IpStats>>> = //pub static WORST_10_RTT: Lazy<RwLock<Vec<IpStats>>> =
Lazy::new(|| RwLock::new(Vec::with_capacity(10))); // Lazy::new(|| RwLock::new(Vec::with_capacity(10)));
pub static RTT_HISTOGRAM: Lazy<RwLock<Vec<u32>>> = pub static RTT_HISTOGRAM: Lazy<RwLock<Vec<u32>>> =
Lazy::new(|| RwLock::new(Vec::with_capacity(100))); Lazy::new(|| RwLock::new(Vec::with_capacity(100)));

View File

@ -129,16 +129,12 @@ fn watch_for_shaped_devices_changing() -> Result<()> {
async fn get_data_from_server() -> Result<()> { async fn get_data_from_server() -> Result<()> {
// Send request to lqosd // Send request to lqosd
let requests = vec![ let requests = vec![
BusRequest::GetWorstRtt { start: 0, end: 10 },
BusRequest::RttHistogram, BusRequest::RttHistogram,
BusRequest::AllUnknownIps, BusRequest::AllUnknownIps,
]; ];
for r in bus_request(requests).await?.iter() { for r in bus_request(requests).await?.iter() {
match r { match r {
BusResponse::WorstRtt(stats) => {
*WORST_10_RTT.write().unwrap() = stats.clone();
}
BusResponse::RttHistogram(stats) => { BusResponse::RttHistogram(stats) => {
*RTT_HISTOGRAM.write().unwrap() = stats.clone(); *RTT_HISTOGRAM.write().unwrap() = stats.clone();
} }

View File

@ -2,7 +2,7 @@ mod cache;
mod cache_manager; mod cache_manager;
use self::cache::{ use self::cache::{
CPU_USAGE, HOST_COUNTS, NUM_CPUS, RAM_USED, RTT_HISTOGRAM, CPU_USAGE, HOST_COUNTS, NUM_CPUS, RAM_USED, RTT_HISTOGRAM,
TOTAL_RAM, WORST_10_RTT, TOTAL_RAM,
}; };
use crate::{auth_guard::AuthGuard, cache_control::NoCache}; use crate::{auth_guard::AuthGuard, cache_control::NoCache};
pub use cache::{SHAPED_DEVICES, UNKNOWN_DEVICES}; pub use cache::{SHAPED_DEVICES, UNKNOWN_DEVICES};
@ -123,10 +123,18 @@ pub async fn top_10_downloaders(_auth: AuthGuard) -> NoCache<Json<Vec<IpStatsWit
} }
#[get("/api/worst_10_rtt")] #[get("/api/worst_10_rtt")]
pub fn worst_10_rtt(_auth: AuthGuard) -> Json<Vec<IpStatsWithPlan>> { pub async fn worst_10_rtt(_auth: AuthGuard) -> NoCache<Json<Vec<IpStatsWithPlan>>> {
let tt: Vec<IpStatsWithPlan> = if let Ok(messages) = bus_request(vec![BusRequest::GetWorstRtt { start: 0, end: 10 }]).await
WORST_10_RTT.read().unwrap().iter().map(|tt| tt.into()).collect(); {
Json(tt) for msg in messages {
if let BusResponse::WorstRtt(stats) = msg {
let result = stats.iter().map(|tt| tt.into()).collect();
return NoCache::new(Json(result));
}
}
}
NoCache::new(Json(Vec::new()))
} }
#[get("/api/rtt_histogram")] #[get("/api/rtt_histogram")]