Skip to content

Commit

Permalink
Calculate disconnections in last hour (#11007)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvru authored Oct 28, 2024
1 parent d4eaec4 commit 634dc20
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ydb/library/actors/interconnect/interconnect_tcp_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace NActors {
Y_ABORT_UNLESS(!*DynamicPtr);
*DynamicPtr = this;
}
NumDisconnects.fill(0);
}

void TInterconnectProxyTCP::Bootstrap() {
Expand Down Expand Up @@ -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;
}

}
13 changes: 13 additions & 0 deletions ydb/library/actors/interconnect/interconnect_tcp_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 634dc20

Please sign in to comment.