diff --git a/Cargo.lock b/Cargo.lock index 1ada85b1..8fc84653 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -235,7 +235,7 @@ dependencies = [ [[package]] name = "blitz-dashboard" -version = "0.44.7" +version = "0.44.8" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 62fe9d4b..d13a4cea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blitz-dashboard" -version = "0.44.7" +version = "0.44.8" authors = ["Pavel Perestoronin "] edition = "2018" resolver = "2" diff --git a/src/crawler.rs b/src/crawler.rs index 03925372..81fe54c5 100644 --- a/src/crawler.rs +++ b/src/crawler.rs @@ -200,10 +200,7 @@ impl Crawler { .await?; self.insert_vehicles(&mut *connection, &tanks).await?; log::debug!("Inserted {} tanks for #{}.", tanks.len(), old_info.id); - self.metrics - .n_updated_accounts - .fetch_add(1, Ordering::Relaxed); - self.metrics.total_lag_secs.fetch_add( + self.metrics.max_lag_secs.fetch_max( (Utc::now() - new_info.base.last_battle_time) .num_seconds() .try_into()?, diff --git a/src/crawler/metrics.rs b/src/crawler/metrics.rs index 9b69276d..8da60559 100644 --- a/src/crawler/metrics.rs +++ b/src/crawler/metrics.rs @@ -13,10 +13,9 @@ pub struct TotalCrawlerMetrics { #[derive(Clone)] pub struct CrawlerMetrics { pub n_accounts: Arc, - pub n_updated_accounts: Arc, pub n_tanks: Arc, pub last_account_id: Arc, - pub total_lag_secs: Arc, + pub max_lag_secs: Arc, } impl TotalCrawlerMetrics { @@ -37,8 +36,8 @@ impl TotalCrawlerMetrics { let total_aps = hot_aps + cold_aps; let cold_tps = self.cold.n_tanks.swap(0, Ordering::Relaxed) as f64 / elapsed_secs; let hot_tps = self.hot.n_tanks.swap(0, Ordering::Relaxed) as f64 / elapsed_secs; - let cold_lag = self.cold.average_lag(); - let hot_lag = self.hot.average_lag(); + let cold_lag_secs = self.cold.max_lag_secs.swap(0, Ordering::Relaxed); + let hot_lag_secs = self.hot.max_lag_secs.swap(0, Ordering::Relaxed); self.start = Instant::now(); @@ -50,7 +49,7 @@ impl TotalCrawlerMetrics { " | ", "TPS: 🔥{hot_tps:.1} 🧊{cold_tps:.2}", " | ", - "lag: 🔥{hot_lag} 🧊{cold_lag}", + "max lag: 🔥{hot_lag} 🧊{cold_lag}", " | ", "🔥#{last_hot_account_id} 🧊#{last_cold_account_id}", ), @@ -62,8 +61,8 @@ impl TotalCrawlerMetrics { cold_tps = cold_tps, last_hot_account_id = self.hot.last_account_id.load(Ordering::Relaxed), last_cold_account_id = self.cold.last_account_id.load(Ordering::Relaxed), - hot_lag = humantime::format_duration(hot_lag), - cold_lag = humantime::format_duration(cold_lag), + hot_lag = humantime::format_duration(StdDuration::from_secs(hot_lag_secs)), + cold_lag = humantime::format_duration(StdDuration::from_secs(cold_lag_secs)), ); } } @@ -72,17 +71,9 @@ impl CrawlerMetrics { pub fn new() -> Self { Self { n_accounts: Arc::new(AtomicU32::new(0)), - n_updated_accounts: Arc::new(AtomicU64::new(0)), n_tanks: Arc::new(AtomicU32::new(0)), last_account_id: Arc::new(AtomicI32::new(0)), - total_lag_secs: Arc::new(AtomicU64::new(0)), + max_lag_secs: Arc::new(AtomicU64::new(0)), } } - - pub fn average_lag(&self) -> StdDuration { - StdDuration::from_secs( - self.total_lag_secs.swap(0, Ordering::Relaxed) - / self.n_updated_accounts.swap(0, Ordering::Relaxed).max(1), - ) - } }