Skip to content

merge 24-3: add ring queue config #8780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ydb/core/driver_lib/run/kikimr_services_initializers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ void AddExecutorPool(
TBasicExecutorPoolConfig basic;
basic.PoolId = poolId;
basic.PoolName = poolConfig.GetName();
basic.UseRingQueue = systemConfig.HasUseRingQueue() && systemConfig.GetUseRingQueue();
if (poolConfig.HasMaxAvgPingDeviation()) {
auto poolGroup = counters->GetSubgroup("execpool", basic.PoolName);
auto &poolInfo = cpuManager.PingInfoByPool[poolId];
Expand Down
1 change: 1 addition & 0 deletions ydb/core/protos/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ message TActorSystemConfig {
optional ENodeType NodeType = 14 [default = COMPUTE];
optional uint32 ForceIOPoolThreads = 17;
optional bool UseSharedThreads = 18;
optional bool UseRingQueue = 19;

optional bool MonitorStuckActors = 15;
optional EActorSystemProfile ActorSystemProfile = 16;
Expand Down
2 changes: 2 additions & 0 deletions ydb/library/actors/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace NActors {
i16 SoftProcessingDurationTs = 0;
EASProfile ActorSystemProfile = EASProfile::Default;
bool HasSharedThread = false;
bool UseRingQueue = false;
};

struct TSharedExecutorPoolConfig {
Expand All @@ -47,6 +48,7 @@ namespace NActors {
TString PoolName;
ui32 Threads = 1;
TCpuMask Affinity; // Executor thread affinity
bool UseRingQueue = false;
};

struct TSelfPingInfo {
Expand Down
15 changes: 9 additions & 6 deletions ydb/library/actors/core/executor_pool_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,20 @@ namespace NActors {
}
#endif

TExecutorPoolBase::TExecutorPoolBase(ui32 poolId, ui32 threads, TAffinity* affinity)
TExecutorPoolBase::TExecutorPoolBase(ui32 poolId, ui32 threads, TAffinity* affinity, bool useRingQueue)
: TExecutorPoolBaseMailboxed(poolId)
, PoolThreads(threads)
, ThreadsAffinity(affinity)
#ifdef RING_ACTIVATION_QUEUE
, Activations(threads == 1)
#endif
{}
{
if (useRingQueue) {
Activations.emplace<TRingActivationQueue>(threads == 1);
} else {
Activations.emplace<TUnorderedCacheActivationQueue>();
}
}

TExecutorPoolBase::~TExecutorPoolBase() {
while (Activations.Pop(0))
while (std::visit([](auto &x){return x.Pop(0);}, Activations))
;
}

Expand Down
11 changes: 3 additions & 8 deletions ydb/library/actors/core/executor_pool_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,16 @@ namespace NActors {

class TExecutorPoolBase: public TExecutorPoolBaseMailboxed {
protected:

#ifdef RING_ACTIVATION_QUEUE
using TActivationQueue = TRingActivationQueue;
#else
using TActivationQueue = TUnorderedCache<ui32, 512, 4>;
#endif
using TUnorderedCacheActivationQueue = TUnorderedCache<ui32, 512, 4>;

const i16 PoolThreads;
TIntrusivePtr<TAffinity> ThreadsAffinity;
TAtomic Semaphore = 0;
TActivationQueue Activations;
std::variant<TUnorderedCacheActivationQueue, TRingActivationQueue> Activations;
TAtomic ActivationsRevolvingCounter = 0;
std::atomic_bool StopFlag = false;
public:
TExecutorPoolBase(ui32 poolId, ui32 threads, TAffinity* affinity);
TExecutorPoolBase(ui32 poolId, ui32 threads, TAffinity* affinity, bool useRingQueue);
~TExecutorPoolBase();
void ScheduleActivation(ui32 activation) override;
void SpecificScheduleActivation(ui32 activation) override;
Expand Down
9 changes: 5 additions & 4 deletions ydb/library/actors/core/executor_pool_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace NActors {
}

TBasicExecutorPool::TBasicExecutorPool(const TBasicExecutorPoolConfig& cfg, IHarmonizer *harmonizer, TExecutorPoolJail *jail)
: TExecutorPoolBase(cfg.PoolId, cfg.Threads, new TAffinity(cfg.Affinity))
: TExecutorPoolBase(cfg.PoolId, cfg.Threads, new TAffinity(cfg.Affinity), cfg.UseRingQueue)
, DefaultSpinThresholdCycles(cfg.SpinThreshold * NHPTimer::GetCyclesPerSecond() * 0.000001) // convert microseconds to cycles
, SpinThresholdCycles(DefaultSpinThresholdCycles)
, SpinThresholdCyclesPerThread(new NThreading::TPadded<std::atomic<ui64>>[cfg.Threads])
Expand Down Expand Up @@ -235,7 +235,7 @@ namespace NActors {
}
} else {
TInternalActorTypeGuard<EInternalActorSystemActivity::ACTOR_SYSTEM_GET_ACTIVATION_FROM_QUEUE, false> activityGuard;
if (const ui32 activation = Activations.Pop(++revolvingCounter)) {
if (const ui32 activation = std::visit([&revolvingCounter](auto &x) {return x.Pop(++revolvingCounter);}, Activations)) {
if (workerId >= 0) {
Threads[workerId].SetWork();
} else {
Expand Down Expand Up @@ -308,8 +308,9 @@ namespace NActors {

void TBasicExecutorPool::ScheduleActivationExCommon(ui32 activation, ui64 revolvingCounter, TAtomic x) {
TSemaphore semaphore = TSemaphore::GetSemaphore(x);

Activations.Push(activation, revolvingCounter);
std::visit([activation, revolvingCounter](auto &x) {
x.Push(activation, revolvingCounter);
}, Activations);
bool needToWakeUp = false;
bool needToChangeOldSemaphore = true;

Expand Down
13 changes: 8 additions & 5 deletions ydb/library/actors/core/executor_pool_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <ydb/library/actors/util/datetime.h>

namespace NActors {
TIOExecutorPool::TIOExecutorPool(ui32 poolId, ui32 threads, const TString& poolName, TAffinity* affinity)
: TExecutorPoolBase(poolId, threads, affinity)
TIOExecutorPool::TIOExecutorPool(ui32 poolId, ui32 threads, const TString& poolName, TAffinity* affinity, bool useRingQueue)
: TExecutorPoolBase(poolId, threads, affinity, useRingQueue)
, Threads(new TExecutorThreadCtx[threads])
, PoolName(poolName)
{}
Expand All @@ -17,7 +17,8 @@ namespace NActors {
cfg.PoolId,
cfg.Threads,
cfg.PoolName,
new TAffinity(cfg.Affinity)
new TAffinity(cfg.Affinity),
cfg.UseRingQueue
)
{
Harmonizer = harmonizer;
Expand Down Expand Up @@ -53,7 +54,7 @@ namespace NActors {
}

while (!StopFlag.load(std::memory_order_acquire)) {
if (const ui32 activation = Activations.Pop(++revolvingCounter)) {
if (const ui32 activation = std::visit([&revolvingCounter](auto &x){return x.Pop(++revolvingCounter);}, Activations)) {
return activation;
}
SpinLockPause();
Expand Down Expand Up @@ -86,7 +87,9 @@ namespace NActors {
}

void TIOExecutorPool::ScheduleActivationEx(ui32 activation, ui64 revolvingWriteCounter) {
Activations.Push(activation, revolvingWriteCounter);
std::visit([activation, revolvingWriteCounter](auto &x) {
x.Push(activation, revolvingWriteCounter);
}, Activations);
const TAtomic x = AtomicIncrement(Semaphore);
if (x <= 0) {
for (;; ++revolvingWriteCounter) {
Expand Down
2 changes: 1 addition & 1 deletion ydb/library/actors/core/executor_pool_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +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);
TIOExecutorPool(ui32 poolId, ui32 threads, const TString& poolName = "", TAffinity* affinity = nullptr, bool useRingQueue = false);
explicit TIOExecutorPool(const TIOExecutorPoolConfig& cfg, IHarmonizer *harmonizer = nullptr);
~TIOExecutorPool();

Expand Down
Loading