Skip to content

Commit b0967c3

Browse files
committed
Ydb stable 22-5-10
x-stable-origin-commit: f696baac1a4b8d48eb52b52b35930eef6d0eab42
1 parent 9b78acb commit b0967c3

File tree

304 files changed

+11843
-3143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

304 files changed

+11843
-3143
lines changed

library/cpp/actors/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ target_sources(cpp-actors-core PRIVATE
4242
${CMAKE_SOURCE_DIR}/library/cpp/actors/core/executor_pool_io.cpp
4343
${CMAKE_SOURCE_DIR}/library/cpp/actors/core/executor_pool_united.cpp
4444
${CMAKE_SOURCE_DIR}/library/cpp/actors/core/executor_thread.cpp
45+
${CMAKE_SOURCE_DIR}/library/cpp/actors/core/harmonizer.cpp
4546
${CMAKE_SOURCE_DIR}/library/cpp/actors/core/interconnect.cpp
4647
${CMAKE_SOURCE_DIR}/library/cpp/actors/core/io_dispatcher.cpp
4748
${CMAKE_SOURCE_DIR}/library/cpp/actors/core/log.cpp

library/cpp/actors/core/actor_ut.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,12 @@ Y_UNIT_TEST_SUITE(TestDecorator) {
543543
setup->NodeId = 0;
544544
setup->ExecutorsCount = 1;
545545
setup->Executors.Reset(new TAutoPtr<IExecutorPool>[setup->ExecutorsCount]);
546+
547+
ui64 ts = GetCycleCountFast();
548+
THolder<IHarmonizer> harmonizer(MakeHarmonizer(ts));
546549
for (ui32 i = 0; i < setup->ExecutorsCount; ++i) {
547-
setup->Executors[i] = new TBasicExecutorPool(i, 1, 10, "basic");
550+
setup->Executors[i] = new TBasicExecutorPool(i, 1, 10, "basic", harmonizer.Get());
551+
harmonizer->AddPool(setup->Executors[i].Get());
548552
}
549553
setup->Scheduler = new TBasicSchedulerThread;
550554

library/cpp/actors/core/actorsystem.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,55 @@ namespace NActors {
124124
return 1;
125125
}
126126

127+
virtual i16 GetPriority() const {
128+
return 0;
129+
}
130+
127131
// generic
128132
virtual TAffinity* Affinity() const = 0;
129133

130134
virtual void SetRealTimeMode() const {}
135+
136+
virtual ui32 GetThreadCount() const {
137+
return 1;
138+
};
139+
140+
virtual void SetThreadCount(ui32 threads) {
141+
Y_UNUSED(threads);
142+
}
143+
144+
virtual i16 GetBlockingThreadCount() const {
145+
return 0;
146+
}
147+
148+
virtual i16 GetDefaultThreadCount() const {
149+
return 1;
150+
}
151+
152+
virtual i16 GetMinThreadCount() const {
153+
return 1;
154+
}
155+
156+
virtual i16 GetMaxThreadCount() const {
157+
return 1;
158+
159+
}
160+
161+
virtual bool IsThreadBeingStopped(i16 threadIdx) const {
162+
Y_UNUSED(threadIdx);
163+
return false;
164+
}
165+
166+
virtual double GetThreadConsumedUs(i16 threadIdx) {
167+
Y_UNUSED(threadIdx);
168+
return 0.0;
169+
}
170+
171+
virtual double GetThreadBookedUs(i16 threadIdx) {
172+
Y_UNUSED(threadIdx);
173+
return 0.0;
174+
}
175+
131176
};
132177

133178
// could be proxy to in-pool schedulers (for NUMA-aware executors)

library/cpp/actors/core/balancer.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
#include "probes.h"
44

5-
#include <library/cpp/actors/util/intrinsics.h>
5+
#include <library/cpp/actors/util/cpu_load_log.h>
66
#include <library/cpp/actors/util/datetime.h>
7+
#include <library/cpp/actors/util/intrinsics.h>
78

89
#include <util/system/spinlock.h>
910

@@ -27,11 +28,11 @@ namespace NActors {
2728

2829
TLevel() {}
2930

30-
TLevel(const TBalancingConfig& cfg, TPoolId poolId, ui64 currentCpus, double cpuIdle) {
31+
TLevel(const TBalancingConfig& cfg, TPoolId poolId, ui64 currentCpus, double cpuIdle, ui64 addLatencyUs, ui64 worstLatencyUs) {
3132
ScaleFactor = double(currentCpus) / cfg.Cpus;
32-
if (cpuIdle > 1.3) { // TODO: add a better underload criterion, based on estimated latency w/o 1 cpu
33+
if ((worstLatencyUs + addLatencyUs) < 2000 && cpuIdle > 1.0) { // Uderload criterion, based on estimated latency w/o 1 cpu
3334
LoadClass = Underloaded;
34-
} else if (cpuIdle < 0.2) { // TODO: add a better overload criterion, based on latency
35+
} else if (worstLatencyUs > 2000 || cpuIdle < 0.2) { // Overload criterion, based on latency
3536
LoadClass = Overloaded;
3637
} else {
3738
LoadClass = Moderate;
@@ -82,6 +83,8 @@ namespace NActors {
8283
TBalancerConfig Config;
8384

8485
public:
86+
87+
ui64 GetPeriodUs() override;
8588
// Setup
8689
TBalancer(const TBalancerConfig& config, const TVector<TUnitedExecutorPoolConfig>& unitedPools, ui64 ts);
8790
bool AddCpu(const TCpuAllocation& cpuAlloc, TCpuState* cpu) override;
@@ -238,9 +241,12 @@ namespace NActors {
238241
}
239242

240243
// Compute levels
241-
pool.CurLevel = TLevel(pool.Config, pool.PoolId, pool.CurrentCpus, pool.CpuIdle);
242-
pool.AddLevel = TLevel(pool.Config, pool.PoolId, pool.CurrentCpus + 1, pool.CpuIdle); // we expect taken cpu to became utilized
243-
pool.SubLevel = TLevel(pool.Config, pool.PoolId, pool.CurrentCpus - 1, pool.CpuIdle - 1);
244+
pool.CurLevel = TLevel(pool.Config, pool.PoolId, pool.CurrentCpus, pool.CpuIdle,
245+
pool.Next.ExpectedLatencyIncreaseUs, pool.Next.WorstActivationTimeUs);
246+
pool.AddLevel = TLevel(pool.Config, pool.PoolId, pool.CurrentCpus + 1, pool.CpuIdle,
247+
0, pool.Next.WorstActivationTimeUs); // we expect taken cpu to became utilized
248+
pool.SubLevel = TLevel(pool.Config, pool.PoolId, pool.CurrentCpus - 1, pool.CpuIdle - 1,
249+
pool.Next.ExpectedLatencyIncreaseUs, pool.Next.WorstActivationTimeUs);
244250

245251
// Prepare for balancing
246252
pool.PrevCpus = pool.CurrentCpus;
@@ -263,7 +269,7 @@ namespace NActors {
263269
TPool& from = **fromIter;
264270
if (from.CurrentCpus == from.PrevCpus && // if not balanced yet
265271
from.CurrentCpus > from.Config.MinCpus && // and constraints would not be violated
266-
from.SubLevel.Importance < to.AddLevel.Importance) // and which of two pools is more important would not change after cpu movement
272+
from.SubLevel.Importance <= to.AddLevel.Importance) // and which of two pools is more important would not change after cpu movement
267273
{
268274
MoveCpu(from, to);
269275
from.CurrentCpus--;
@@ -295,6 +301,10 @@ namespace NActors {
295301
Lock.Release();
296302
}
297303

304+
ui64 TBalancer::GetPeriodUs() {
305+
return Config.PeriodUs;
306+
}
307+
298308
IBalancer* MakeBalancer(const TBalancerConfig& config, const TVector<TUnitedExecutorPoolConfig>& unitedPools, ui64 ts) {
299309
return new TBalancer(config, unitedPools, ts);
300310
}

library/cpp/actors/core/balancer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace NActors {
1010
ui64 Ts = 0; // Measurement timestamp
1111
ui64 CpuUs = 0; // Total cpu microseconds consumed by pool on all cpus since start
1212
ui64 IdleUs = ui64(-1); // Total cpu microseconds in spinning or waiting on futex
13+
ui64 WorstActivationTimeUs = 0;
14+
ui64 ExpectedLatencyIncreaseUs = 0;
1315
};
1416

1517
// Pool cpu balancer
@@ -20,6 +22,7 @@ namespace NActors {
2022
virtual void SetPoolStats(TPoolId pool, const TBalancerStats& stats) = 0;
2123
virtual void Balance() = 0;
2224
virtual void Unlock() = 0;
25+
virtual ui64 GetPeriodUs() = 0;
2326
// TODO: add method for reconfiguration on fly
2427
};
2528

library/cpp/actors/core/config.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ namespace NActors {
4141
ui32 EventsPerMailbox = DEFAULT_EVENTS_PER_MAILBOX;
4242
int RealtimePriority = 0;
4343
ui32 MaxActivityType = 5;
44+
i16 MinThreadCount = 0;
45+
i16 MaxThreadCount = 0;
46+
i16 DefaultThreadCount = 0;
47+
i16 Priority = 0;
4448
};
4549

4650
struct TIOExecutorPoolConfig {
@@ -88,11 +92,18 @@ namespace NActors {
8892
TBalancerConfig Balancer;
8993
};
9094

95+
struct TSelfPingInfo {
96+
NMonitoring::TDynamicCounters::TCounterPtr AvgPingCounter;
97+
NMonitoring::TDynamicCounters::TCounterPtr AvgPingCounterWithSmallWindow;
98+
ui32 MaxAvgPingUs;
99+
};
100+
91101
struct TCpuManagerConfig {
92102
TUnitedWorkersConfig UnitedWorkers;
93103
TVector<TBasicExecutorPoolConfig> Basic;
94104
TVector<TIOExecutorPoolConfig> IO;
95105
TVector<TUnitedExecutorPoolConfig> United;
106+
TVector<TSelfPingInfo> PingInfoByPool;
96107

97108
ui32 GetExecutorsCount() const {
98109
return Basic.size() + IO.size() + United.size();

library/cpp/actors/core/cpu_manager.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@ namespace NActors {
1616
UnitedWorkers.Reset(new TUnitedWorkers(Config.UnitedWorkers, Config.United, allocation, Balancer.Get()));
1717
}
1818

19+
ui64 ts = GetCycleCountFast();
20+
Harmonizer.Reset(MakeHarmonizer(ts));
21+
1922
Executors.Reset(new TAutoPtr<IExecutorPool>[ExecutorPoolCount]);
2023

2124
for (ui32 excIdx = 0; excIdx != ExecutorPoolCount; ++excIdx) {
2225
Executors[excIdx].Reset(CreateExecutorPool(excIdx));
26+
if (excIdx < Config.PingInfoByPool.size()) {
27+
Harmonizer->AddPool(Executors[excIdx].Get(), &Config.PingInfoByPool[excIdx]);
28+
} else {
29+
Harmonizer->AddPool(Executors[excIdx].Get());
30+
}
2331
}
2432
}
2533

@@ -89,7 +97,7 @@ namespace NActors {
8997
IExecutorPool* TCpuManager::CreateExecutorPool(ui32 poolId) {
9098
for (TBasicExecutorPoolConfig& cfg : Config.Basic) {
9199
if (cfg.PoolId == poolId) {
92-
return new TBasicExecutorPool(cfg);
100+
return new TBasicExecutorPool(cfg, Harmonizer.Get());
93101
}
94102
}
95103
for (TIOExecutorPoolConfig& cfg : Config.IO) {

library/cpp/actors/core/cpu_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "actorsystem.h"
4+
#include "harmonizer.h"
45
#include "executor_pool_basic.h"
56
#include "executor_pool_io.h"
67
#include "executor_pool_united.h"
@@ -11,6 +12,7 @@ namespace NActors {
1112
TArrayHolder<TAutoPtr<IExecutorPool>> Executors;
1213
THolder<TUnitedWorkers> UnitedWorkers;
1314
THolder<IBalancer> Balancer;
15+
THolder<IHarmonizer> Harmonizer;
1416
TCpuManagerConfig Config;
1517
public:
1618
explicit TCpuManager(THolder<TActorSystemSetup>& setup)

0 commit comments

Comments
 (0)