Skip to content

Commit efd8a43

Browse files
authored
Per query cpu limits (#8520)
1 parent 735f365 commit efd8a43

File tree

9 files changed

+526
-154
lines changed

9 files changed

+526
-154
lines changed

ydb/core/kqp/counters/kqp_counters.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,8 @@ TKqpCounters::TKqpCounters(const ::NMonitoring::TDynamicCounterPtr& counters, co
830830
FullScansExecuted = KqpGroup->GetCounter("FullScans", true);
831831

832832
SchedulerThrottled = KqpGroup->GetCounter("NodeScheduler/ThrottledUs", true);
833+
SchedulerGroupsCount = KqpGroup->GetCounter("NodeScheduler/GroupsCount", false);
834+
SchedulerValuesCount = KqpGroup->GetCounter("NodeScheduler/ValuesCount", false);
833835
SchedulerCapacity = KqpGroup->GetCounter("NodeScheduler/Capacity");
834836
ComputeActorExecutions = KqpGroup->GetHistogram("NodeScheduler/BatchUs", NMonitoring::ExponentialHistogram(20, 2, 1));
835837
ComputeActorDelays = KqpGroup->GetHistogram("NodeScheduler/Delays", NMonitoring::ExponentialHistogram(20, 2, 1));

ydb/core/kqp/counters/kqp_counters.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ class TKqpCounters : public TKqpCountersBase, public NYql::NDq::TSpillingCounter
416416
NMonitoring::THistogramPtr ComputeActorDelays;
417417
::NMonitoring::TDynamicCounters::TCounterPtr ThrottledActorsSpuriousActivations;
418418
NMonitoring::THistogramPtr SchedulerDelays;
419+
NMonitoring::TDynamicCounters::TCounterPtr SchedulerGroupsCount;
420+
NMonitoring::TDynamicCounters::TCounterPtr SchedulerValuesCount;
419421

420422
// Sequences counters
421423
::NMonitoring::TDynamicCounters::TCounterPtr SequencerActorsCount;

ydb/core/kqp/executer_actor/kqp_planner.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ std::unique_ptr<TEvKqpNode::TEvStartKqpTasksRequest> TKqpPlanner::SerializeReque
237237
request.SetDatabase(Database);
238238
if (UserRequestContext->PoolConfig.has_value()) {
239239
request.SetMemoryPoolPercent(UserRequestContext->PoolConfig->QueryMemoryLimitPercentPerNode);
240-
request.SetMaxCpuShare(UserRequestContext->PoolConfig->TotalCpuLimitPercentPerNode / 100.0);
240+
request.SetPoolMaxCpuShare(UserRequestContext->PoolConfig->TotalCpuLimitPercentPerNode / 100.0);
241+
if (UserRequestContext->PoolConfig->QueryCpuLimitPercentPerNode >= 0) {
242+
request.SetQueryCpuShare(UserRequestContext->PoolConfig->QueryCpuLimitPercentPerNode / 100.0);
243+
}
241244
}
242245

243246
return result;

ydb/core/kqp/node_service/kqp_node_service.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,26 @@ class TKqpNodeService : public TActorBootstrapped<TKqpNodeService> {
195195

196196
auto schedulerNow = TlsActivationContext->Monotonic();
197197

198+
TString schedulerGroup = msg.GetSchedulerGroup();
199+
200+
if (SchedulerOptions.Scheduler->Disabled(schedulerGroup)) {
201+
auto share = msg.GetPoolMaxCpuShare();
202+
if (share <= 0 && msg.HasQueryCpuShare()) {
203+
share = 1.0;
204+
}
205+
if (share > 0) {
206+
Scheduler->UpdateGroupShare(schedulerGroup, share, schedulerNow);
207+
Send(SchedulerActorId, new TEvSchedulerNewPool(msg.GetDatabase(), schedulerGroup));
208+
} else {
209+
schedulerGroup = "";
210+
}
211+
}
212+
213+
std::optional<ui64> querySchedulerGroup;
214+
if (msg.HasQueryCpuShare() && schedulerGroup) {
215+
querySchedulerGroup = Scheduler->MakePerQueryGroup(schedulerNow, msg.GetQueryCpuShare(), schedulerGroup);
216+
}
217+
198218
// start compute actors
199219
TMaybe<NYql::NDqProto::TRlPath> rlPath = Nothing();
200220
if (msgRtSettings.HasRlPath()) {
@@ -208,30 +228,21 @@ class TKqpNodeService : public TActorBootstrapped<TKqpNodeService> {
208228

209229
const ui32 tasksCount = msg.GetTasks().size();
210230
for (auto& dqTask: *msg.MutableTasks()) {
211-
TString group = msg.GetSchedulerGroup();
212-
213231
TComputeActorSchedulingOptions schedulingTaskOptions {
214232
.Now = schedulerNow,
215233
.SchedulerActorId = SchedulerActorId,
216234
.Scheduler = Scheduler.get(),
217-
.Group = group,
235+
.Group = schedulerGroup,
218236
.Weight = 1,
219-
.NoThrottle = false,
237+
.NoThrottle = schedulerGroup.empty(),
220238
.Counters = Counters
221239
};
222240

223-
if (SchedulerOptions.Scheduler->Disabled(group)) {
224-
auto share = msg.GetMaxCpuShare();
225-
if (share > 0) {
226-
Scheduler->UpdateMaxShare(group, share, schedulerNow);
227-
Send(SchedulerActorId, new TEvSchedulerNewPool(msg.GetDatabase(), group, share));
228-
} else {
229-
schedulingTaskOptions.NoThrottle = true;
230-
}
231-
}
232-
233241
if (!schedulingTaskOptions.NoThrottle) {
234242
schedulingTaskOptions.Handle = SchedulerOptions.Scheduler->Enroll(schedulingTaskOptions.Group, schedulingTaskOptions.Weight, schedulingTaskOptions.Now);
243+
if (querySchedulerGroup) {
244+
Scheduler->AddToGroup(schedulerNow, *querySchedulerGroup, schedulingTaskOptions.Handle);
245+
}
235246
}
236247

237248
auto result = CaFactory_->CreateKqpComputeActor({

0 commit comments

Comments
 (0)