1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#include "service_actor.h"
#include <ydb/core/base/appdata.h>
#include <library/cpp/monlib/service/pages/templates.h>
namespace NKikimr {
class TMemoryLoadTestActor : public TActorBootstrapped<TMemoryLoadTestActor> {
enum {
EvAllocateBlock = EventSpaceBegin(TEvents::ES_PRIVATE),
EvEnd
};
struct TEvAllocateBlock : public TEventLocal<TEvAllocateBlock, EvAllocateBlock> {};
const TActorId Parent;
const ui64 Tag;
TDuration Duration;
ui64 BlockSize;
TDuration Interval;
TInstant TestStartTime;
TVector<TVector<char>> Blocks;
ui64 AllocatedSize = 0;
public:
static constexpr auto ActorActivityType() {
return NKikimrServices::TActivity::BS_LOAD_PDISK_LOG_WRITE;
}
TMemoryLoadTestActor(const NKikimr::TEvLoadTestRequest::TMemoryLoadStart& cmd,
const TActorId& parent, const TIntrusivePtr<::NMonitoring::TDynamicCounters>& counters, ui64 index, ui64 tag)
: Parent(parent)
, Tag(tag)
{
Y_UNUSED(counters);
Y_UNUSED(index);
VERIFY_PARAM(DurationSeconds);
Duration = TDuration::Seconds(cmd.GetDurationSeconds());
VERIFY_PARAM(BlockSize);
BlockSize = cmd.GetBlockSize();
VERIFY_PARAM(IntervalUs);
Interval = TDuration::MicroSeconds(cmd.GetIntervalUs());
Blocks.reserve(Duration.MicroSeconds() / Interval.MicroSeconds() + 1);
}
void Bootstrap(const TActorContext& ctx) {
LOG_DEBUG_S(ctx, NKikimrServices::BS_LOAD_TEST, "Tag# " << Tag
<< " TMemoryLoadTestActor Bootstrap called");
Become(&TMemoryLoadTestActor::StateFunc);
LOG_INFO_S(ctx, NKikimrServices::BS_LOAD_TEST, "Tag# " << Tag
<< " Schedule PoisonPill");
ctx.Schedule(Duration, new TEvents::TEvPoisonPill);
ctx.Schedule(Interval, new TEvAllocateBlock);
TestStartTime = TAppData::TimeProvider->Now();
}
void HandlePoisonPill(const TActorContext& ctx) {
LOG_INFO_S(ctx, NKikimrServices::BS_LOAD_TEST, "Tag# " << Tag
<< " Handle PoisonPill");
TIntrusivePtr<TEvLoad::TLoadReport> report(new TEvLoad::TLoadReport());
report->Duration = Duration;
ctx.Send(Parent, new TEvLoad::TEvLoadTestFinished(Tag, report, "OK"));
Die(ctx);
}
void Handle(TEvAllocateBlock::TPtr&, const TActorContext& ctx) {
auto size = RandomNumber<ui64>(BlockSize * 2 + 1);
Blocks.push_back({});
auto& block = Blocks.back();
block.resize(size);
for (size_t i = 0; i < size; ++i) {
block[i] = 0;
}
AllocatedSize += size;
LOG_DEBUG_S(ctx, NKikimrServices::BS_LOAD_TEST, "Tag# " << Tag
<< " Handle AllocateBlock");
ctx.Schedule(Interval, new TEvAllocateBlock);
}
void Handle(NMon::TEvHttpInfo::TPtr& ev, const TActorContext& ctx) {
#define PARAM(NAME, VALUE) \
TABLER() { \
TABLED() { str << NAME; } \
TABLED() { str << VALUE; } \
}
TStringStream str;
HTML(str) {
TABLE_CLASS("table table-condensed") {
TABLEHEAD() {
TABLER() {
TABLEH() { str << "Parameter"; }
TABLEH() { str << "Value"; }
}
}
TABLEBODY() {
PARAM("Elapsed time / Duration",
(TAppData::TimeProvider->Now() - TestStartTime).Seconds() << "s / "
<< Duration.Seconds() << "s");
PARAM("Interval", Interval.MicroSeconds() << "us");
PARAM("Block size", BlockSize);
PARAM("Allocated bytes", AllocatedSize);
PARAM("Allocated blocks", Blocks.size());
}
}
}
ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(str.Str(), ev->Get()->SubRequestId));
}
STRICT_STFUNC(StateFunc,
CFunc(TEvents::TSystem::PoisonPill, HandlePoisonPill)
HFunc(TEvAllocateBlock, Handle)
HFunc(NMon::TEvHttpInfo, Handle)
)
};
IActor* CreateMemoryLoadTest(
const NKikimr::TEvLoadTestRequest::TMemoryLoadStart& cmd,
const TActorId& parent,
const TIntrusivePtr<::NMonitoring::TDynamicCounters>& counters,
ui64 index,
ui64 tag)
{
return new TMemoryLoadTestActor(cmd, parent, counters, index, tag);
}
} // NKikimr
|