diff options
author | ivanmorozov <ivanmorozov@yandex-team.com> | 2023-07-09 10:21:29 +0300 |
---|---|---|
committer | ivanmorozov <ivanmorozov@yandex-team.com> | 2023-07-09 10:21:29 +0300 |
commit | 6519925862676d6da052188ed76143198de99098 (patch) | |
tree | fbf8fdb0ee39f0e819a08db83637748129473ce6 /library/cpp | |
parent | 9f0b257a72fa295d1f62c9b6581770703fed052f (diff) | |
download | ydb-6519925862676d6da052188ed76143198de99098.tar.gz |
KIKIMR-18568: internal control stats pool size limit
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/actors/core/actorsystem.h | 5 | ||||
-rw-r--r-- | library/cpp/actors/core/config.h | 5 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_pool_base.cpp | 16 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_pool_base.h | 4 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_pool_basic.cpp | 5 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_pool_basic.h | 2 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_pool_basic_ut.cpp | 8 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_pool_io.cpp | 7 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_pool_io.h | 3 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_pool_united.cpp | 4 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_pool_united_ut.cpp | 8 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_thread.cpp | 2 | ||||
-rw-r--r-- | library/cpp/actors/core/indexes.h | 9 | ||||
-rw-r--r-- | library/cpp/actors/core/mon_stats.h | 13 | ||||
-rw-r--r-- | library/cpp/actors/core/worker_context.h | 3 | ||||
-rw-r--r-- | library/cpp/actors/util/local_process_key.h | 9 |
16 files changed, 54 insertions, 49 deletions
diff --git a/library/cpp/actors/core/actorsystem.h b/library/cpp/actors/core/actorsystem.h index 9cb8940223d..821b94ada98 100644 --- a/library/cpp/actors/core/actorsystem.h +++ b/library/cpp/actors/core/actorsystem.h @@ -99,7 +99,6 @@ namespace NActors { TCpuManagerConfig CpuManager; TAutoPtr<ISchedulerThread> Scheduler; - ui32 MaxActivityType = 5; // for default entries TInterconnectSetup Interconnect; @@ -273,10 +272,6 @@ namespace NActors { TActorId LookupLocalService(const TActorId& x) const; TActorId RegisterLocalService(const TActorId& serviceId, const TActorId& actorId); - ui32 GetMaxActivityType() const { - return SystemSetup ? SystemSetup->MaxActivityType : 1; - } - TInstant Timestamp() const { return TInstant::MicroSeconds(RelaxedLoad(&CurrentTimestamp)); } diff --git a/library/cpp/actors/core/config.h b/library/cpp/actors/core/config.h index 650b1f39f5b..220cb3d9d13 100644 --- a/library/cpp/actors/core/config.h +++ b/library/cpp/actors/core/config.h @@ -40,7 +40,6 @@ namespace NActors { TDuration TimePerMailbox = DEFAULT_TIME_PER_MAILBOX; ui32 EventsPerMailbox = DEFAULT_EVENTS_PER_MAILBOX; int RealtimePriority = 0; - ui32 MaxActivityType = 5; i16 MinThreadCount = 0; i16 MaxThreadCount = 0; i16 DefaultThreadCount = 0; @@ -52,7 +51,6 @@ namespace NActors { TString PoolName; ui32 Threads = 1; TCpuMask Affinity; // Executor thread affinity - ui32 MaxActivityType = 5; }; struct TUnitedExecutorPoolConfig { @@ -71,9 +69,6 @@ namespace NActors { TDuration TimePerMailbox = DEFAULT_TIME_PER_MAILBOX; ui32 EventsPerMailbox = DEFAULT_EVENTS_PER_MAILBOX; - // Introspection - ui32 MaxActivityType = 5; - // Long-term balancing TBalancingConfig Balancing; }; diff --git a/library/cpp/actors/core/executor_pool_base.cpp b/library/cpp/actors/core/executor_pool_base.cpp index 047503b78e0..1671190f5ca 100644 --- a/library/cpp/actors/core/executor_pool_base.cpp +++ b/library/cpp/actors/core/executor_pool_base.cpp @@ -14,13 +14,10 @@ namespace NActors { actor->Registered(sys, owner); } - TExecutorPoolBaseMailboxed::TExecutorPoolBaseMailboxed(ui32 poolId, ui32 maxActivityType) + TExecutorPoolBaseMailboxed::TExecutorPoolBaseMailboxed(ui32 poolId) : IExecutorPool(poolId) , ActorSystem(nullptr) , MailboxTable(new TMailboxTable) -#ifdef ACTORSLIB_COLLECT_EXEC_STATS - , Stats(maxActivityType) -#endif {} TExecutorPoolBaseMailboxed::~TExecutorPoolBaseMailboxed() { @@ -54,8 +51,8 @@ namespace NActors { } #endif - TExecutorPoolBase::TExecutorPoolBase(ui32 poolId, ui32 threads, TAffinity* affinity, ui32 maxActivityType) - : TExecutorPoolBaseMailboxed(poolId, maxActivityType) + TExecutorPoolBase::TExecutorPoolBase(ui32 poolId, ui32 threads, TAffinity* affinity) + : TExecutorPoolBaseMailboxed(poolId) , PoolThreads(threads) , ThreadsAffinity(affinity) {} @@ -119,8 +116,11 @@ namespace NActors { NHPTimer::STime hpstart = GetCycleCountFast(); #ifdef ACTORSLIB_COLLECT_EXEC_STATS ui32 at = actor->GetActivityType(); - if (at >= Stats.MaxActivityType()) - at = 0; + Y_VERIFY_DEBUG(at < Stats.ActorsAliveByActivity.size()); + if (at >= Stats.MaxActivityType()) { + at = TActorTypeOperator::GetActorActivityIncorrectIndex(); + Y_VERIFY(at < Stats.ActorsAliveByActivity.size()); + } AtomicIncrement(Stats.ActorsAliveByActivity[at]); if (ActorSystem->MonitorStuckActors()) { with_lock (StuckObserverMutex) { diff --git a/library/cpp/actors/core/executor_pool_base.h b/library/cpp/actors/core/executor_pool_base.h index d9286f6b11a..8a5214c92cb 100644 --- a/library/cpp/actors/core/executor_pool_base.h +++ b/library/cpp/actors/core/executor_pool_base.h @@ -28,7 +28,7 @@ namespace NActors { TAtomic RegisterRevolvingCounter = 0; ui64 AllocateID(); public: - TExecutorPoolBaseMailboxed(ui32 poolId, ui32 maxActivityType); + explicit TExecutorPoolBaseMailboxed(ui32 poolId); ~TExecutorPoolBaseMailboxed(); void ReclaimMailbox(TMailboxType::EType mailboxType, ui32 hint, TWorkerId workerId, ui64 revolvingWriteCounter) override; TMailboxHeader *ResolveMailbox(ui32 hint) override; @@ -48,7 +48,7 @@ namespace NActors { TAtomic ActivationsRevolvingCounter = 0; volatile bool StopFlag = false; public: - TExecutorPoolBase(ui32 poolId, ui32 threads, TAffinity* affinity, ui32 maxActivityType); + TExecutorPoolBase(ui32 poolId, ui32 threads, TAffinity* affinity); ~TExecutorPoolBase(); void ScheduleActivation(ui32 activation) override; void SpecificScheduleActivation(ui32 activation) override; diff --git a/library/cpp/actors/core/executor_pool_basic.cpp b/library/cpp/actors/core/executor_pool_basic.cpp index 4e630531865..6f0d785ff58 100644 --- a/library/cpp/actors/core/executor_pool_basic.cpp +++ b/library/cpp/actors/core/executor_pool_basic.cpp @@ -29,7 +29,7 @@ namespace NActors { i16 maxThreadCount, i16 defaultThreadCount, i16 priority) - : TExecutorPoolBase(poolId, threads, affinity, maxActivityType) + : TExecutorPoolBase(poolId, threads, affinity) , SpinThreshold(spinThreshold) , SpinThresholdCycles(spinThreshold * NHPTimer::GetCyclesPerSecond() * 0.000001) // convert microseconds to cycles , Threads(new TThreadCtx[threads]) @@ -48,6 +48,7 @@ namespace NActors { , Harmonizer(harmonizer) , Priority(priority) { + Y_UNUSED(maxActivityType); i16 limit = Min(threads, (ui32)Max<i16>()); if (DefaultThreadCount) { DefaultThreadCount = Min(DefaultThreadCount, limit); @@ -79,7 +80,7 @@ namespace NActors { cfg.TimePerMailbox, cfg.EventsPerMailbox, cfg.RealtimePriority, - cfg.MaxActivityType, + 0, cfg.MinThreadCount, cfg.MaxThreadCount, cfg.DefaultThreadCount, diff --git a/library/cpp/actors/core/executor_pool_basic.h b/library/cpp/actors/core/executor_pool_basic.h index b773b6f9167..e58718a225a 100644 --- a/library/cpp/actors/core/executor_pool_basic.h +++ b/library/cpp/actors/core/executor_pool_basic.h @@ -120,7 +120,7 @@ namespace NActors { TDuration timePerMailbox = DEFAULT_TIME_PER_MAILBOX, ui32 eventsPerMailbox = DEFAULT_EVENTS_PER_MAILBOX, int realtimePriority = 0, - ui32 maxActivityType = 1, + ui32 maxActivityType = 0 /* deprecated */, i16 minThreadCount = 0, i16 maxThreadCount = 0, i16 defaultThreadCount = 0, diff --git a/library/cpp/actors/core/executor_pool_basic_ut.cpp b/library/cpp/actors/core/executor_pool_basic_ut.cpp index a487582f324..ecc889211f0 100644 --- a/library/cpp/actors/core/executor_pool_basic_ut.cpp +++ b/library/cpp/actors/core/executor_pool_basic_ut.cpp @@ -346,10 +346,10 @@ Y_UNIT_TEST_SUITE(BasicExecutorPool) { UNIT_ASSERT_VALUES_EQUAL(stats[0].EventDeliveryTimeHistogram.TotalSamples, msgCount); UNIT_ASSERT_VALUES_EQUAL(stats[0].EventProcessingCountHistogram.TotalSamples, msgCount); UNIT_ASSERT(stats[0].EventProcessingTimeHistogram.TotalSamples > 0); - UNIT_ASSERT(stats[0].ElapsedTicksByActivity[0] > 0); - UNIT_ASSERT_VALUES_EQUAL(stats[0].ReceivedEventsByActivity[0], msgCount); - UNIT_ASSERT_VALUES_EQUAL(stats[0].ActorsAliveByActivity[0], 1); - UNIT_ASSERT_VALUES_EQUAL(stats[0].ScheduledEventsByActivity[0], 0); + UNIT_ASSERT(stats[0].ElapsedTicksByActivity[NActors::TActorTypeOperator::GetOtherActivityIndex()] > 0); + UNIT_ASSERT_VALUES_EQUAL(stats[0].ReceivedEventsByActivity[NActors::TActorTypeOperator::GetOtherActivityIndex()], msgCount); + UNIT_ASSERT_VALUES_EQUAL(stats[0].ActorsAliveByActivity[NActors::TActorTypeOperator::GetOtherActivityIndex()], 1); + UNIT_ASSERT_VALUES_EQUAL(stats[0].ScheduledEventsByActivity[NActors::TActorTypeOperator::GetOtherActivityIndex()], 0); UNIT_ASSERT_VALUES_EQUAL(stats[0].PoolActorRegistrations, 1); UNIT_ASSERT_VALUES_EQUAL(stats[0].PoolDestroyedActors, 0); UNIT_ASSERT_VALUES_EQUAL(stats[0].PoolAllocatedMailboxes, 4095); // one line diff --git a/library/cpp/actors/core/executor_pool_io.cpp b/library/cpp/actors/core/executor_pool_io.cpp index 6987bbd29c1..80b927c486d 100644 --- a/library/cpp/actors/core/executor_pool_io.cpp +++ b/library/cpp/actors/core/executor_pool_io.cpp @@ -5,8 +5,8 @@ #include <library/cpp/actors/util/datetime.h> namespace NActors { - TIOExecutorPool::TIOExecutorPool(ui32 poolId, ui32 threads, const TString& poolName, TAffinity* affinity, ui32 maxActivityType) - : TExecutorPoolBase(poolId, threads, affinity, maxActivityType) + TIOExecutorPool::TIOExecutorPool(ui32 poolId, ui32 threads, const TString& poolName, TAffinity* affinity) + : TExecutorPoolBase(poolId, threads, affinity) , Threads(new TThreadCtx[threads]) , PoolName(poolName) {} @@ -16,8 +16,7 @@ namespace NActors { cfg.PoolId, cfg.Threads, cfg.PoolName, - new TAffinity(cfg.Affinity), - cfg.MaxActivityType + new TAffinity(cfg.Affinity) ) {} diff --git a/library/cpp/actors/core/executor_pool_io.h b/library/cpp/actors/core/executor_pool_io.h index 6c9069d9b63..6b37d095acf 100644 --- a/library/cpp/actors/core/executor_pool_io.h +++ b/library/cpp/actors/core/executor_pool_io.h @@ -26,8 +26,7 @@ namespace NActors { const TString PoolName; const ui32 ActorSystemIndex = NActors::TActorTypeOperator::GetActorSystemIndex(); public: - TIOExecutorPool(ui32 poolId, ui32 threads, const TString& poolName = "", TAffinity* affinity = nullptr, - ui32 maxActivityType = 1); + TIOExecutorPool(ui32 poolId, ui32 threads, const TString& poolName = "", TAffinity* affinity = nullptr); explicit TIOExecutorPool(const TIOExecutorPoolConfig& cfg); ~TIOExecutorPool(); diff --git a/library/cpp/actors/core/executor_pool_united.cpp b/library/cpp/actors/core/executor_pool_united.cpp index d1e9e15385c..eb4c8348d75 100644 --- a/library/cpp/actors/core/executor_pool_united.cpp +++ b/library/cpp/actors/core/executor_pool_united.cpp @@ -1134,7 +1134,7 @@ namespace NActors { // Reinitialize per cpu pool stats with right MaxActivityType for (const TCpuAllocation& cpuAlloc : allocation.Items) { TCpu& cpu = Cpus[cpuAlloc.CpuId]; - cpu.PoolStats[cfg.PoolId] = TExecutorThreadStats(cfg.MaxActivityType); + cpu.PoolStats[cfg.PoolId] = TExecutorThreadStats(); } // Setup WakeOrderCpus: left to right exclusive cpus, then left to right shared cpus. @@ -1374,7 +1374,7 @@ namespace NActors { } TUnitedExecutorPool::TUnitedExecutorPool(const TUnitedExecutorPoolConfig& cfg, TUnitedWorkers* united) - : TExecutorPoolBaseMailboxed(cfg.PoolId, cfg.MaxActivityType) + : TExecutorPoolBaseMailboxed(cfg.PoolId) , United(united) , PoolName(cfg.PoolName) { diff --git a/library/cpp/actors/core/executor_pool_united_ut.cpp b/library/cpp/actors/core/executor_pool_united_ut.cpp index f066254ffed..2871e016fe0 100644 --- a/library/cpp/actors/core/executor_pool_united_ut.cpp +++ b/library/cpp/actors/core/executor_pool_united_ut.cpp @@ -178,10 +178,10 @@ Y_UNIT_TEST_SUITE(UnitedExecutorPool) { UNIT_ASSERT_VALUES_EQUAL(stats[0].EventDeliveryTimeHistogram.TotalSamples, msgCount); UNIT_ASSERT_VALUES_EQUAL(stats[0].EventProcessingCountHistogram.TotalSamples, msgCount); UNIT_ASSERT(stats[0].EventProcessingTimeHistogram.TotalSamples > 0); - UNIT_ASSERT(stats[0].ElapsedTicksByActivity[0] > 0); - UNIT_ASSERT_VALUES_EQUAL(stats[0].ReceivedEventsByActivity[0], msgCount); - UNIT_ASSERT_VALUES_EQUAL(stats[0].ActorsAliveByActivity[0], 1); - UNIT_ASSERT_VALUES_EQUAL(stats[0].ScheduledEventsByActivity[0], 0); + UNIT_ASSERT(stats[0].ElapsedTicksByActivity[NActors::TActorTypeOperator::GetOtherActivityIndex()] > 0); + UNIT_ASSERT_VALUES_EQUAL(stats[0].ReceivedEventsByActivity[NActors::TActorTypeOperator::GetOtherActivityIndex()], msgCount); + UNIT_ASSERT_VALUES_EQUAL(stats[0].ActorsAliveByActivity[NActors::TActorTypeOperator::GetOtherActivityIndex()], 1); + UNIT_ASSERT_VALUES_EQUAL(stats[0].ScheduledEventsByActivity[NActors::TActorTypeOperator::GetOtherActivityIndex()], 0); UNIT_ASSERT_VALUES_EQUAL(stats[0].PoolActorRegistrations, 1); UNIT_ASSERT_VALUES_EQUAL(stats[0].PoolDestroyedActors, 0); UNIT_ASSERT_VALUES_EQUAL(stats[0].PoolAllocatedMailboxes, 4095); // one line diff --git a/library/cpp/actors/core/executor_thread.cpp b/library/cpp/actors/core/executor_thread.cpp index 2efbfd01f09..0b6045693bb 100644 --- a/library/cpp/actors/core/executor_thread.cpp +++ b/library/cpp/actors/core/executor_thread.cpp @@ -40,7 +40,7 @@ namespace NActors { ui32 eventsPerMailbox) : ActorSystem(actorSystem) , ExecutorPool(executorPool) - , Ctx(workerId, cpuId, actorSystem ? actorSystem->GetMaxActivityType() : 1) + , Ctx(workerId, cpuId) , ThreadName(threadName) , IsUnitedWorker(true) { diff --git a/library/cpp/actors/core/indexes.h b/library/cpp/actors/core/indexes.h index 61cc78fccc5..2bac5370de0 100644 --- a/library/cpp/actors/core/indexes.h +++ b/library/cpp/actors/core/indexes.h @@ -18,6 +18,7 @@ public: namespace NActors { enum class EInternalActorType { OTHER = 0, + INCORRECT_ACTOR_TYPE_INDEX, ACTOR_SYSTEM, ACTORLIB_COMMON, ACTORLIB_STATS, @@ -43,6 +44,10 @@ enum class EInternalActorType { class TActorTypeOperator { public: + static constexpr ui32 GetMaxAvailableActorsCount() { + return TLocalProcessKeyStateIndexLimiter::GetMaxKeysCount(); + } + template <class TEnum> static ui32 GetEnumActivityType(const TEnum enumValue) { return TEnumProcessKey<TActorActivityTag, TEnum>::GetIndex(enumValue); @@ -55,5 +60,9 @@ public: static ui32 GetOtherActivityIndex() { return TEnumProcessKey<TActorActivityTag, EInternalActorType>::GetIndex(EInternalActorType::OTHER); } + + static ui32 GetActorActivityIncorrectIndex() { + return TEnumProcessKey<TActorActivityTag, EInternalActorType>::GetIndex(EInternalActorType::INCORRECT_ACTOR_TYPE_INDEX); + } }; } diff --git a/library/cpp/actors/core/mon_stats.h b/library/cpp/actors/core/mon_stats.h index 709dce99265..536628b5187 100644 --- a/library/cpp/actors/core/mon_stats.h +++ b/library/cpp/actors/core/mon_stats.h @@ -2,6 +2,7 @@ #include "defs.h" //#include "actor.h" +#include <library/cpp/actors/util/local_process_key.h> #include <library/cpp/monlib/metrics/histogram_snapshot.h> #include <util/system/hp_timer.h> @@ -109,12 +110,12 @@ namespace NActors { ui64 MailboxPushedOutByEventCount = 0; ui64 NotEnoughCpuExecutions = 0; - TExecutorThreadStats(size_t activityVecSize = 5) // must be not empty as 0 used as default - : ElapsedTicksByActivity(activityVecSize) - , ReceivedEventsByActivity(activityVecSize) - , ActorsAliveByActivity(activityVecSize) - , ScheduledEventsByActivity(activityVecSize) - , StuckActorsByActivity(activityVecSize) + TExecutorThreadStats() // must be not empty as 0 used as default + : ElapsedTicksByActivity(TLocalProcessKeyStateIndexLimiter::GetMaxKeysCount()) + , ReceivedEventsByActivity(TLocalProcessKeyStateIndexLimiter::GetMaxKeysCount()) + , ActorsAliveByActivity(TLocalProcessKeyStateIndexLimiter::GetMaxKeysCount()) + , ScheduledEventsByActivity(TLocalProcessKeyStateIndexLimiter::GetMaxKeysCount()) + , StuckActorsByActivity(TLocalProcessKeyStateIndexLimiter::GetMaxKeysCount()) {} template <typename T> diff --git a/library/cpp/actors/core/worker_context.h b/library/cpp/actors/core/worker_context.h index cc8da2ff777..1ad78e22075 100644 --- a/library/cpp/actors/core/worker_context.h +++ b/library/cpp/actors/core/worker_context.h @@ -34,11 +34,10 @@ namespace NActors { i64 HPStart = 0; ui32 ExecutedEvents = 0; - TWorkerContext(TWorkerId workerId, TCpuId cpuId, size_t activityVecSize) + TWorkerContext(TWorkerId workerId, TCpuId cpuId) : WorkerId(workerId) , CpuId(cpuId) , Lease(WorkerId, NeverExpire) - , WorkerStats(activityVecSize) {} #ifdef ACTORSLIB_COLLECT_EXEC_STATS diff --git a/library/cpp/actors/util/local_process_key.h b/library/cpp/actors/util/local_process_key.h index 1ba756e8d5d..6b330751a72 100644 --- a/library/cpp/actors/util/local_process_key.h +++ b/library/cpp/actors/util/local_process_key.h @@ -9,6 +9,13 @@ #include <util/generic/serialized_enum.h> #include <library/cpp/actors/prof/tag.h> +class TLocalProcessKeyStateIndexLimiter { +public: + static constexpr ui32 GetMaxKeysCount() { + return 10000; + } +}; + template <class T> class TLocalProcessKeyStateIndexConstructor { public: @@ -67,7 +74,7 @@ public: private: - static constexpr ui32 MaxKeysCount = 1000000; + static constexpr ui32 MaxKeysCount = TLocalProcessKeyStateIndexLimiter::GetMaxKeysCount(); private: TVector<TString> Names; |