From 1375cd18326608a2613badf98caa59b3d1cc45bd Mon Sep 17 00:00:00 2001 From: fanyang Date: Thu, 25 Jun 2026 09:16:12 +0800 Subject: [PATCH] docs(stats): fix misleading/stale comments and rename test_counter - GC test: cutoff is in the future, so every metric is stale by timestamp (not "nothing is stale"); only live handles retain. - GC loop: drop the inaccurate "no Instant alloc" rationale. - bench: the handle path no longer calls Instant::now() (it uses fastant); reword the HANDLE_TOTAL_WORK rationale. - rename test_unsafe_counter -> test_counter to match the type rename. --- easytier/benches/counter_contention.rs | 5 +++-- easytier/src/common/stats_manager.rs | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/easytier/benches/counter_contention.rs b/easytier/benches/counter_contention.rs index 3723f3b2..a9eee61e 100644 --- a/easytier/benches/counter_contention.rs +++ b/easytier/benches/counter_contention.rs @@ -31,8 +31,9 @@ use parking_lot::Mutex; const COUNTER_SHARDS: usize = 16; const TOTAL_WORK: u64 = 8_000_000; -// The handle path calls `Instant::now()` per `add`, so it is far heavier per op -// than the counter-only groups; use a smaller total to keep the bench fast. +// The handle path does a counter update plus a timestamp `touch` per `add`, +// so it is heavier per op than the counter-only groups; use a smaller total to +// keep the bench fast. const HANDLE_TOTAL_WORK: u64 = 2_000_000; const TASK_COUNTS: &[usize] = &[1, 2, 4, 8, 16, 32]; diff --git a/easytier/src/common/stats_manager.rs b/easytier/src/common/stats_manager.rs index 9d8ad1e3..f748e678 100644 --- a/easytier/src/common/stats_manager.rs +++ b/easytier/src/common/stats_manager.rs @@ -578,7 +578,8 @@ impl StatsManager { interval.tick().await; // Drop metrics untouched for 180s and with no live handles. - // Compare in the millis-since-base domain; no Instant alloc. + // Compare in the millis-since-base domain so neither the hot + // path nor GC reconstructs an `Instant` or locks. let cutoff_millis = now_millis().saturating_sub(180_000); let Some(counters) = counters_clone.upgrade() else { @@ -756,7 +757,7 @@ mod tests { } #[tokio::test] - async fn test_unsafe_counter() { + async fn test_counter() { let counter = Counter::new(); assert_eq!(counter.get(), 0); @@ -908,8 +909,8 @@ mod tests { let counter = stats.get_simple_counter(MetricName::TrafficBytesForwarded); counter.set(1); - // Cutoff 1s in the future, so nothing is stale by timestamp; only live - // handles keep a metric. + // Cutoff 1s in the future, so every metric is stale by timestamp; only + // a live handle keeps a metric. let cutoff_millis = now_millis() + 1_000; stats .counters