@@ -48,25 +48,37 @@ class TPoolHandlerActorBase : public TActor<TDerived> {
48
48
49
49
TCommonCounters (NMonitoring::TDynamicCounterPtr counters, const TString& database, const TString& poolId, const NResourcePool::TPoolSettings& poolConfig)
50
50
: CountersRoot(counters)
51
- , CountersSubgroup(counters->GetSubgroup (" pool" , CanonizePath(TStringBuilder() << database << "/" << poolId)))
51
+ , CountersSubgroup(counters ? counters ->GetSubgroup (" pool" , CanonizePath(TStringBuilder() << database << "/" << poolId)) : nullptr )
52
52
{
53
53
Register ();
54
54
UpdateConfigCounters (poolConfig);
55
55
}
56
56
57
+ explicit operator bool () const {
58
+ return !!CountersRoot;
59
+ }
60
+
57
61
void CollectRequestLatency (TInstant continueTime) {
58
- if (continueTime) {
62
+ if (continueTime && CountersRoot ) {
59
63
RequestsLatencyMs->Collect ((TInstant::Now () - continueTime).MilliSeconds ());
60
64
}
61
65
}
62
66
63
67
void UpdateConfigCounters (const NResourcePool::TPoolSettings& poolConfig) {
68
+ if (!CountersRoot) {
69
+ return ;
70
+ }
71
+
64
72
InFlightLimit->Set (std::max (poolConfig.ConcurrentQueryLimit , 0 ));
65
73
QueueSizeLimit->Set (std::max (poolConfig.QueueSize , 0 ));
66
74
LoadCpuThreshold->Set (std::max (poolConfig.DatabaseLoadCpuThreshold , 0.0 ));
67
75
}
68
76
69
77
void OnCleanup () {
78
+ if (!CountersRoot) {
79
+ return ;
80
+ }
81
+
70
82
ActivePoolHandlers->Dec ();
71
83
72
84
InFlightLimit->Set (0 );
@@ -76,6 +88,10 @@ class TPoolHandlerActorBase : public TActor<TDerived> {
76
88
77
89
private:
78
90
void Register () {
91
+ if (!CountersRoot) {
92
+ return ;
93
+ }
94
+
79
95
ActivePoolHandlers = CountersRoot->GetCounter (" ActivePoolHandlers" , false );
80
96
ActivePoolHandlers->Inc ();
81
97
@@ -202,7 +218,9 @@ class TPoolHandlerActorBase : public TActor<TDerived> {
202
218
}
203
219
204
220
TRequest* request = &LocalSessions.insert ({sessionId, TRequest (workerActorId, sessionId)}).first ->second ;
205
- Counters.LocalDelayedRequests ->Inc ();
221
+ if (Counters) {
222
+ Counters.LocalDelayedRequests ->Inc ();
223
+ }
206
224
207
225
UpdatePoolConfig (ev->Get ()->PoolConfig );
208
226
UpdateSchemeboardSubscription (ev->Get ()->PathId );
@@ -303,25 +321,35 @@ class TPoolHandlerActorBase : public TActor<TDerived> {
303
321
LocalInFlight++;
304
322
request->Started = true ;
305
323
request->ContinueTime = TInstant::Now ();
306
- Counters.LocalInFly ->Inc ();
307
- Counters.ContinueOk ->Inc ();
308
- Counters.DelayedTimeMs ->Collect ((TInstant::Now () - request->StartTime ).MilliSeconds ());
324
+ if (Counters) {
325
+ Counters.LocalInFly ->Inc ();
326
+ Counters.ContinueOk ->Inc ();
327
+ Counters.DelayedTimeMs ->Collect ((TInstant::Now () - request->StartTime ).MilliSeconds ());
328
+ }
309
329
LOG_D (" Reply continue success to " << request->WorkerActorId << " , session id: " << request->SessionId << " , local in flight: " << LocalInFlight);
310
330
} else {
311
331
if (status == Ydb::StatusIds::OVERLOADED) {
312
- Counters.ContinueOverloaded ->Inc ();
332
+ if (Counters) {
333
+ Counters.ContinueOverloaded ->Inc ();
334
+ }
313
335
LOG_I (" Reply overloaded to " << request->WorkerActorId << " , session id: " << request->SessionId << " , issues: " << issues.ToOneLineString ());
314
336
} else if (status == Ydb::StatusIds::CANCELLED) {
315
- Counters.Cancelled ->Inc ();
337
+ if (Counters) {
338
+ Counters.Cancelled ->Inc ();
339
+ }
316
340
LOG_I (" Reply cancelled to " << request->WorkerActorId << " , session id: " << request->SessionId << " , issues: " << issues.ToOneLineString ());
317
341
} else {
318
- Counters.ContinueError ->Inc ();
342
+ if (Counters) {
343
+ Counters.ContinueError ->Inc ();
344
+ }
319
345
LOG_W (" Reply continue error " << status << " to " << request->WorkerActorId << " , session id: " << request->SessionId << " , issues: " << issues.ToOneLineString ());
320
346
}
321
347
RemoveRequest (request);
322
348
}
323
349
324
- Counters.LocalDelayedRequests ->Dec ();
350
+ if (Counters) {
351
+ Counters.LocalDelayedRequests ->Dec ();
352
+ }
325
353
}
326
354
327
355
void FinalReply (TRequest* request, Ydb::StatusIds::StatusCode status, const TString& message) {
@@ -340,8 +368,10 @@ class TPoolHandlerActorBase : public TActor<TDerived> {
340
368
341
369
if (request->Started ) {
342
370
LocalInFlight--;
343
- Counters.LocalInFly ->Dec ();
344
- } else {
371
+ if (Counters) {
372
+ Counters.LocalInFly ->Dec ();
373
+ }
374
+ } else if (Counters) {
345
375
Counters.LocalDelayedRequests ->Dec ();
346
376
}
347
377
@@ -428,11 +458,15 @@ class TPoolHandlerActorBase : public TActor<TDerived> {
428
458
this ->Send (request->WorkerActorId , new TEvCleanupResponse (status, issues));
429
459
430
460
if (status == Ydb::StatusIds::SUCCESS) {
431
- Counters.CleanupOk ->Inc ();
432
- Counters.CollectRequestLatency (request->ContinueTime );
461
+ if (Counters) {
462
+ Counters.CleanupOk ->Inc ();
463
+ Counters.CollectRequestLatency (request->ContinueTime );
464
+ }
433
465
LOG_D (" Reply cleanup success to " << request->WorkerActorId << " , session id: " << request->SessionId << " , local in flight: " << LocalInFlight);
434
466
} else {
435
- Counters.CleanupError ->Inc ();
467
+ if (Counters) {
468
+ Counters.CleanupError ->Inc ();
469
+ }
436
470
LOG_W (" Reply cleanup error " << status << " to " << request->WorkerActorId << " , session id: " << request->SessionId << " , issues: " << issues.ToOneLineString ());
437
471
}
438
472
}
@@ -442,8 +476,10 @@ class TPoolHandlerActorBase : public TActor<TDerived> {
442
476
ev->Record .MutableRequest ()->SetSessionId (request->SessionId );
443
477
this ->Send (MakeKqpProxyID (this ->SelfId ().NodeId ()), ev.release ());
444
478
445
- Counters.Cancelled ->Inc ();
446
- Counters.CollectRequestLatency (request->ContinueTime );
479
+ if (Counters) {
480
+ Counters.Cancelled ->Inc ();
481
+ Counters.CollectRequestLatency (request->ContinueTime );
482
+ }
447
483
LOG_I (" Cancel request for worker " << request->WorkerActorId << " , session id: " << request->SessionId << " , local in flight: " << LocalInFlight);
448
484
}
449
485
@@ -547,34 +583,54 @@ class TFifoPoolHandlerActor : public TPoolHandlerActorBase<TFifoPoolHandlerActor
547
583
using TBase = TPoolHandlerActorBase<TFifoPoolHandlerActor>;
548
584
549
585
struct TCounters {
586
+ const NMonitoring::TDynamicCounterPtr CountersSubgroup;
587
+
550
588
// Fifo pool counters
551
589
NMonitoring::TDynamicCounters::TCounterPtr PendingRequestsCount;
552
590
NMonitoring::TDynamicCounters::TCounterPtr FinishingRequestsCount;
553
591
NMonitoring::TDynamicCounters::TCounterPtr GlobalInFly;
554
592
NMonitoring::TDynamicCounters::TCounterPtr GlobalDelayedRequests;
555
593
NMonitoring::THistogramPtr PoolStateUpdatesBacklogMs;
556
594
557
- TCounters (NMonitoring::TDynamicCounterPtr countersSubgroup) {
558
- Register (countersSubgroup);
595
+ TCounters (NMonitoring::TDynamicCounterPtr countersSubgroup)
596
+ : CountersSubgroup(countersSubgroup)
597
+ {
598
+ Register ();
599
+ }
600
+
601
+ explicit operator bool () const {
602
+ return !!CountersSubgroup;
559
603
}
560
604
561
605
void UpdateGlobalState (const TPoolStateDescription& description) {
606
+ if (!CountersSubgroup) {
607
+ return ;
608
+ }
609
+
562
610
GlobalInFly->Set (description.RunningRequests );
563
611
GlobalDelayedRequests->Set (description.DelayedRequests );
564
612
}
565
613
566
614
void OnCleanup () {
615
+ if (!CountersSubgroup) {
616
+ return ;
617
+ }
618
+
567
619
GlobalInFly->Set (0 );
568
620
GlobalDelayedRequests->Set (0 );
569
621
}
570
622
571
623
private:
572
- void Register (NMonitoring::TDynamicCounterPtr countersSubgroup) {
573
- PendingRequestsCount = countersSubgroup->GetCounter (" PendingRequestsCount" , false );
574
- FinishingRequestsCount = countersSubgroup->GetCounter (" FinishingRequestsCount" , false );
575
- GlobalInFly = countersSubgroup->GetCounter (" GlobalInFly" , false );
576
- GlobalDelayedRequests = countersSubgroup->GetCounter (" GlobalDelayedRequests" , false );
577
- PoolStateUpdatesBacklogMs = countersSubgroup->GetHistogram (" PoolStateUpdatesBacklogMs" , NMonitoring::LinearHistogram (20 , 0 , 3 * LEASE_DURATION.MillisecondsFloat () / 40 ));
624
+ void Register () {
625
+ if (!CountersSubgroup) {
626
+ return ;
627
+ }
628
+
629
+ PendingRequestsCount = CountersSubgroup->GetCounter (" PendingRequestsCount" , false );
630
+ FinishingRequestsCount = CountersSubgroup->GetCounter (" FinishingRequestsCount" , false );
631
+ GlobalInFly = CountersSubgroup->GetCounter (" GlobalInFly" , false );
632
+ GlobalDelayedRequests = CountersSubgroup->GetCounter (" GlobalDelayedRequests" , false );
633
+ PoolStateUpdatesBacklogMs = CountersSubgroup->GetHistogram (" PoolStateUpdatesBacklogMs" , NMonitoring::LinearHistogram (20 , 0 , 3 * LEASE_DURATION.MillisecondsFloat () / 40 ));
578
634
}
579
635
};
580
636
@@ -628,7 +684,9 @@ class TFifoPoolHandlerActor : public TPoolHandlerActorBase<TFifoPoolHandlerActor
628
684
}
629
685
630
686
PendingRequests.emplace_back (request->SessionId );
631
- FifoCounters.PendingRequestsCount ->Inc ();
687
+ if (FifoCounters) {
688
+ FifoCounters.PendingRequestsCount ->Inc ();
689
+ }
632
690
633
691
if (!PreparingFinished) {
634
692
this ->Send (MakeKqpWorkloadServiceId (this ->SelfId ().NodeId ()), new TEvPrivate::TEvPrepareTablesRequest (Database, PoolId));
@@ -710,7 +768,9 @@ class TFifoPoolHandlerActor : public TPoolHandlerActorBase<TFifoPoolHandlerActor
710
768
});
711
769
712
770
PendingRequests.clear ();
713
- FifoCounters.PendingRequestsCount ->Set (0 );
771
+ if (FifoCounters) {
772
+ FifoCounters.PendingRequestsCount ->Set (0 );
773
+ }
714
774
}
715
775
716
776
void Handle (TEvPrivate::TEvRefreshPoolStateResponse::TPtr& ev) {
@@ -723,7 +783,7 @@ class TFifoPoolHandlerActor : public TPoolHandlerActorBase<TFifoPoolHandlerActor
723
783
return ;
724
784
}
725
785
726
- if (LastRefreshTime) {
786
+ if (LastRefreshTime && FifoCounters ) {
727
787
FifoCounters.PoolStateUpdatesBacklogMs ->Collect ((TInstant::Now () - LastRefreshTime).MilliSeconds ());
728
788
}
729
789
LastRefreshTime = TInstant::Now ();
@@ -744,7 +804,9 @@ class TFifoPoolHandlerActor : public TPoolHandlerActorBase<TFifoPoolHandlerActor
744
804
RemoveBackRequests (PendingRequests, std::min (delayedRequests - QueueSizeLimit, PendingRequests.size ()), [this ](TRequest* request) {
745
805
ReplyContinue (request, Ydb::StatusIds::OVERLOADED, TStringBuilder () << " Too many pending requests for pool " << PoolId);
746
806
});
747
- FifoCounters.PendingRequestsCount ->Set (PendingRequests.size ());
807
+ if (FifoCounters) {
808
+ FifoCounters.PendingRequestsCount ->Set (PendingRequests.size ());
809
+ }
748
810
}
749
811
750
812
if (PendingRequests.empty () && delayedRequestsCount > QueueSizeLimit) {
@@ -774,7 +836,9 @@ class TFifoPoolHandlerActor : public TPoolHandlerActorBase<TFifoPoolHandlerActor
774
836
}
775
837
776
838
GlobalState.DelayedRequests ++;
777
- FifoCounters.GlobalDelayedRequests ->Inc ();
839
+ if (FifoCounters) {
840
+ FifoCounters.GlobalDelayedRequests ->Inc ();
841
+ }
778
842
LOG_D (" succefully delayed request, session id: " << ev->Get ()->SessionId );
779
843
780
844
DoStartDelayedRequest (GetLoadCpuThreshold ());
@@ -849,12 +913,16 @@ class TFifoPoolHandlerActor : public TPoolHandlerActorBase<TFifoPoolHandlerActor
849
913
request->UsedCpuQuota = !!GetLoadCpuThreshold ();
850
914
requestFound = true ;
851
915
GlobalState.RunningRequests ++;
852
- FifoCounters.GlobalInFly ->Inc ();
916
+ if (FifoCounters) {
917
+ FifoCounters.GlobalInFly ->Inc ();
918
+ }
853
919
ReplyContinue (request);
854
920
} else {
855
921
// Request was dropped due to lease expiration
856
922
PendingRequests.emplace_front (request->SessionId );
857
- FifoCounters.PendingRequestsCount ->Inc ();
923
+ if (FifoCounters) {
924
+ FifoCounters.PendingRequestsCount ->Inc ();
925
+ }
858
926
}
859
927
});
860
928
DelayedRequests.pop_front ();
@@ -947,7 +1015,9 @@ class TFifoPoolHandlerActor : public TPoolHandlerActorBase<TFifoPoolHandlerActor
947
1015
RunningOperation = true ;
948
1016
this ->Register (CreateCleanupRequestsActor (this ->SelfId (), Database, PoolId, FinishedRequests, Counters.CountersSubgroup ));
949
1017
FinishedRequests.clear ();
950
- FifoCounters.FinishingRequestsCount ->Set (0 );
1018
+ if (FifoCounters) {
1019
+ FifoCounters.FinishingRequestsCount ->Set (0 );
1020
+ }
951
1021
}
952
1022
}
953
1023
@@ -971,7 +1041,9 @@ class TFifoPoolHandlerActor : public TPoolHandlerActorBase<TFifoPoolHandlerActor
971
1041
972
1042
RemoveFinishedRequests (PendingRequests);
973
1043
RemoveFinishedRequests (DelayedRequests);
974
- FifoCounters.PendingRequestsCount ->Set (PendingRequests.size ());
1044
+ if (FifoCounters) {
1045
+ FifoCounters.PendingRequestsCount ->Set (PendingRequests.size ());
1046
+ }
975
1047
}
976
1048
977
1049
void RemoveFinishedRequests (std::deque<TString>& requests) {
@@ -1012,13 +1084,17 @@ class TFifoPoolHandlerActor : public TPoolHandlerActorBase<TFifoPoolHandlerActor
1012
1084
TString PopPendingRequest () {
1013
1085
TString sessionId = PendingRequests.front ();
1014
1086
PendingRequests.pop_front ();
1015
- FifoCounters.PendingRequestsCount ->Dec ();
1087
+ if (FifoCounters) {
1088
+ FifoCounters.PendingRequestsCount ->Dec ();
1089
+ }
1016
1090
return sessionId;
1017
1091
}
1018
1092
1019
1093
void AddFinishedRequest (const TString& sessionId) {
1020
1094
FinishedRequests.emplace_back (sessionId);
1021
- FifoCounters.FinishingRequestsCount ->Inc ();
1095
+ if (FifoCounters) {
1096
+ FifoCounters.FinishingRequestsCount ->Inc ();
1097
+ }
1022
1098
}
1023
1099
1024
1100
private:
0 commit comments