diff options
author | Alexander Rutkovsky <alexvru@mail.ru> | 2022-02-10 16:47:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:39 +0300 |
commit | f3646f91e0de459836a7800b9ce3e8dc57a2ab3a (patch) | |
tree | 25c1423200152570c1f8307e5b8304b9bc3840c5 /library/cpp/actors/helpers | |
parent | fccc62e9bfdce9be2fe7e0f23479da3a5512211a (diff) | |
download | ydb-f3646f91e0de459836a7800b9ce3e8dc57a2ab3a.tar.gz |
Restoring authorship annotation for Alexander Rutkovsky <alexvru@mail.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/actors/helpers')
-rw-r--r-- | library/cpp/actors/helpers/activeactors.h | 10 | ||||
-rw-r--r-- | library/cpp/actors/helpers/mon_histogram_helper.h | 6 | ||||
-rw-r--r-- | library/cpp/actors/helpers/selfping_actor.cpp | 106 | ||||
-rw-r--r-- | library/cpp/actors/helpers/selfping_actor.h | 18 | ||||
-rw-r--r-- | library/cpp/actors/helpers/selfping_actor_ut.cpp | 48 |
5 files changed, 94 insertions, 94 deletions
diff --git a/library/cpp/actors/helpers/activeactors.h b/library/cpp/actors/helpers/activeactors.h index 0fdb0fab10..9f8f6a2820 100644 --- a/library/cpp/actors/helpers/activeactors.h +++ b/library/cpp/actors/helpers/activeactors.h @@ -1,11 +1,11 @@ -#pragma once - +#pragma once + #include <library/cpp/actors/core/actor.h> #include <library/cpp/actors/core/events.h> #include <util/generic/hash_set.h> - + namespace NActors { - + //////////////////////////////////////////////////////////////////////////// // TActiveActors // This class helps manage created actors and kill them all on PoisonPill. @@ -38,5 +38,5 @@ namespace NActors { } }; -} // NKikimr +} // NKikimr diff --git a/library/cpp/actors/helpers/mon_histogram_helper.h b/library/cpp/actors/helpers/mon_histogram_helper.h index a9a57e3823..dade3c6506 100644 --- a/library/cpp/actors/helpers/mon_histogram_helper.h +++ b/library/cpp/actors/helpers/mon_histogram_helper.h @@ -1,7 +1,7 @@ #pragma once #include <library/cpp/monlib/dynamic_counters/counters.h> - + #include <util/string/cast.h> namespace NActors { @@ -14,8 +14,8 @@ namespace NActors { { } - THistogramCounterHelper(const THistogramCounterHelper&) = default; - + THistogramCounterHelper(const THistogramCounterHelper&) = default; + void Init(NMonitoring::TDynamicCounters* group, const TString& baseName, const TString& unit, ui64 firstBucket, ui64 bucketCnt, bool useSensorLabelName = true) { diff --git a/library/cpp/actors/helpers/selfping_actor.cpp b/library/cpp/actors/helpers/selfping_actor.cpp index f9bfaf8dc0..97f9c0a856 100644 --- a/library/cpp/actors/helpers/selfping_actor.cpp +++ b/library/cpp/actors/helpers/selfping_actor.cpp @@ -1,15 +1,15 @@ -#include "selfping_actor.h" - +#include "selfping_actor.h" + #include <library/cpp/actors/core/actor_bootstrapped.h> #include <library/cpp/actors/core/hfunc.h> - + #include <library/cpp/containers/stack_vector/stack_vec.h> #include <library/cpp/sliding_window/sliding_window.h> - -namespace NActors { - -namespace { - + +namespace NActors { + +namespace { + struct TEvPing: public TEventLocal<TEvPing, TEvents::THelloWorld::Ping> { TEvPing(double timeStart) : TimeStart(timeStart) @@ -58,47 +58,47 @@ struct TAvgOperation { }; -class TSelfPingActor : public TActorBootstrapped<TSelfPingActor> { -private: - const TDuration SendInterval; - const NMonitoring::TDynamicCounters::TCounterPtr Counter; +class TSelfPingActor : public TActorBootstrapped<TSelfPingActor> { +private: + const TDuration SendInterval; + const NMonitoring::TDynamicCounters::TCounterPtr Counter; const NMonitoring::TDynamicCounters::TCounterPtr CalculationTimeCounter; - + NSlidingWindow::TSlidingWindow<NSlidingWindow::TMaxOperation<ui64>> SlidingWindow; NSlidingWindow::TSlidingWindow<TAvgOperation<ui64>> CalculationSlidingWindow; - + THPTimer Timer; -public: +public: static constexpr auto ActorActivityType() { return SELF_PING_ACTOR; } TSelfPingActor(TDuration sendInterval, const NMonitoring::TDynamicCounters::TCounterPtr& counter, const NMonitoring::TDynamicCounters::TCounterPtr& calculationTimeCounter) - : SendInterval(sendInterval) - , Counter(counter) + : SendInterval(sendInterval) + , Counter(counter) , CalculationTimeCounter(calculationTimeCounter) - , SlidingWindow(TDuration::Seconds(15), 100) + , SlidingWindow(TDuration::Seconds(15), 100) , CalculationSlidingWindow(TDuration::Seconds(15), 100) - { - } - - void Bootstrap(const TActorContext& ctx) - { - Become(&TSelfPingActor::RunningState); + { + } + + void Bootstrap(const TActorContext& ctx) + { + Become(&TSelfPingActor::RunningState); SchedulePing(ctx, Timer.Passed()); - } - - STFUNC(RunningState) - { - switch (ev->GetTypeRewrite()) { + } + + STFUNC(RunningState) + { + switch (ev->GetTypeRewrite()) { HFunc(TEvPing, HandlePing); - default: - Y_FAIL("TSelfPingActor::RunningState: unexpected event 0x%08" PRIx32, ev->GetTypeRewrite()); - } - } - + default: + Y_FAIL("TSelfPingActor::RunningState: unexpected event 0x%08" PRIx32, ev->GetTypeRewrite()); + } + } + ui64 MeasureTaskDurationNs() { // Prepare worm test data // 11 * 11 * 3 * 8 = 2904 bytes, fits in L1 cache @@ -147,37 +147,37 @@ public: } void HandlePing(TEvPing::TPtr &ev, const TActorContext &ctx) - { + { const auto now = ctx.Now(); const double hpNow = Timer.Passed(); - const auto& e = *ev->Get(); + const auto& e = *ev->Get(); const double passedTime = hpNow - e.TimeStart; const ui64 delayUs = passedTime > 0.0 ? static_cast<ui64>(passedTime * 1e6) : 0; - + *Counter = SlidingWindow.Update(delayUs, now); - + ui64 d = MeasureTaskDurationNs(); auto res = CalculationSlidingWindow.Update({1, d}, now); *CalculationTimeCounter = double(res.Sum) / double(res.Count + 1); SchedulePing(ctx, hpNow); - } - -private: + } + +private: void SchedulePing(const TActorContext &ctx, double hpNow) const - { + { ctx.Schedule(SendInterval, new TEvPing(hpNow)); - } -}; - -} // namespace - -IActor* CreateSelfPingActor( - TDuration sendInterval, + } +}; + +} // namespace + +IActor* CreateSelfPingActor( + TDuration sendInterval, const NMonitoring::TDynamicCounters::TCounterPtr& counter, const NMonitoring::TDynamicCounters::TCounterPtr& calculationTimeCounter) -{ +{ return new TSelfPingActor(sendInterval, counter, calculationTimeCounter); -} - -} // NActors +} + +} // NActors diff --git a/library/cpp/actors/helpers/selfping_actor.h b/library/cpp/actors/helpers/selfping_actor.h index d7d07f9fa8..945863d81d 100644 --- a/library/cpp/actors/helpers/selfping_actor.h +++ b/library/cpp/actors/helpers/selfping_actor.h @@ -1,13 +1,13 @@ -#pragma once - +#pragma once + #include <library/cpp/actors/core/actor.h> #include <library/cpp/monlib/dynamic_counters/counters.h> - -namespace NActors { - -NActors::IActor* CreateSelfPingActor( - TDuration sendInterval, + +namespace NActors { + +NActors::IActor* CreateSelfPingActor( + TDuration sendInterval, const NMonitoring::TDynamicCounters::TCounterPtr& counter, const NMonitoring::TDynamicCounters::TCounterPtr& calculationTimeCounter); - -} // NActors + +} // NActors diff --git a/library/cpp/actors/helpers/selfping_actor_ut.cpp b/library/cpp/actors/helpers/selfping_actor_ut.cpp index 459635fa24..1959ace638 100644 --- a/library/cpp/actors/helpers/selfping_actor_ut.cpp +++ b/library/cpp/actors/helpers/selfping_actor_ut.cpp @@ -1,11 +1,11 @@ -#include "selfping_actor.h" - +#include "selfping_actor.h" + #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/actors/testlib/test_runtime.h> - -namespace NActors { -namespace Tests { - + +namespace NActors { +namespace Tests { + THolder<TTestActorRuntimeBase> CreateRuntime() { auto runtime = MakeHolder<TTestActorRuntimeBase>(); runtime->SetScheduledEventFilter([](auto&&, auto&&, auto&&, auto&&) { return false; }); @@ -15,31 +15,31 @@ THolder<TTestActorRuntimeBase> CreateRuntime() { Y_UNIT_TEST_SUITE(TSelfPingTest) { Y_UNIT_TEST(Basic) - { + { auto runtime = CreateRuntime(); - + //const TActorId sender = runtime.AllocateEdgeActor(); - - NMonitoring::TDynamicCounters::TCounterPtr counter(new NMonitoring::TCounterForPtr()); + + NMonitoring::TDynamicCounters::TCounterPtr counter(new NMonitoring::TCounterForPtr()); NMonitoring::TDynamicCounters::TCounterPtr counter2(new NMonitoring::TCounterForPtr()); - - auto actor = CreateSelfPingActor( - TDuration::MilliSeconds(100), // sendInterval (unused in test) + + auto actor = CreateSelfPingActor( + TDuration::MilliSeconds(100), // sendInterval (unused in test) counter, counter2); - + UNIT_ASSERT_VALUES_EQUAL(counter->Val(), 0); UNIT_ASSERT_VALUES_EQUAL(counter2->Val(), 0); const TActorId actorId = runtime->Register(actor); Y_UNUSED(actorId); - + //runtime.Send(new IEventHandle(actorId, sender, new TEvSelfPing::TEvPing(0.0))); - - // TODO check after events are handled - //Sleep(TDuration::Seconds(1)); - //UNIT_ASSERT((intmax_t)counter->Val() >= (intmax_t)Delay.MicroSeconds()); - } -} - -} // namespace Tests -} // namespace NActors + + // TODO check after events are handled + //Sleep(TDuration::Seconds(1)); + //UNIT_ASSERT((intmax_t)counter->Val() >= (intmax_t)Delay.MicroSeconds()); + } +} + +} // namespace Tests +} // namespace NActors |