Browse Source

Add metrics about thread count in pool,

kruall 2 years ago
parent
commit
840348d6ec

+ 3 - 0
library/cpp/actors/core/executor_pool_basic.cpp

@@ -334,6 +334,8 @@ namespace NActors {
         poolStats.MaxUtilizationTime = RelaxedLoad(&MaxUtilizationAccumulator) / (i64)(NHPTimer::GetCyclesPerSecond() / 1000);
         poolStats.WrongWakenedThreadCount = RelaxedLoad(&WrongWakenedThreadCount);
         poolStats.CurrentThreadCount = RelaxedLoad(&ThreadCount);
+        poolStats.DefaultThreadCount = DefaultThreadCount;
+        poolStats.MaxThreadCount = MaxThreadCount;
         if (Harmonizer) {
             TPoolHarmonizedStats stats = Harmonizer->GetPoolStats(PoolId);
             poolStats.IsNeedy = stats.IsNeedy;
@@ -342,6 +344,7 @@ namespace NActors {
             poolStats.IncreasingThreadsByNeedyState = stats.IncreasingThreadsByNeedyState;
             poolStats.DecreasingThreadsByStarvedState = stats.DecreasingThreadsByStarvedState;
             poolStats.DecreasingThreadsByHoggishState = stats.DecreasingThreadsByHoggishState;
+            poolStats.PotentialMaxThreadCount = stats.PotentialMaxThreadCount;
         }
 
         statsCopy.resize(PoolThreads + 1);

+ 7 - 0
library/cpp/actors/core/harmonizer.cpp

@@ -121,6 +121,7 @@ struct TPoolInfo {
     TAtomic IncreasingThreadsByNeedyState = 0;
     TAtomic DecreasingThreadsByStarvedState = 0;
     TAtomic DecreasingThreadsByHoggishState = 0;
+    TAtomic PotentialMaxThreadCount = 0;
 
     bool IsBeingStopped(i16 threadIdx);
     double GetBooked(i16 threadIdx);
@@ -293,9 +294,14 @@ void THarmonizer::HarmonizeImpl(ui64 ts) {
         LWPROBE(HarmonizeCheckPool, poolIdx, pool.Pool->GetName(), poolBooked, poolConsumed, lastSecondPoolBooked, lastSecondPoolConsumed, pool.GetThreadCount(), pool.MaxThreadCount, isStarved, isNeedy, isHoggish);
     }
     double budget = total - Max(booked, lastSecondBooked);
+    i16 budgetInt = static_cast<i16>(Max(budget, 0.0));
     if (budget < -0.1) {
         isStarvedPresent = true;
     }
+    for (size_t poolIdx = 0; poolIdx < Pools.size(); ++poolIdx) {
+        TPoolInfo& pool = Pools[poolIdx];
+        AtomicSet(pool.PotentialMaxThreadCount, Min(pool.MaxThreadCount, budgetInt));
+    }
     double overbooked = consumed - booked;
     if (isStarvedPresent) {
       // last_starved_at_consumed_value = сумма по всем пулам consumed;
@@ -422,6 +428,7 @@ TPoolHarmonizedStats THarmonizer::GetPoolStats(i16 poolId) const {
         .IncreasingThreadsByNeedyState = static_cast<ui64>(RelaxedLoad(&pool.IncreasingThreadsByNeedyState)),
         .DecreasingThreadsByStarvedState = static_cast<ui64>(RelaxedLoad(&pool.DecreasingThreadsByStarvedState)),
         .DecreasingThreadsByHoggishState = static_cast<ui64>(RelaxedLoad(&pool.DecreasingThreadsByHoggishState)),
+        .PotentialMaxThreadCount = static_cast<i16>(RelaxedLoad(&pool.PotentialMaxThreadCount)),
         .IsNeedy = static_cast<bool>(flags & 1),
         .IsStarved = static_cast<bool>(flags & 2),
         .IsHoggish = static_cast<bool>(flags & 4),

+ 1 - 0
library/cpp/actors/core/harmonizer.h

@@ -10,6 +10,7 @@ namespace NActors {
         ui64 IncreasingThreadsByNeedyState = 0;
         ui64 DecreasingThreadsByStarvedState = 0;
         ui64 DecreasingThreadsByHoggishState = 0;
+        i16 PotentialMaxThreadCount = 0;
         bool IsNeedy = false;
         bool IsStarved = false;
         bool IsHoggish = false;

+ 3 - 0
library/cpp/actors/core/mon_stats.h

@@ -65,6 +65,9 @@ namespace NActors {
         ui64 DecreasingThreadsByHoggishState = 0;
         i16 WrongWakenedThreadCount = 0;
         i16 CurrentThreadCount = 0;
+        i16 PotentialMaxThreadCount = 0;
+        i16 DefaultThreadCount = 0;
+        i16 MaxThreadCount = 0;
         bool IsNeedy = false;
         bool IsStarved = false;
         bool IsHoggish = false;

+ 9 - 0
library/cpp/actors/helpers/pool_stats_collector.h

@@ -126,6 +126,9 @@ private:
         NMonitoring::TDynamicCounters::TCounterPtr MailboxPushedOutByEventCount;
         NMonitoring::TDynamicCounters::TCounterPtr WrongWakenedThreadCount;
         NMonitoring::TDynamicCounters::TCounterPtr CurrentThreadCount;
+        NMonitoring::TDynamicCounters::TCounterPtr PotentialMaxThreadCount;
+        NMonitoring::TDynamicCounters::TCounterPtr DefaultThreadCount;
+        NMonitoring::TDynamicCounters::TCounterPtr MaxThreadCount;
         NMonitoring::TDynamicCounters::TCounterPtr IsNeedy;
         NMonitoring::TDynamicCounters::TCounterPtr IsStarved;
         NMonitoring::TDynamicCounters::TCounterPtr IsHoggish;
@@ -178,6 +181,9 @@ private:
             MailboxPushedOutByEventCount = PoolGroup->GetCounter("MailboxPushedOutByEventCount", true);
             WrongWakenedThreadCount = PoolGroup->GetCounter("WrongWakenedThreadCount", true);
             CurrentThreadCount = PoolGroup->GetCounter("CurrentThreadCount", false);
+            PotentialMaxThreadCount = PoolGroup->GetCounter("PotentialMaxThreadCount", false);
+            DefaultThreadCount = PoolGroup->GetCounter("DefaultThreadCount", false);
+            MaxThreadCount = PoolGroup->GetCounter("MaxThreadCount", false);
             IsNeedy = PoolGroup->GetCounter("IsNeedy", false);
             IsStarved = PoolGroup->GetCounter("IsStarved", false);
             IsHoggish = PoolGroup->GetCounter("IsHoggish", false);
@@ -222,6 +228,9 @@ private:
             *MailboxPushedOutByEventCount = stats.MailboxPushedOutByEventCount;
             *WrongWakenedThreadCount = poolStats.WrongWakenedThreadCount;
             *CurrentThreadCount = poolStats.CurrentThreadCount;
+            *PotentialMaxThreadCount = poolStats.PotentialMaxThreadCount;
+            *DefaultThreadCount = poolStats.DefaultThreadCount;
+            *MaxThreadCount = poolStats.MaxThreadCount;
             *IsNeedy = poolStats.IsNeedy;
             *IsStarved = poolStats.IsStarved;
             *IsHoggish = poolStats.IsHoggish;