|
| 1 | +#include "schemeshard_self_pinger.h" |
| 2 | +#include "schemeshard.h" // for TEvMeasureSelfResponseTime and TEvWakeupToMeasureSelfResponseTime |
| 3 | + |
| 4 | +#include <ydb/core/protos/counters_schemeshard.pb.h> |
| 5 | + |
| 6 | +namespace NKikimr::NSchemeShard { |
| 7 | + |
| 8 | +void TSelfPinger::Handle(TEvSchemeShard::TEvMeasureSelfResponseTime::TPtr &ev, const NActors::TActorContext &ctx) { |
| 9 | + Y_UNUSED(ev); |
| 10 | + TInstant now = AppData(ctx)->TimeProvider->Now(); |
| 11 | + TDuration responseTime = now - SelfPingSentTime; |
| 12 | + LastResponseTime = responseTime; |
| 13 | + TabletCounters->Simple()[COUNTER_RESPONSE_TIME_USEC].Set(LastResponseTime.MicroSeconds()); |
| 14 | + if (responseTime.MilliSeconds() > 1000) { |
| 15 | + LOG_WARN_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, |
| 16 | + "Schemeshard " << TabletId << " response time is " << responseTime.MilliSeconds() << " msec"); |
| 17 | + } |
| 18 | + SelfPingInFlight = false; |
| 19 | + if (responseTime > SELF_PING_INTERVAL) { |
| 20 | + DoSelfPing(ctx); |
| 21 | + } else { |
| 22 | + ScheduleSelfPingWakeup(ctx); |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +void TSelfPinger::Handle(TEvSchemeShard::TEvWakeupToMeasureSelfResponseTime::TPtr &ev, const NActors::TActorContext &ctx) { |
| 27 | + Y_UNUSED(ev); |
| 28 | + SelfPingWakeupScheduled = false; |
| 29 | + DoSelfPing(ctx); |
| 30 | +} |
| 31 | + |
| 32 | +void TSelfPinger::OnAnyEvent(const NActors::TActorContext &ctx) { |
| 33 | + TInstant now = AppData(ctx)->TimeProvider->Now(); |
| 34 | + if (SelfPingInFlight) { |
| 35 | + TDuration responseTime = now - SelfPingSentTime; |
| 36 | + // Increase measured response time is ping is taking longer than then the previous one |
| 37 | + LastResponseTime = Max(LastResponseTime, responseTime); |
| 38 | + TabletCounters->Simple()[COUNTER_RESPONSE_TIME_USEC].Set(LastResponseTime.MicroSeconds()); |
| 39 | + } else if ((now - SelfPingWakeupScheduledTime) > SELF_PING_INTERVAL) { |
| 40 | + DoSelfPing(ctx); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +void TSelfPinger::DoSelfPing(const NActors::TActorContext &ctx) { |
| 45 | + if (SelfPingInFlight) |
| 46 | + return; |
| 47 | + |
| 48 | + ctx.Send(ctx.SelfID, new TEvSchemeShard::TEvMeasureSelfResponseTime); |
| 49 | + SelfPingSentTime = AppData(ctx)->TimeProvider->Now(); |
| 50 | + SelfPingInFlight = true; |
| 51 | +} |
| 52 | + |
| 53 | +void TSelfPinger::ScheduleSelfPingWakeup(const NActors::TActorContext &ctx) { |
| 54 | + if (SelfPingWakeupScheduled) |
| 55 | + return; |
| 56 | + |
| 57 | + ctx.Schedule(SELF_PING_INTERVAL, new TEvSchemeShard::TEvWakeupToMeasureSelfResponseTime); |
| 58 | + SelfPingWakeupScheduled = true; |
| 59 | + SelfPingWakeupScheduledTime = AppData(ctx)->TimeProvider->Now(); |
| 60 | +} |
| 61 | + |
| 62 | +} // namespace NKikimr::NSchemeShard |
0 commit comments