@@ -51,11 +51,27 @@ class TWithMemoryControllerServer : public TServer {
51
51
ProcessMemoryInfoProvider = MakeIntrusive<TProcessMemoryInfoProvider>();
52
52
ProcessMemoryInfo = &ProcessMemoryInfoProvider->ProcessMemoryInfo ;
53
53
54
+ // copy-paste from TMemoryControllerInitializer::InitializeServices
55
+ NMemory::TResourceBrokerConfig resourceBrokerSelfConfig;
56
+ const auto & resourceBrokerConfig = Settings->AppConfig ->GetResourceBrokerConfig ();
57
+ if (resourceBrokerConfig.HasResourceLimit () && resourceBrokerConfig.GetResourceLimit ().HasMemory ()) {
58
+ resourceBrokerSelfConfig.LimitBytes = resourceBrokerConfig.GetResourceLimit ().GetMemory ();
59
+ }
60
+ for (const auto & queue : resourceBrokerConfig.GetQueues ()) {
61
+ if (queue.GetName () == NLocalDb::KqpResourceManagerQueue) {
62
+ if (queue.HasLimit () && queue.GetLimit ().HasMemory ()) {
63
+ resourceBrokerSelfConfig.QueryExecutionLimitBytes = queue.GetLimit ().GetMemory ();
64
+ }
65
+ }
66
+ }
67
+ Cerr << " ResourceBrokerSelfConfig: " << resourceBrokerSelfConfig.ToString () << Endl;
68
+
54
69
for (ui32 nodeIndex = 0 ; nodeIndex < Runtime->GetNodeCount (); ++nodeIndex) {
55
70
Runtime->AddLocalService (MakeMemoryControllerId (nodeIndex),
56
71
TActorSetupCmd (
57
72
CreateMemoryController (TDuration::Seconds (1 ), (TIntrusivePtr<IProcessMemoryInfoProvider>)ProcessMemoryInfoProvider,
58
- {}, Runtime->GetDynamicCounters ()),
73
+ Settings->AppConfig ->GetMemoryControllerConfig (), resourceBrokerSelfConfig,
74
+ Runtime->GetDynamicCounters ()),
59
75
TMailboxType::ReadAsFilled,
60
76
0 ),
61
77
nodeIndex);
@@ -167,9 +183,9 @@ Y_UNIT_TEST(Counters_NoHardLimit) {
167
183
UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Stats/CGroupLimit" )->Val (), 0_MB);
168
184
UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Stats/MemTotal" )->Val (), 0_MB);
169
185
UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Stats/AllocatedMemory" )->Val (), 0_MB);
170
- UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Stats/HardLimit" )->Val (), 512_MB ); // default
171
- UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Stats/SoftLimit" )->Val (), 384_MB );
172
- UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Stats/TargetUtilization" )->Val (), 256_MB );
186
+ UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Stats/HardLimit" )->Val (), 2_GB ); // default
187
+ UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Stats/SoftLimit" )->Val (), 1536_MB );
188
+ UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Stats/TargetUtilization" )->Val (), 1_GB );
173
189
174
190
server->ProcessMemoryInfo ->CGroupLimit = 200_MB;
175
191
runtime.SimulateSleep (TDuration::Seconds (2 ));
@@ -401,12 +417,16 @@ Y_UNIT_TEST(ResourceBroker) {
401
417
runtime.Send (new IEventHandle (MakeResourceBrokerID (), sender, new TEvResourceBroker::TEvConfigRequest (NLocalDb::KqpResourceManagerQueue)));
402
418
auto config = runtime.GrabEdgeEvent <TEvResourceBroker::TEvConfigResponse>(handle);
403
419
UNIT_ASSERT_VALUES_EQUAL (config->QueueConfig ->GetLimit ().GetMemory (), 150_MB);
420
+ UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Consumer/QueryExecution/Limit" )->Val (), 150_MB);
421
+ UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Stats/ActivitiesLimitBytes" )->Val (), 300_MB);
404
422
405
423
server->ProcessMemoryInfo ->CGroupLimit = 500_MB;
406
424
runtime.SimulateSleep (TDuration::Seconds (2 ));
407
425
runtime.Send (new IEventHandle (MakeResourceBrokerID (), sender, new TEvResourceBroker::TEvConfigRequest (NLocalDb::KqpResourceManagerQueue)));
408
426
config = runtime.GrabEdgeEvent <TEvResourceBroker::TEvConfigResponse>(handle);
409
427
UNIT_ASSERT_VALUES_EQUAL (config->QueueConfig ->GetLimit ().GetMemory (), 75_MB);
428
+ UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Consumer/QueryExecution/Limit" )->Val (), 75_MB);
429
+ UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Stats/ActivitiesLimitBytes" )->Val (), 150_MB);
410
430
411
431
// ensure that other settings are not affected:
412
432
runtime.Send (new IEventHandle (MakeResourceBrokerID (), sender, new TEvResourceBroker::TEvConfigRequest (" queue_cs_ttl" )));
@@ -417,7 +437,60 @@ Y_UNIT_TEST(ResourceBroker) {
417
437
config = runtime.GrabEdgeEvent <TEvResourceBroker::TEvConfigResponse>(handle);
418
438
UNIT_ASSERT_VALUES_EQUAL (config->QueueConfig ->GetLimit ().GetCpu (), 3 );
419
439
UNIT_ASSERT_VALUES_EQUAL (config->QueueConfig ->GetLimit ().GetMemory (), 3221225472 );
440
+ }
441
+
442
+ Y_UNIT_TEST (ResourceBroker_ConfigLimit) {
443
+ using namespace NResourceBroker ;
420
444
445
+ TPortManager pm;
446
+ TServerSettings serverSettings (pm.GetPort (2134 ));
447
+ serverSettings.SetDomainName (" Root" )
448
+ .SetUseRealThreads (false );
449
+
450
+ auto memoryControllerConfig = serverSettings.AppConfig ->MutableMemoryControllerConfig ();
451
+ memoryControllerConfig->SetQueryExecutionLimitPercent (15 );
452
+
453
+ auto resourceBrokerConfig = serverSettings.AppConfig ->MutableResourceBrokerConfig ();
454
+ resourceBrokerConfig->MutableResourceLimit ()->SetMemory (1000_MB);
455
+ auto queue = resourceBrokerConfig->AddQueues ();
456
+ queue->SetName (" queue_kqp_resource_manager" );
457
+ queue->MutableLimit ()->SetMemory (999_MB);
458
+ queue = resourceBrokerConfig->AddQueues ();
459
+ queue->SetName (" queue_cs_ttl" );
460
+ queue->MutableLimit ()->SetMemory (13_MB);
461
+
462
+ auto server = MakeIntrusive<TWithMemoryControllerServer>(serverSettings);
463
+ server->ProcessMemoryInfo ->CGroupLimit = 500_MB;
464
+ auto & runtime = *server->GetRuntime ();
465
+ TAutoPtr<IEventHandle> handle;
466
+ auto sender = runtime.AllocateEdgeActor ();
467
+
468
+ InitRoot (server, sender);
469
+
470
+ runtime.SimulateSleep (TDuration::Seconds (2 ));
471
+ runtime.Send (new IEventHandle (MakeResourceBrokerID (), sender, new TEvResourceBroker::TEvConfigRequest (NLocalDb::KqpResourceManagerQueue)));
472
+ auto config = runtime.GrabEdgeEvent <TEvResourceBroker::TEvConfigResponse>(handle);
473
+ UNIT_ASSERT_VALUES_EQUAL (config->QueueConfig ->GetLimit ().GetMemory (), 999_MB);
474
+ UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Consumer/QueryExecution/Limit" )->Val (), 999_MB);
475
+ UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Stats/ActivitiesLimitBytes" )->Val (), 1000_MB);
476
+
477
+ server->ProcessMemoryInfo ->CGroupLimit = 200_MB;
478
+ runtime.SimulateSleep (TDuration::Seconds (2 ));
479
+ runtime.Send (new IEventHandle (MakeResourceBrokerID (), sender, new TEvResourceBroker::TEvConfigRequest (NLocalDb::KqpResourceManagerQueue)));
480
+ config = runtime.GrabEdgeEvent <TEvResourceBroker::TEvConfigResponse>(handle);
481
+ UNIT_ASSERT_VALUES_EQUAL (config->QueueConfig ->GetLimit ().GetMemory (), 999_MB);
482
+ UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Consumer/QueryExecution/Limit" )->Val (), 999_MB);
483
+ UNIT_ASSERT_VALUES_EQUAL (server->MemoryControllerCounters ->GetCounter (" Stats/ActivitiesLimitBytes" )->Val (), 1000_MB);
484
+
485
+ // ensure that other settings are not affected:
486
+ runtime.Send (new IEventHandle (MakeResourceBrokerID (), sender, new TEvResourceBroker::TEvConfigRequest (" queue_cs_ttl" )));
487
+ config = runtime.GrabEdgeEvent <TEvResourceBroker::TEvConfigResponse>(handle);
488
+ UNIT_ASSERT_VALUES_EQUAL (config->QueueConfig ->GetLimit ().GetCpu (), 3 );
489
+ UNIT_ASSERT_VALUES_EQUAL (config->QueueConfig ->GetLimit ().GetMemory (), 13_MB);
490
+ runtime.Send (new IEventHandle (MakeResourceBrokerID (), sender, new TEvResourceBroker::TEvConfigRequest (" queue_cs_general" )));
491
+ config = runtime.GrabEdgeEvent <TEvResourceBroker::TEvConfigResponse>(handle);
492
+ UNIT_ASSERT_VALUES_EQUAL (config->QueueConfig ->GetLimit ().GetCpu (), 3 );
493
+ UNIT_ASSERT_VALUES_EQUAL (config->QueueConfig ->GetLimit ().GetMemory (), 3221225472 );
421
494
}
422
495
423
496
}
0 commit comments