6
6
7
7
namespace NKikimr ::NKqp::NComputeActor {
8
8
9
+
9
10
struct TMemoryQuotaManager : public NYql ::NDq::TGuaranteeQuotaManager {
10
11
11
12
TMemoryQuotaManager (std::shared_ptr<NRm::IKqpResourceManager> resourceManager
@@ -26,7 +27,10 @@ struct TMemoryQuotaManager : public NYql::NDq::TGuaranteeQuotaManager {
26
27
}
27
28
28
29
~TMemoryQuotaManager () override {
29
- State->OnTaskTerminate (TxId, TaskId, Success);
30
+ if (State) {
31
+ State->OnTaskTerminate (TxId, TaskId, Success);
32
+ }
33
+
30
34
ResourceManager->FreeResources (TxId, TaskId);
31
35
}
32
36
@@ -77,66 +81,86 @@ struct TMemoryQuotaManager : public NYql::NDq::TGuaranteeQuotaManager {
77
81
};
78
82
79
83
class TKqpCaFactory : public IKqpNodeComputeActorFactory {
80
- NKikimrConfig::TTableServiceConfig::TResourceManager Config;
81
84
std::shared_ptr<NRm::IKqpResourceManager> ResourceManager_;
82
85
NYql::NDq::IDqAsyncIoFactory::TPtr AsyncIoFactory;
83
86
const std::optional<TKqpFederatedQuerySetup> FederatedQuerySetup;
84
87
88
+ std::atomic<ui64> MkqlLightProgramMemoryLimit = 0 ;
89
+ std::atomic<ui64> MkqlHeavyProgramMemoryLimit = 0 ;
90
+ std::atomic<ui64> MinChannelBufferSize = 0 ;
91
+ std::atomic<ui64> ReasonableSpillingTreshold = 0 ;
92
+
85
93
public:
86
94
TKqpCaFactory (const NKikimrConfig::TTableServiceConfig::TResourceManager& config,
87
95
std::shared_ptr<NRm::IKqpResourceManager> resourceManager,
88
96
NYql::NDq::IDqAsyncIoFactory::TPtr asyncIoFactory,
89
97
const std::optional<TKqpFederatedQuerySetup> federatedQuerySetup)
90
- : Config(config)
91
- , ResourceManager_(resourceManager)
98
+ : ResourceManager_(resourceManager)
92
99
, AsyncIoFactory(asyncIoFactory)
93
100
, FederatedQuerySetup(federatedQuerySetup)
94
- {}
101
+ {
102
+ ApplyConfig (config);
103
+ }
95
104
96
- TActorId CreateKqpComputeActor (const TActorId& executerId, ui64 txId, NYql::NDqProto::TDqTask* dqTask,
97
- const NYql::NDq::TComputeRuntimeSettings& settings,
98
- NWilson::TTraceId traceId, TIntrusivePtr<NActors::TProtoArenaHolder> arena, const TString& serializedGUCSettings,
99
- TComputeStagesWithScan& computesByStage, ui64 outputChunkMaxSize, std::shared_ptr<IKqpNodeState> state,
100
- NRm::EKqpMemoryPool memoryPool, ui32 numberOfTasks)
105
+ void ApplyConfig (const NKikimrConfig::TTableServiceConfig::TResourceManager& config)
101
106
{
107
+ MkqlLightProgramMemoryLimit.store (config.GetMkqlLightProgramMemoryLimit ());
108
+ MkqlHeavyProgramMemoryLimit.store (config.GetMkqlHeavyProgramMemoryLimit ());
109
+ MinChannelBufferSize.store (config.GetMinChannelBufferSize ());
110
+ ReasonableSpillingTreshold.store (config.GetReasonableSpillingTreshold ());
111
+ }
112
+
113
+ TActorId CreateKqpComputeActor (TCreateArgs&& args) {
102
114
NYql::NDq::TComputeMemoryLimits memoryLimits;
103
115
memoryLimits.ChannelBufferSize = 0 ;
104
- memoryLimits.MkqlLightProgramMemoryLimit = Config. GetMkqlLightProgramMemoryLimit ();
105
- memoryLimits.MkqlHeavyProgramMemoryLimit = Config. GetMkqlHeavyProgramMemoryLimit ();
116
+ memoryLimits.MkqlLightProgramMemoryLimit = MkqlLightProgramMemoryLimit. load ();
117
+ memoryLimits.MkqlHeavyProgramMemoryLimit = MkqlHeavyProgramMemoryLimit. load ();
106
118
107
- auto estimation = EstimateTaskResources (*dqTask, Config, numberOfTasks );
119
+ auto estimation = ResourceManager_-> EstimateTaskResources (*args. Task , args. NumberOfTasks );
108
120
109
121
{
110
122
ui32 inputChannelsCount = 0 ;
111
- for (auto && i : dqTask ->GetInputs ()) {
123
+ for (auto && i : args. Task ->GetInputs ()) {
112
124
inputChannelsCount += i.ChannelsSize ();
113
125
}
114
126
115
- memoryLimits.ChannelBufferSize = std::max<ui32>(estimation.ChannelBufferMemoryLimit / std::max<ui32>(1 , inputChannelsCount), Config. GetMinChannelBufferSize ());
116
- memoryLimits.OutputChunkMaxSize = outputChunkMaxSize ;
127
+ memoryLimits.ChannelBufferSize = std::max<ui32>(estimation.ChannelBufferMemoryLimit / std::max<ui32>(1 , inputChannelsCount), MinChannelBufferSize. load ());
128
+ memoryLimits.OutputChunkMaxSize = args. OutputChunkMaxSize ;
117
129
AFL_DEBUG (NKikimrServices::KQP_COMPUTE)(" event" , " channel_info" )
118
130
(" ch_size" , estimation.ChannelBufferMemoryLimit )
119
131
(" ch_count" , estimation.ChannelBuffersCount )
120
132
(" ch_limit" , memoryLimits.ChannelBufferSize )
121
- (" inputs" , dqTask ->InputsSize ())
133
+ (" inputs" , args. Task ->InputsSize ())
122
134
(" input_channels_count" , inputChannelsCount);
123
135
}
124
136
125
- auto & taskOpts = dqTask ->GetProgram ().GetSettings ();
137
+ auto & taskOpts = args. Task ->GetProgram ().GetSettings ();
126
138
auto limit = taskOpts.GetHasMapJoin () || taskOpts.GetHasStateAggregation ()
127
139
? memoryLimits.MkqlHeavyProgramMemoryLimit
128
140
: memoryLimits.MkqlLightProgramMemoryLimit ;
129
141
130
142
memoryLimits.MemoryQuotaManager = std::make_shared<TMemoryQuotaManager>(
131
143
ResourceManager_,
132
- memoryPool ,
133
- std::move (state ),
134
- txId ,
135
- dqTask ->GetId (),
144
+ args. MemoryPool ,
145
+ std::move (args. State ),
146
+ args. TxId ,
147
+ args. Task ->GetId (),
136
148
limit,
137
- Config.GetReasonableSpillingTreshold ());
149
+ ReasonableSpillingTreshold.load ());
150
+
151
+ auto runtimeSettings = args.RuntimeSettings ;
152
+ runtimeSettings.ExtraMemoryAllocationPool = args.MemoryPool ;
153
+ runtimeSettings.UseSpilling = args.WithSpilling ;
154
+ runtimeSettings.StatsMode = args.StatsMode ;
155
+
156
+ if (args.Deadline ) {
157
+ runtimeSettings.Timeout = args.Deadline - TAppData::TimeProvider->Now ();
158
+ }
159
+
160
+ if (args.RlPath ) {
161
+ runtimeSettings.RlPath = args.RlPath ;
162
+ }
138
163
139
- auto runtimeSettings = settings;
140
164
NYql::NDq::IMemoryQuotaManager::TWeakPtr memoryQuotaManager = memoryLimits.MemoryQuotaManager ;
141
165
runtimeSettings.TerminateHandler = [memoryQuotaManager]
142
166
(bool success, const NYql::TIssues& issues) {
@@ -157,29 +181,32 @@ class TKqpCaFactory : public IKqpNodeComputeActorFactory {
157
181
};
158
182
159
183
ETableKind tableKind = ETableKind::Unknown;
160
- if (dqTask->HasMetaId ()) {
161
- YQL_ENSURE (computesByStage.GetMetaById (*dqTask, meta) || dqTask->GetMeta ().UnpackTo (&meta), " cannot take meta on MetaId exists in tasks" );
184
+ if (args.Task ->HasMetaId ()) {
185
+ YQL_ENSURE (args.ComputesByStages );
186
+ YQL_ENSURE (args.ComputesByStages ->GetMetaById (*args.Task , meta) || args.Task ->GetMeta ().UnpackTo (&meta), " cannot take meta on MetaId exists in tasks" );
162
187
tableKind = tableKindExtract (meta);
163
- } else if (dqTask ->GetMeta ().UnpackTo (&meta)) {
188
+ } else if (args. Task ->GetMeta ().UnpackTo (&meta)) {
164
189
tableKind = tableKindExtract (meta);
165
190
}
166
191
167
192
if (tableKind == ETableKind::Datashard || tableKind == ETableKind::Olap) {
168
- auto & info = computesByStage.UpsertTaskWithScan (*dqTask, meta, !AppData ()->FeatureFlags .GetEnableSeparationComputeActorsFromRead ());
169
- IActor* computeActor = CreateKqpScanComputeActor (executerId, txId, dqTask,
193
+ YQL_ENSURE (args.ComputesByStages );
194
+ auto & info = args.ComputesByStages ->UpsertTaskWithScan (*args.Task , meta, !AppData ()->FeatureFlags .GetEnableSeparationComputeActorsFromRead ());
195
+ IActor* computeActor = CreateKqpScanComputeActor (args.ExecuterId , args.TxId , args.Task ,
170
196
AsyncIoFactory, runtimeSettings, memoryLimits,
171
- std::move (traceId ), std::move (arena ));
197
+ std::move (args. TraceId ), std::move (args. Arena ));
172
198
TActorId result = TlsActivationContext->Register (computeActor);
173
199
info.MutableActorIds ().emplace_back (result);
174
200
return result;
175
201
} else {
176
202
std::shared_ptr<TGUCSettings> GUCSettings;
177
- if (!serializedGUCSettings .empty ()) {
178
- GUCSettings = std::make_shared<TGUCSettings>(serializedGUCSettings );
203
+ if (!args. SerializedGUCSettings .empty ()) {
204
+ GUCSettings = std::make_shared<TGUCSettings>(args. SerializedGUCSettings );
179
205
}
180
- IActor* computeActor = ::NKikimr::NKqp::CreateKqpComputeActor (executerId, txId, dqTask, AsyncIoFactory,
181
- runtimeSettings, memoryLimits, std::move (traceId), std::move (arena), FederatedQuerySetup, GUCSettings);
182
- return TlsActivationContext->Register (computeActor);
206
+ IActor* computeActor = ::NKikimr::NKqp::CreateKqpComputeActor (args.ExecuterId , args.TxId , args.Task , AsyncIoFactory,
207
+ runtimeSettings, memoryLimits, std::move (args.TraceId ), std::move (args.Arena ), FederatedQuerySetup, GUCSettings);
208
+ return args.ShareMailbox ? TlsActivationContext->AsActorContext ().RegisterWithSameMailbox (computeActor) :
209
+ TlsActivationContext->AsActorContext ().Register (computeActor);
183
210
}
184
211
}
185
212
};
0 commit comments