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.
This commit is contained in:
fanyang
2026-06-25 09:16:12 +08:00
parent ebb97fd4f4
commit 1375cd1832
2 changed files with 8 additions and 6 deletions
+3 -2
View File
@@ -31,8 +31,9 @@ use parking_lot::Mutex;
const COUNTER_SHARDS: usize = 16; const COUNTER_SHARDS: usize = 16;
const TOTAL_WORK: u64 = 8_000_000; const TOTAL_WORK: u64 = 8_000_000;
// The handle path calls `Instant::now()` per `add`, so it is far heavier per op // The handle path does a counter update plus a timestamp `touch` per `add`,
// than the counter-only groups; use a smaller total to keep the bench fast. // 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 HANDLE_TOTAL_WORK: u64 = 2_000_000;
const TASK_COUNTS: &[usize] = &[1, 2, 4, 8, 16, 32]; const TASK_COUNTS: &[usize] = &[1, 2, 4, 8, 16, 32];
+5 -4
View File
@@ -578,7 +578,8 @@ impl StatsManager {
interval.tick().await; interval.tick().await;
// Drop metrics untouched for 180s and with no live handles. // 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 cutoff_millis = now_millis().saturating_sub(180_000);
let Some(counters) = counters_clone.upgrade() else { let Some(counters) = counters_clone.upgrade() else {
@@ -756,7 +757,7 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
async fn test_unsafe_counter() { async fn test_counter() {
let counter = Counter::new(); let counter = Counter::new();
assert_eq!(counter.get(), 0); assert_eq!(counter.get(), 0);
@@ -908,8 +909,8 @@ mod tests {
let counter = stats.get_simple_counter(MetricName::TrafficBytesForwarded); let counter = stats.get_simple_counter(MetricName::TrafficBytesForwarded);
counter.set(1); counter.set(1);
// Cutoff 1s in the future, so nothing is stale by timestamp; only live // Cutoff 1s in the future, so every metric is stale by timestamp; only
// handles keep a metric. // a live handle keeps a metric.
let cutoff_millis = now_millis() + 1_000; let cutoff_millis = now_millis() + 1_000;
stats stats
.counters .counters