Skip to content

Commit d763137

Browse files
authored
Merge d34bd25 into d4eaec4
2 parents d4eaec4 + d34bd25 commit d763137

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

ydb/library/actors/interconnect/interconnect_tcp_proxy.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,4 +942,39 @@ namespace NActors {
942942
// TODO: unregister actor mon page
943943
TActor::PassAway();
944944
}
945+
946+
void TInterconnectProxyTCP::RegisterDisconnect() {
947+
const TMonotonic now = TActivationContext::Monotonic();
948+
ShiftDisconnectWindow(now);
949+
++NumDisconnectsInLastHour;
950+
if (NumDisconnects.empty()) {
951+
NumDisconnects.push_back(1);
952+
FirstDisconnectWindowMinutes = now.Minutes();
953+
} else {
954+
++NumDisconnects.back();
955+
}
956+
}
957+
958+
ui32 TInterconnectProxyTCP::GetDisconnectCountInLastHour() {
959+
ShiftDisconnectWindow(TMonotonic::Now());
960+
return NumDisconnectsInLastHour;
961+
}
962+
963+
void TInterconnectProxyTCP::ShiftDisconnectWindow(TMonotonic now) {
964+
if (!NumDisconnects.empty()) {
965+
if (const ui32 steps = now.Minutes() - FirstDisconnectWindowMinutes; steps < NumDisconnects.size()) {
966+
auto it = NumDisconnects.begin();
967+
for (ui32 i = 0; i < steps; ++i, ++it) {
968+
NumDisconnectsInLastHour -= *it;
969+
}
970+
NumDisconnects.erase(NumDisconnects.begin(), it);
971+
FirstDisconnectWindowMinutes += steps;
972+
} else {
973+
NumDisconnects.clear();
974+
NumDisconnectsInLastHour = 0;
975+
FirstDisconnectWindowMinutes = 0;
976+
}
977+
}
978+
}
979+
945980
}

ydb/library/actors/interconnect/interconnect_tcp_proxy.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,17 @@ namespace NActors {
565565
void HandleTerminate();
566566

567567
void PassAway() override;
568+
569+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
570+
// Disconnection management
571+
572+
std::deque<ui32> NumDisconnects;
573+
ui32 NumDisconnectsInLastHour = 0;
574+
ui64 FirstDisconnectWindowMinutes = 0;
575+
576+
void RegisterDisconnect();
577+
ui32 GetDisconnectCountInLastHour();
578+
void ShiftDisconnectWindow(TMonotonic now);
568579
};
569580

570581
}

ydb/library/actors/interconnect/interconnect_tcp_session.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ namespace NActors {
542542
CloseOnIdleWatchdog.Disarm();
543543
LostConnectionWatchdog.Rearm(SelfId());
544544
Proxy->Metrics->SetConnected(0);
545+
Proxy->RegisterDisconnect();
545546
LOG_INFO(*TlsActivationContext, NActorsServices::INTERCONNECT_STATUS, "[%u] disconnected", Proxy->PeerNodeId);
546547
}
547548
if (XdcSocket) {

0 commit comments

Comments
 (0)