@@ -84,7 +84,7 @@ void DoBgslotsreload(void* arg);
8484// threadpool metrics
8585struct ThreadPoolMetrics {
8686 std::atomic<uint64_t > tasks_scheduled{0 };
87- std::atomic<uint64_t > tasks_completed {0 };
87+ std::atomic<uint64_t > active_tasks {0 };
8888 std::atomic<uint64_t > borrow_attempts{0 };
8989
9090 // latency(1ms, 5ms, 10ms, 50ms, 100ms, 500ms, 1s, 5s, >5s)
@@ -567,6 +567,7 @@ class PikaServer : public pstd::noncopyable {
567567 void AutoDeleteExpiredDump ();
568568 void AutoUpdateNetworkMetric ();
569569 void PrintThreadPoolQueueStatus ();
570+ void AutoUpdateIdlePoolEMA ();
570571 void StatDiskUsage ();
571572 int64_t GetLastSaveTime (const std::string& dump_dir);
572573
@@ -708,22 +709,31 @@ class PikaServer : public pstd::noncopyable {
708709 PoolLatencyStats slow_pool_stats_;
709710
710711 // EMA configuration parameters (atomic for dynamic updates)
711- std::atomic<uint32_t > ema_alpha_numerator_{5 }; // EMA alpha numerator (alpha = 5/100 = 0.05)
712- std::atomic<uint32_t > ema_alpha_denominator_{100 }; // EMA alpha denominator
713- std::atomic<uint64_t > fast_busy_threshold_us_{2000 }; // Fast pool busy threshold (2ms)
714- std::atomic<uint64_t > fast_idle_threshold_us_{500 }; // Fast pool idle threshold (0.5ms)
715- std::atomic<uint64_t > slow_busy_threshold_us_{5000 }; // Slow pool busy threshold (5ms)
716- std::atomic<uint64_t > slow_idle_threshold_us_{1000 }; // Slow pool idle threshold (1ms)
712+ std::atomic<uint32_t > ema_alpha_numerator_{5 };
713+ std::atomic<uint32_t > ema_alpha_denominator_{100 };
714+ std::atomic<uint64_t > fast_busy_threshold_us_{2000 };
715+ std::atomic<uint64_t > fast_idle_threshold_us_{500 };
716+ std::atomic<uint64_t > slow_busy_threshold_us_{5000 };
717+ std::atomic<uint64_t > slow_idle_threshold_us_{1000 };
717718
718719 // Get EMA queue wait time (us)
719720 uint64_t GetEMAQueueWait (TaskPoolType pool_type) const ;
721+
722+ // EMA decay helper functions
723+ uint64_t CalculateDecayedEMA (uint64_t old_ema, uint64_t last_update, uint64_t now);
724+ void UpdateSinglePoolEMA (PoolLatencyStats& stats, uint64_t new_sample, uint64_t now);
725+ void DecaySinglePool (PoolLatencyStats& stats, uint64_t now);
720726
721727 // Busy/Idle determination based on EMA (internal helpers)
722728 bool IsFastPoolBusyByEMA () const ;
723729 bool IsFastPoolIdleByEMA () const ;
724730 bool IsSlowPoolBusyByEMA () const ;
725731 bool IsSlowPoolIdleByEMA () const ;
726732
733+ // Borrow idle window
734+ std::atomic<uint64_t > threadpool_idle_window_us_{1000000 };
735+ std::atomic<uint64_t > fast_pool_last_active_us_{0 };
736+ std::atomic<uint64_t > slow_pool_last_active_us_{0 };
727737 /*
728738 * acl
729739 */
0 commit comments