From c2432da61d011a79730d182d113484f93d1fbf57 Mon Sep 17 00:00:00 2001 From: Talya <22233835+hookzof@users.noreply.github.com> Date: Mon, 23 Mar 2026 01:42:31 +0100 Subject: [PATCH] Implement background cleanup task for user-stats Added a background task to clean up stale user-stats entries, improving performance under high connection counts. --- src/maestro/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/maestro/mod.rs b/src/maestro/mod.rs index 7d3b168..f22300e 100644 --- a/src/maestro/mod.rs +++ b/src/maestro/mod.rs @@ -220,6 +220,12 @@ pub async fn run() -> std::result::Result<(), Box> { let stats = Arc::new(Stats::new()); stats.apply_telemetry_policy(TelemetryPolicy::from_config(&config.general.telemetry)); + // Spawn background task to periodically clean up stale user-stats entries. + // This replaces per-packet maybe_cleanup_user_stats() calls that were removed + // from the I/O hot path to reduce DashMap write-lock contention under high + // connection counts. + let _stats_cleanup_task = stats.spawn_cleanup_task(); + let upstream_manager = Arc::new(UpstreamManager::new( config.upstreams.clone(), config.general.upstream_connect_retry_attempts,