diff options
author | Alexander Rutkovsky <alexvru@ydb.tech> | 2024-10-28 19:56:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-28 17:56:42 +0100 |
commit | 634dc2025c2a7bbb0093b1a63dd2e64f969a497f (patch) | |
tree | a65e853588959f299cfb6c735dc5911d34d9a420 | |
parent | d4eaec4b2160071cab2d5b85eb2f5a9265a0c90c (diff) | |
download | ydb-634dc2025c2a7bbb0093b1a63dd2e64f969a497f.tar.gz |
Calculate disconnections in last hour (#11007)
3 files changed, 44 insertions, 0 deletions
diff --git a/ydb/library/actors/interconnect/interconnect_tcp_proxy.cpp b/ydb/library/actors/interconnect/interconnect_tcp_proxy.cpp index e3a960d82b..2fad87c59e 100644 --- a/ydb/library/actors/interconnect/interconnect_tcp_proxy.cpp +++ b/ydb/library/actors/interconnect/interconnect_tcp_proxy.cpp @@ -29,6 +29,7 @@ namespace NActors { Y_ABORT_UNLESS(!*DynamicPtr); *DynamicPtr = this; } + NumDisconnects.fill(0); } void TInterconnectProxyTCP::Bootstrap() { @@ -942,4 +943,33 @@ namespace NActors { // TODO: unregister actor mon page TActor::PassAway(); } + + void TInterconnectProxyTCP::RegisterDisconnect() { + const TMonotonic now = TActivationContext::Monotonic(); + ShiftDisconnectWindow(now); + ++NumDisconnectsInLastHour; + ++NumDisconnects[NumDisconnectsIndex]; + } + + ui32 TInterconnectProxyTCP::GetDisconnectCountInLastHour() { + ShiftDisconnectWindow(TMonotonic::Now()); + return NumDisconnectsInLastHour; + } + + void TInterconnectProxyTCP::ShiftDisconnectWindow(TMonotonic now) { + const ui64 currentMinutes = now.Minutes(); + if (FirstDisconnectWindowMinutes) { + const ui32 steps = currentMinutes - FirstDisconnectWindowMinutes; + if (steps < NumDisconnectsSize) { // advance window by "steps" items, clearing them + for (ui32 i = 0; i < steps; ++i) { + NumDisconnectsInLastHour -= std::exchange(NumDisconnects[++NumDisconnectsIndex %= NumDisconnectsSize], 0); + } + } else { // window has been fully flushed + NumDisconnects.fill(0); + NumDisconnectsInLastHour = 0; + } + } + FirstDisconnectWindowMinutes = currentMinutes; + } + } diff --git a/ydb/library/actors/interconnect/interconnect_tcp_proxy.h b/ydb/library/actors/interconnect/interconnect_tcp_proxy.h index 3fa9253a3f..1933ef1ffd 100644 --- a/ydb/library/actors/interconnect/interconnect_tcp_proxy.h +++ b/ydb/library/actors/interconnect/interconnect_tcp_proxy.h @@ -565,6 +565,19 @@ namespace NActors { void HandleTerminate(); void PassAway() override; + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Disconnection management + + static constexpr size_t NumDisconnectsSize = 60; + std::array<ui32, NumDisconnectsSize> NumDisconnects; + size_t NumDisconnectsIndex = 0; + ui32 NumDisconnectsInLastHour = 0; + ui64 FirstDisconnectWindowMinutes = 0; + + void RegisterDisconnect(); + ui32 GetDisconnectCountInLastHour(); + void ShiftDisconnectWindow(TMonotonic now); }; } diff --git a/ydb/library/actors/interconnect/interconnect_tcp_session.cpp b/ydb/library/actors/interconnect/interconnect_tcp_session.cpp index c9f589713d..e7634a3dd6 100644 --- a/ydb/library/actors/interconnect/interconnect_tcp_session.cpp +++ b/ydb/library/actors/interconnect/interconnect_tcp_session.cpp @@ -542,6 +542,7 @@ namespace NActors { CloseOnIdleWatchdog.Disarm(); LostConnectionWatchdog.Rearm(SelfId()); Proxy->Metrics->SetConnected(0); + Proxy->RegisterDisconnect(); LOG_INFO(*TlsActivationContext, NActorsServices::INTERCONNECT_STATUS, "[%u] disconnected", Proxy->PeerNodeId); } if (XdcSocket) { |