Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

Commit

Permalink
πŸ”Š Use max lag metric instead
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed Aug 14, 2021
1 parent f8e3415 commit 237264d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blitz-dashboard"
version = "0.44.7"
version = "0.44.8"
authors = ["Pavel Perestoronin <[email protected]>"]
edition = "2018"
resolver = "2"
Expand Down
5 changes: 1 addition & 4 deletions src/crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?,
Expand Down
23 changes: 7 additions & 16 deletions src/crawler/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ pub struct TotalCrawlerMetrics {
#[derive(Clone)]
pub struct CrawlerMetrics {
pub n_accounts: Arc<AtomicU32>,
pub n_updated_accounts: Arc<AtomicU64>,
pub n_tanks: Arc<AtomicU32>,
pub last_account_id: Arc<AtomicI32>,
pub total_lag_secs: Arc<AtomicU64>,
pub max_lag_secs: Arc<AtomicU64>,
}

impl TotalCrawlerMetrics {
Expand All @@ -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();

Expand All @@ -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}",
),
Expand All @@ -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)),
);
}
}
Expand All @@ -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),
)
}
}

0 comments on commit 237264d

Please sign in to comment.