Skip to content

Calculate disconnections in last hour #11007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading