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
142
143
144
145
146
147
148
149
150
151
152
153
154
|
#include <library/cpp/messagebus/rain_check/test/helper/misc.h>
#include <library/cpp/messagebus/rain_check/core/rain_check.h>
#include <util/datetime/base.h>
#include <array>
using namespace NRainCheck;
static const unsigned SUBTASKS = 2;
struct TRainCheckPerftestEnv: public TSimpleEnvTemplate<TRainCheckPerftestEnv> {
unsigned SubtasksPerTask;
TRainCheckPerftestEnv()
: TSimpleEnvTemplate<TRainCheckPerftestEnv>(4)
, SubtasksPerTask(1000)
{
}
};
struct TCoroOuter: public ICoroTask {
TRainCheckPerftestEnv* const Env;
TCoroOuter(TRainCheckPerftestEnv* env)
: Env(env)
{
}
void Run() override {
for (;;) {
TInstant start = TInstant::Now();
unsigned count = 0;
unsigned current = 1000;
do {
for (unsigned i = 0; i < current; ++i) {
std::array<TSubtaskCompletion, SUBTASKS> completion;
for (unsigned j = 0; j < SUBTASKS; ++j) {
//SpawnSubtask<TNopSimpleTask>(Env, &completion[j]);
//SpawnSubtask<TSpawnNopTasksCoroTask>(Env, &completion[j], SUBTASKS);
SpawnSubtask<TSpawnNopTasksSimpleTask>(Env, &completion[j], SUBTASKS);
}
WaitForSubtasks();
}
count += current;
current *= 2;
} while (TInstant::Now() - start < TDuration::Seconds(1));
TDuration d = TInstant::Now() - start;
unsigned dns = d.NanoSeconds() / count;
Cerr << dns << "ns per spawn/join\n";
}
}
};
struct TSimpleOuter: public ISimpleTask {
TRainCheckPerftestEnv* const Env;
TSimpleOuter(TRainCheckPerftestEnv* env, const void*)
: Env(env)
{
}
TInstant StartInstant;
unsigned Count;
unsigned Current;
unsigned I;
TContinueFunc Start() override {
StartInstant = TInstant::Now();
Count = 0;
Current = 1000;
I = 0;
return &TSimpleOuter::Spawn;
}
std::array<TSubtaskCompletion, SUBTASKS> Completion;
TContinueFunc Spawn() {
for (unsigned j = 0; j < SUBTASKS; ++j) {
//SpawnSubtask<TNopSimpleTask>(Env, &Completion[j]);
//SpawnSubtask<TSpawnNopTasksCoroTask>(Env, &Completion[j], SUBTASKS);
SpawnSubtask<TSpawnNopTasksSimpleTask>(Env, &Completion[j], SUBTASKS);
}
return &TSimpleOuter::Join;
}
TContinueFunc Join() {
I += 1;
if (I != Current) {
return &TSimpleOuter::Spawn;
}
I = 0;
Count += Current;
Current *= 2;
TDuration d = TInstant::Now() - StartInstant;
if (d < TDuration::Seconds(1)) {
return &TSimpleOuter::Spawn;
}
unsigned dns = d.NanoSeconds() / Count;
Cerr << dns << "ns per spawn/join\n";
return &TSimpleOuter::Start;
}
};
struct TReproduceCrashTask: public ISimpleTask {
TRainCheckPerftestEnv* const Env;
TReproduceCrashTask(TRainCheckPerftestEnv* env)
: Env(env)
{
}
std::array<TSubtaskCompletion, SUBTASKS> Completion;
TContinueFunc Start() override {
for (unsigned j = 0; j < 2; ++j) {
//SpawnSubtask<TNopSimpleTask>(Env, &Completion[j]);
SpawnSubtask<TSpawnNopTasksSimpleTask>(Env, &Completion[j], SUBTASKS);
}
return &TReproduceCrashTask::Start;
}
};
int main(int argc, char** argv) {
Y_UNUSED(argc);
Y_UNUSED(argv);
TRainCheckPerftestEnv env;
env.SpawnTask<TSimpleOuter>("");
//env.SpawnTask<TCoroOuter>();
//env.SpawnTask<TReproduceCrashTask>();
for (;;) {
Sleep(TDuration::Hours(1));
}
return 0;
}
|