Skip to content

Commit 3821c07

Browse files
gridnevvvitkunga
andauthored
add arrow memory pools graphs (#9061)
Co-authored-by: kungurtsev <alexey66rus@gmail.com>
1 parent a837a20 commit 3821c07

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

ydb/core/memory_controller/memory_controller.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include <ydb/library/actors/core/process_stats.h>
1717
#include <ydb/library/services/services.pb.h>
1818
#include <ydb/library/yql/minikql/aligned_page_pool.h>
19+
#include <contrib/libs/apache/arrow/cpp/src/arrow/type.h>
20+
#include <contrib/libs/apache/arrow/cpp/src/arrow/memory_pool.h>
21+
#include <ydb/library/yql/public/udf/arrow/memory_pool.h>
1922

2023
namespace NKikimr::NMemory {
2124

@@ -98,7 +101,7 @@ class TMemoryController : public TActorBootstrapped<TMemoryController> {
98101
const TResourceBrokerConfig& resourceBrokerConfig,
99102
TIntrusivePtr<::NMonitoring::TDynamicCounters> counters)
100103
: Interval(interval)
101-
, MemTables(std::make_shared<TMemTableMemoryConsumersCollection>(counters,
104+
, MemTables(std::make_shared<TMemTableMemoryConsumersCollection>(counters,
102105
Consumers.emplace(EMemoryConsumerKind::MemTable, MakeIntrusive<TMemoryConsumer>(EMemoryConsumerKind::MemTable, TActorId{})).first->second))
103106
, ProcessMemoryInfoProvider(std::move(processMemoryInfoProvider))
104107
, Config(config)
@@ -109,7 +112,7 @@ class TMemoryController : public TActorBootstrapped<TMemoryController> {
109112
void Bootstrap(const TActorContext& ctx) {
110113
Become(&TThis::StateWork);
111114

112-
Send(NConsole::MakeConfigsDispatcherID(SelfId().NodeId()),
115+
Send(NConsole::MakeConfigsDispatcherID(SelfId().NodeId()),
113116
new NConsole::TEvConfigsDispatcher::TEvSetConfigSubscriptionRequest({
114117
NKikimrConsole::TConfigItem::MemoryControllerConfigItem}));
115118

@@ -146,7 +149,7 @@ class TMemoryController : public TActorBootstrapped<TMemoryController> {
146149
ui64 hardLimitBytes = GetHardLimitBytes(Config, processMemoryInfo, hasMemTotalHardLimit);
147150
ui64 softLimitBytes = GetSoftLimitBytes(Config, hardLimitBytes);
148151
ui64 targetUtilizationBytes = GetTargetUtilizationBytes(Config, hardLimitBytes);
149-
ui64 activitiesLimitBytes = ResourceBrokerSelfConfig.LimitBytes
152+
ui64 activitiesLimitBytes = ResourceBrokerSelfConfig.LimitBytes
150153
? ResourceBrokerSelfConfig.LimitBytes // for backward compatibility
151154
: GetActivitiesLimitBytes(Config, hardLimitBytes);
152155

@@ -161,7 +164,7 @@ class TMemoryController : public TActorBootstrapped<TMemoryController> {
161164
ui64 otherConsumption = SafeDiff(processMemoryInfo.AllocatedMemory, consumersConsumption);
162165

163166
ui64 externalConsumption = 0;
164-
if (hasMemTotalHardLimit && processMemoryInfo.AnonRss.has_value()
167+
if (hasMemTotalHardLimit && processMemoryInfo.AnonRss.has_value()
165168
&& processMemoryInfo.MemTotal.has_value() && processMemoryInfo.MemAvailable.has_value()) {
166169
// externalConsumption + AnonRss + MemAvailable = MemTotal
167170
externalConsumption = SafeDiff(processMemoryInfo.MemTotal.value(),
@@ -174,20 +177,20 @@ class TMemoryController : public TActorBootstrapped<TMemoryController> {
174177
// want to find maximum possible coefficient in range [0..1] so that
175178
// Sum(
176179
// Max(
177-
// consumers[i].Consumption,
180+
// consumers[i].Consumption,
178181
// consumers[i].MinBytes + coefficient * (consumers[i].MaxBytes - consumers[i].MinBytes
179182
// )
180183
// ) <= targetConsumersConsumption
181184
auto coefficient = BinarySearchCoefficient(consumers, targetConsumersConsumption);
182185

183186
ui64 resultingConsumersConsumption = 0;
184187
for (const auto& consumer : consumers) {
185-
// Note: take Max with current consumer consumption because memory free may happen with a delay, or don't happen at all
188+
// Note: take Max with current consumer consumption because memory free may happen with a delay, or don't happen at all
186189
resultingConsumersConsumption += Max(consumer.Consumption, consumer.GetLimit(coefficient));
187190
}
188191

189192
LOG_INFO_S(ctx, NKikimrServices::MEMORY_CONTROLLER, "Periodic memory stats:"
190-
<< " AnonRss: " << processMemoryInfo.AnonRss << " CGroupLimit: " << processMemoryInfo.CGroupLimit
193+
<< " AnonRss: " << processMemoryInfo.AnonRss << " CGroupLimit: " << processMemoryInfo.CGroupLimit
191194
<< " MemTotal: " << processMemoryInfo.MemTotal << " MemAvailable: " << processMemoryInfo.MemAvailable
192195
<< " AllocatedMemory: " << processMemoryInfo.AllocatedMemory << " AllocatorCachesMemory: " << processMemoryInfo.AllocatorCachesMemory
193196
<< " HardLimit: " << hardLimitBytes << " SoftLimit: " << softLimitBytes << " TargetUtilization: " << targetUtilizationBytes
@@ -212,6 +215,8 @@ class TMemoryController : public TActorBootstrapped<TMemoryController> {
212215
Counters->GetCounter("Stats/TargetConsumersConsumption")->Set(targetConsumersConsumption);
213216
Counters->GetCounter("Stats/ResultingConsumersConsumption")->Set(resultingConsumersConsumption);
214217
Counters->GetCounter("Stats/Coefficient")->Set(coefficient * 1e9);
218+
Counters->GetCounter("Stats/ArrowAllocatedMemory")->Set(arrow::default_memory_pool()->bytes_allocated());
219+
Counters->GetCounter("Stats/ArrowYqlAllocatedMemory")->Set(NYql::NUdf::GetYqlMemoryPool()->bytes_allocated());
215220

216221
auto *memoryStatsUpdate = new NNodeWhiteboard::TEvWhiteboard::TEvMemoryStatsUpdate();
217222
auto& memoryStats = memoryStatsUpdate->Record;
@@ -251,7 +256,7 @@ class TMemoryController : public TActorBootstrapped<TMemoryController> {
251256
Counters->GetCounter("Stats/ConsumersLimit")->Set(consumersLimitBytes);
252257

253258
ui64 queryExecutionConsumption = TAlignedPagePool::GetGlobalPagePoolSize();
254-
ui64 queryExecutionLimitBytes = ResourceBrokerSelfConfig.QueryExecutionLimitBytes
259+
ui64 queryExecutionLimitBytes = ResourceBrokerSelfConfig.QueryExecutionLimitBytes
255260
? ResourceBrokerSelfConfig.QueryExecutionLimitBytes // for backward compatibility
256261
: GetQueryExecutionLimitBytes(Config, hardLimitBytes);
257262
LOG_INFO_S(ctx, NKikimrServices::MEMORY_CONTROLLER, "Consumer QueryExecution state:"
@@ -303,9 +308,9 @@ class TMemoryController : public TActorBootstrapped<TMemoryController> {
303308

304309
void Handle(TEvResourceBroker::TEvConfigureResult::TPtr &ev, const TActorContext& ctx) {
305310
const auto *msg = ev->Get();
306-
LOG_LOG_S(ctx,
307-
msg->Record.GetSuccess() ? NActors::NLog::PRI_INFO : NActors::NLog::PRI_ERROR,
308-
NKikimrServices::MEMORY_CONTROLLER,
311+
LOG_LOG_S(ctx,
312+
msg->Record.GetSuccess() ? NActors::NLog::PRI_INFO : NActors::NLog::PRI_ERROR,
313+
NKikimrServices::MEMORY_CONTROLLER,
309314
"ResourceBroker configure result " << msg->Record.ShortDebugString());
310315
}
311316

@@ -404,7 +409,7 @@ class TMemoryController : public TActorBootstrapped<TMemoryController> {
404409

405410
TConsumerState BuildConsumerState(const TMemoryConsumer& consumer, ui64 hardLimitBytes) const {
406411
TConsumerState result(consumer);
407-
412+
408413
switch (consumer.Kind) {
409414
case EMemoryConsumerKind::MemTable: {
410415
result.MinBytes = GetMemTableMinBytes(Config, hardLimitBytes);
@@ -445,7 +450,7 @@ class TMemoryController : public TActorBootstrapped<TMemoryController> {
445450
IActor* CreateMemoryController(
446451
TDuration interval,
447452
TIntrusiveConstPtr<IProcessMemoryInfoProvider> processMemoryInfoProvider,
448-
const NKikimrConfig::TMemoryControllerConfig& config,
453+
const NKikimrConfig::TMemoryControllerConfig& config,
449454
const TResourceBrokerConfig& resourceBrokerSelfConfig,
450455
const TIntrusivePtr<::NMonitoring::TDynamicCounters>& counters) {
451456
return new TMemoryController(

ydb/core/memory_controller/ya.make

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ PEERDIR(
1616
ydb/core/tablet
1717
)
1818

19+
YQL_LAST_ABI_VERSION()
20+
1921
END()
2022

2123
RECURSE_FOR_TESTS(

0 commit comments

Comments
 (0)