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
155
156
157
158
159
160
161
162
163
164
165
166
167
|
#include <benchmark/benchmark.h>
#include <library/cpp/yt/logging/logger.h>
#include <atomic>
namespace NYT::NLogging {
namespace {
////////////////////////////////////////////////////////////////////////////////
// A log manager whose Enqueue is essentially free, so that the benchmark measures
// only the producer-side cost (building the event payload), not the logging thread.
class TBenchmarkLogManager
: public ILogManager
{
public:
void RegisterStaticAnchor(TLoggingAnchor* anchor, ::TSourceLocation /*sourceLocation*/, TStringBuf /*message*/) override
{
anchor->Registered.store(true);
}
void UpdateAnchor(TLoggingAnchor* anchor) override
{
anchor->CurrentVersion.store(ActualVersion_.load());
}
void Enqueue(TLogEvent&& event) override
{
// Keep the produced payload observable so the build is not optimized away;
// the event is then destroyed (freeing its chunk slice) -- same for both APIs.
benchmark::DoNotOptimize(std::get<TTaggedLogEventPayload>(event.Payload).Underlying().Begin());
}
const TLoggingCategory* GetCategory(TStringBuf /*categoryName*/) override
{
return &Category_;
}
void UpdateCategory(TLoggingCategory* category) override
{
category->CurrentVersion.store(ActualVersion_.load());
}
bool GetAbortOnAlert() const override
{
return false;
}
private:
std::atomic<int> ActualVersion_ = 1;
TLoggingCategory Category_ = {
.Name = "Bench",
.MinPlainTextLevel = ELogLevel::Minimum,
.CurrentVersion = 0,
.ActualVersion = &ActualVersion_,
};
};
////////////////////////////////////////////////////////////////////////////////
// No tags.
void BM_Log_NoTags(benchmark::State& state)
{
TBenchmarkLogManager manager;
TLogger Logger(&manager, "Bench");
for (auto _ : state) {
YT_LOG_INFO("This is a log message of a typical length without tags");
}
}
BENCHMARK(BM_Log_NoTags);
void BM_TLog_NoTags(benchmark::State& state)
{
TBenchmarkLogManager manager;
TLogger Logger(&manager, "Bench");
for (auto _ : state) {
YT_TLOG_INFO("This is a log message of a typical length without tags");
}
}
BENCHMARK(BM_TLog_NoTags);
////////////////////////////////////////////////////////////////////////////////
// One int tag.
void BM_Log_OneTag(benchmark::State& state)
{
TBenchmarkLogManager manager;
TLogger Logger(&manager, "Bench");
for (auto _ : state) {
YT_LOG_INFO("This is a log message of a typical length (TagName: %v)",
123);
}
}
BENCHMARK(BM_Log_OneTag);
void BM_TLog_OneTag(benchmark::State& state)
{
TBenchmarkLogManager manager;
TLogger Logger(&manager, "Bench");
for (auto _ : state) {
YT_TLOG_INFO("This is a log message of a typical length")
.With("TagName", 123);
}
}
BENCHMARK(BM_TLog_OneTag);
////////////////////////////////////////////////////////////////////////////////
// Two tags (int + string).
void BM_Log_TwoTags(benchmark::State& state)
{
TBenchmarkLogManager manager;
TLogger Logger(&manager, "Bench");
for (auto _ : state) {
YT_LOG_INFO("This is a log message of a typical length (TagName1: %v, TagName2: %v)",
123,
"this-is-a-string");
}
}
BENCHMARK(BM_Log_TwoTags);
void BM_TLog_TwoTags(benchmark::State& state)
{
TBenchmarkLogManager manager;
TLogger Logger(&manager, "Bench");
for (auto _ : state) {
YT_TLOG_INFO("This is a log message of a typical length")
.With("TagName1", 123)
.With("TagName2", "this-is-a-string");
}
}
BENCHMARK(BM_TLog_TwoTags);
////////////////////////////////////////////////////////////////////////////////
// Three tags (int + string + double).
void BM_Log_ThreeTags(benchmark::State& state)
{
TBenchmarkLogManager manager;
TLogger Logger(&manager, "Bench");
for (auto _ : state) {
YT_LOG_INFO("This is a log message of a typical length (TagName1: %v, TagName2: %v, TagName3: %v)",
123,
"this-is-a-string",
3.14);
}
}
BENCHMARK(BM_Log_ThreeTags);
void BM_TLog_ThreeTags(benchmark::State& state)
{
TBenchmarkLogManager manager;
TLogger Logger(&manager, "Bench");
for (auto _ : state) {
YT_TLOG_INFO("This is a log message of a typical length")
.With("TagName1", 123)
.With("TagName2", "this-is-a-string")
.With("TagName3", 3.14);
}
}
BENCHMARK(BM_TLog_ThreeTags);
////////////////////////////////////////////////////////////////////////////////
} // namespace
} // namespace NYT::NLogging
|