Skip to content

Commit e8d3629

Browse files
committed
don't lock on zero memory change
add extra counters to track calls
1 parent 654e1f2 commit e8d3629

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

ydb/core/kqp/counters/kqp_counters.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,10 @@ TKqpCounters::TKqpCounters(const ::NMonitoring::TDynamicCounterPtr& counters, co
776776
RmExternalMemory = KqpGroup->GetCounter("RM/ExternalMemory", false);
777777
RmNotEnoughMemory = KqpGroup->GetCounter("RM/NotEnoughMemory", true);
778778
RmNotEnoughComputeActors = KqpGroup->GetCounter("RM/NotEnoughComputeActors", true);
779+
RmOnStartAllocs = KqpGroup->GetCounter("Rm/OnStartAllocs", true);
779780
RmExtraMemAllocs = KqpGroup->GetCounter("RM/ExtraMemAllocs", true);
781+
RmExtraMemFree = KqpGroup->GetCounter("RM/ExtraMemFree", true);
782+
RmOnCompleteFree = KqpGroup->GetCounter("RM/OnCompleteFree", true);
780783
RmInternalError = KqpGroup->GetCounter("RM/InternalError", true);
781784
RmSnapshotLatency = KqpGroup->GetHistogram(
782785
"RM/SnapshotLatency", NMonitoring::ExponentialHistogram(20, 2, 1));

ydb/core/kqp/counters/kqp_counters.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ class TKqpCounters : public TKqpCountersBase, public NYql::NDq::TSpillingCounter
350350
::NMonitoring::TDynamicCounterPtr WorkloadManagerGroup;
351351

352352
::NMonitoring::TDynamicCounters::TCounterPtr FullScansExecuted;
353-
353+
354354
// Lease updates counters
355355
::NMonitoring::THistogramPtr LeaseUpdateLatency;
356356
::NMonitoring::THistogramPtr RunActorLeaseUpdateBacklog;
@@ -377,6 +377,9 @@ class TKqpCounters : public TKqpCountersBase, public NYql::NDq::TSpillingCounter
377377
::NMonitoring::TDynamicCounters::TCounterPtr RmNotEnoughMemory;
378378
::NMonitoring::TDynamicCounters::TCounterPtr RmNotEnoughComputeActors;
379379
::NMonitoring::TDynamicCounters::TCounterPtr RmExtraMemAllocs;
380+
::NMonitoring::TDynamicCounters::TCounterPtr RmOnStartAllocs;
381+
::NMonitoring::TDynamicCounters::TCounterPtr RmExtraMemFree;
382+
::NMonitoring::TDynamicCounters::TCounterPtr RmOnCompleteFree;
380383
::NMonitoring::TDynamicCounters::TCounterPtr RmInternalError;
381384
NMonitoring::THistogramPtr RmSnapshotLatency;
382385
NMonitoring::THistogramPtr NodeServiceStartEventDelivery;

ydb/core/kqp/rm_service/kqp_rm_service.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ class TKqpResourceManager : public IKqpResourceManager {
264264
// all other requests are not guaranteed to be satisfied.
265265
// In the nearest future we need to implement several layers of memory requests.
266266
bool isFirstAllocationRequest = (resources.ExecutionUnits > 0 && resources.MemoryPool == EKqpMemoryPool::DataQuery);
267+
if (resources.ExecutionUnits > 0) {
268+
Counters->RmOnStartAllocs->Inc();
269+
}
270+
267271
if (isFirstAllocationRequest) {
268272
auto& txBucket = TxBucket(txId);
269273
with_lock(txBucket.Lock) {
@@ -370,6 +374,12 @@ class TKqpResourceManager : public IKqpResourceManager {
370374

371375
auto& txBucket = TxBucket(txId);
372376

377+
if (resources.ReleaseAllResources) {
378+
Counters->RmOnCompleteFree->Inc();
379+
} else {
380+
Counters->RmExtraMemFree->Inc();
381+
}
382+
373383
{
374384
TMaybe<TGuard<TMutex>> guard;
375385
guard.ConstructInPlace(txBucket.Lock);
@@ -435,9 +445,11 @@ class TKqpResourceManager : public IKqpResourceManager {
435445
Y_DEBUG_ABORT_UNLESS(Counters->RmMemory->Val() >= 0);
436446
} // with_lock (txBucket.Lock)
437447

438-
with_lock (Lock) {
439-
ScanQueryMemoryResource.Release(releaseScanQueryMemory);
440-
} // with_lock (Lock)
448+
if (releaseScanQueryMemory > 0) {
449+
with_lock (Lock) {
450+
ScanQueryMemoryResource.Release(releaseScanQueryMemory);
451+
} // with_lock (Lock)
452+
}
441453

442454
LOG_AS_D("TxId: " << txId << ", taskId: " << taskId << ". Released resources, "
443455
<< "ScanQueryMemory: " << releaseScanQueryMemory << ", "

0 commit comments

Comments
 (0)