9
9
#include < ydb/core/tablet_flat/test/libs/table/test_make.h>
10
10
#include < ydb/core/tablet_flat/test/libs/table/test_mixer.h>
11
11
#include " ydb/core/tablet_flat/flat_part_btree_index_iter.h"
12
+ #include " ydb/core/tablet_flat/flat_stat_table.h"
12
13
#include " ydb/core/tablet_flat/test/libs/table/wrap_iter.h"
14
+ #include " ydb/core/tx/datashard/datashard.h"
13
15
#include < ydb/core/tablet_flat/test/libs/table/test_writer.h>
14
16
#include < ydb/core/tablet_flat/test/libs/table/test_envs.h>
15
17
#include < ydb/core/tablet_flat/test/libs/table/wrap_part.h>
16
18
#include < ydb/core/tablet_flat/test/libs/table/test_steps.h>
17
19
18
- namespace NKikimr {
19
- namespace NTable {
20
+ #ifndef BENCHMARK_MAKE_LARGE_PART
21
+ #define BENCHMARK_MAKE_LARGE_PART 0
22
+ #endif
23
+
24
+ namespace NKikimr ::NTable {
20
25
21
26
namespace {
22
27
using namespace NTest ;
@@ -26,81 +31,39 @@ namespace {
26
31
27
32
NPage::TConf PageConf (size_t groups, bool writeBTreeIndex) noexcept
28
33
{
29
- NPage::TConf conf{ true , 1024 } ;
34
+ NPage::TConf conf;
30
35
31
36
conf.Groups .resize (groups);
32
- for (size_t group : xrange (groups)) {
33
- conf.Group (group).PageSize = 1024 ;
34
- conf.Group (group).BTreeIndexNodeTargetSize = 1024 ;
35
- }
36
-
37
+
37
38
conf.WriteBTreeIndex = writeBTreeIndex;
38
39
39
40
conf.SliceSize = conf.Group (0 ).PageSize * 4 ;
40
41
41
42
return conf;
42
43
}
43
44
44
- struct TPartEggsFixture : public benchmark ::Fixture {
45
- using TGroupId = NPage::TGroupId;
46
-
47
- void SetUp (const ::benchmark::State& state)
48
- {
49
- const bool groups = state.range (1 );
50
-
51
- TLayoutCook lay;
52
-
53
- lay
54
- .Col (0 , 0 , NScheme::NTypeIds::Uint32)
55
- .Col (0 , 1 , NScheme::NTypeIds::Uint32)
56
- .Col (0 , 2 , NScheme::NTypeIds::Uint32)
57
- .Col (0 , 3 , NScheme::NTypeIds::Uint32)
58
- .Col (groups ? 1 : 0 , 4 , NScheme::NTypeIds::Uint32)
59
- .Key ({0 , 1 , 2 });
60
-
61
- TPartCook cook (lay, PageConf (groups ? 2 : 1 , true ));
62
-
63
- for (ui32 i = 0 ; (groups ? cook.GetDataBytes (0 ) + cook.GetDataBytes (1 ) : cook.GetDataBytes (0 )) < 100ull *1024 *1024 ; i++) {
64
- cook.Add (*TSchemedCookRow (*lay).Col (i / 10000 , i / 100 % 100 , i % 100 , i, i));
65
- }
66
-
67
- Eggs = cook.Finish ();
68
-
69
- const auto part = Eggs.Lone ();
70
-
71
- Cerr << " DataBytes = " << part->Stat .Bytes << " DataPages = " << IndexTools::CountMainPages (*part) << Endl;
72
- Cerr << " FlatIndexBytes = " << part->GetPageSize (part->IndexPages .Groups [groups ? 1 : 0 ], {}) << " BTreeIndexBytes = " << part->IndexPages .BTreeGroups [groups ? 1 : 0 ].IndexSize << Endl;
73
- Cerr << " Levels = " << part->IndexPages .BTreeGroups [groups ? 1 : 0 ].LevelCount << Endl;
74
-
75
- // 100 MB
76
- UNIT_ASSERT_GE (part->Stat .Bytes , 100ull *1024 *1024 );
77
- UNIT_ASSERT_LE (part->Stat .Bytes , 100ull *1024 *1024 + 10ull *1024 *1024 );
78
-
79
- GroupId = TGroupId (groups ? 1 : 0 );
80
- }
81
-
82
- TPartEggs Eggs;
83
- TTestEnv Env;
84
- TGroupId GroupId;
85
- };
86
-
87
- struct TPartSubsetFixture : public benchmark ::Fixture {
45
+ struct TPartFixture : public benchmark ::Fixture {
88
46
using TGroupId = NPage::TGroupId;
89
47
90
- void SetUp (const ::benchmark::State& state)
48
+ void SetUp (::benchmark::State& state)
91
49
{
92
50
const bool useBTree = state.range (0 );
93
51
const bool groups = state.range (1 );
94
52
const bool history = state.range (2 );
95
53
96
- Mass = new NTest::TMass (new NTest::TModelStd (groups), history ? 1000000 : 300000 );
54
+ ui64 rows = history ? 300000 : 1000000 ;
55
+ if (BENCHMARK_MAKE_LARGE_PART) {
56
+ rows *= 10 ;
57
+ }
58
+ Mass = new NTest::TMass (new NTest::TModelStd (groups), rows);
97
59
Subset = TMake (*Mass, PageConf (Mass->Model ->Scheme ->Families .size (), useBTree)).Mixed (0 , 1 , TMixerOne{ }, history ? 0.7 : 0 );
98
60
99
- for (const auto & part : Subset->Flatten ) {
100
- Cerr << " DataBytes = " << part->Stat .Bytes << " DataPages = " << IndexTools::CountMainPages (*part) << Endl;
101
- Cerr << " FlatIndexBytes = " << part->GetPageSize (part->IndexPages .Groups [groups ? 1 : 0 ], {}) << " BTreeIndexBytes = " << (useBTree ? part->IndexPages .BTreeGroups [groups ? 1 : 0 ].IndexSize : 0 ) << Endl;
61
+ for (const auto & part : Subset->Flatten ) { // single part
62
+ state.counters [" DataBytes" ] = part->Stat .Bytes ;
63
+ state.counters [" DataPages" ] = IndexTools::CountMainPages (*part);
64
+ state.counters [" IndexBytes" ] = part->IndexesRawSize ;
102
65
if (useBTree) {
103
- Cerr << " Levels = " << part->IndexPages .BTreeGroups [groups ? 1 : 0 ].LevelCount << Endl ;
66
+ state. counters [ " Levels{0} " ] = part->IndexPages .BTreeGroups [0 ].LevelCount ;
104
67
}
105
68
}
106
69
@@ -111,6 +74,9 @@ namespace {
111
74
Checker = new TCheckIt (*Subset, {new TTestEnv ()});
112
75
CheckerReverse = new TCheckReverseIt (*Subset, {new TTestEnv ()});
113
76
}
77
+
78
+ GroupId = TGroupId (groups, history);
79
+ Part = Subset->Flatten [0 ].Part .Get ();
114
80
}
115
81
116
82
TMersenne<ui64> Rnd;
@@ -119,87 +85,99 @@ namespace {
119
85
TAutoPtr<TCheckIt> Checker;
120
86
TAutoPtr<TCheckReverseIt> CheckerReverse;
121
87
TTestEnv Env;
88
+ TGroupId GroupId;
89
+ TPart const * Part;
122
90
};
123
91
}
124
92
125
- BENCHMARK_DEFINE_F (TPartEggsFixture , SeekRowId)(benchmark::State& state) {
93
+ BENCHMARK_DEFINE_F (TPartFixture , SeekRowId)(benchmark::State& state) {
126
94
const bool useBTree = state.range (0 );
127
95
128
96
for (auto _ : state) {
129
97
THolder<IIndexIter> iter;
130
98
131
99
if (useBTree) {
132
- iter = MakeHolder<TPartBtreeIndexIt>(Eggs. Lone (). Get () , &Env, GroupId);
100
+ iter = MakeHolder<TPartBtreeIndexIt>(Part , &Env, GroupId);
133
101
} else {
134
- iter = MakeHolder<TPartIndexIt>(Eggs. Lone (). Get () , &Env, GroupId);
102
+ iter = MakeHolder<TPartIndexIt>(Part , &Env, GroupId);
135
103
}
136
104
137
- iter->Seek (RandomNumber<ui32>(Eggs. Lone () ->Stat .Rows ));
105
+ iter->Seek (RandomNumber<ui32>(Part ->Stat .Rows ));
138
106
}
139
107
}
140
108
141
- BENCHMARK_DEFINE_F (TPartEggsFixture , Next)(benchmark::State& state) {
109
+ BENCHMARK_DEFINE_F (TPartFixture , Next)(benchmark::State& state) {
142
110
const bool useBTree = state.range (0 );
143
111
144
112
THolder<IIndexIter> iter;
145
113
146
114
if (useBTree) {
147
- iter = MakeHolder<TPartBtreeIndexIt>(Eggs. Lone (). Get () , &Env, GroupId);
115
+ iter = MakeHolder<TPartBtreeIndexIt>(Part , &Env, GroupId);
148
116
} else {
149
- iter = MakeHolder<TPartIndexIt>(Eggs. Lone (). Get () , &Env, GroupId);
117
+ iter = MakeHolder<TPartIndexIt>(Part , &Env, GroupId);
150
118
}
151
119
152
- iter->Seek (RandomNumber<ui32>(Eggs. Lone () ->Stat .Rows ));
120
+ iter->Seek (RandomNumber<ui32>(Part ->Stat .Rows ));
153
121
154
122
for (auto _ : state) {
155
123
if (!iter->IsValid ()) {
156
- iter->Seek (RandomNumber<ui32>(Eggs. Lone () ->Stat .Rows ));
124
+ iter->Seek (RandomNumber<ui32>(Part ->Stat .Rows ));
157
125
}
158
126
iter->Next ();
159
127
}
160
128
}
161
129
162
- BENCHMARK_DEFINE_F (TPartEggsFixture , Prev)(benchmark::State& state) {
130
+ BENCHMARK_DEFINE_F (TPartFixture , Prev)(benchmark::State& state) {
163
131
const bool useBTree = state.range (0 );
164
132
165
133
THolder<IIndexIter> iter;
166
134
167
135
if (useBTree) {
168
- iter = MakeHolder<TPartBtreeIndexIt>(Eggs. Lone (). Get () , &Env, GroupId);
136
+ iter = MakeHolder<TPartBtreeIndexIt>(Part , &Env, GroupId);
169
137
} else {
170
- iter = MakeHolder<TPartIndexIt>(Eggs. Lone (). Get () , &Env, GroupId);
138
+ iter = MakeHolder<TPartIndexIt>(Part , &Env, GroupId);
171
139
}
172
140
173
- iter->Seek (RandomNumber<ui32>(Eggs. Lone () ->Stat .Rows ));
141
+ iter->Seek (RandomNumber<ui32>(Part ->Stat .Rows ));
174
142
175
143
for (auto _ : state) {
176
144
if (!iter->IsValid ()) {
177
- iter->Seek (RandomNumber<ui32>(Eggs. Lone () ->Stat .Rows ));
145
+ iter->Seek (RandomNumber<ui32>(Part ->Stat .Rows ));
178
146
}
179
147
iter->Prev ();
180
148
}
181
149
}
182
150
183
- BENCHMARK_DEFINE_F (TPartEggsFixture , SeekKey)(benchmark::State& state) {
151
+ BENCHMARK_DEFINE_F (TPartFixture , SeekKey)(benchmark::State& state) {
184
152
const bool useBTree = state.range (0 );
185
- const ESeek seek = ESeek (state.range (2 ));
153
+ const ESeek seek = ESeek (state.range (3 ));
154
+
155
+ TRowTool rowTool (*Subset->Scheme );
156
+ auto tags = TVector<TTag>();
157
+ for (auto c : Subset->Scheme ->Cols ) {
158
+ tags.push_back (c.Tag );
159
+ }
186
160
187
161
for (auto _ : state) {
188
162
THolder<IIndexIter> iter;
189
163
190
164
if (useBTree) {
191
- iter = MakeHolder<TPartBtreeIndexIt>(Eggs. Lone (). Get () , &Env, GroupId);
165
+ iter = MakeHolder<TPartBtreeIndexIt>(Part , &Env, GroupId);
192
166
} else {
193
- iter = MakeHolder<TPartIndexIt>(Eggs. Lone (). Get () , &Env, GroupId);
167
+ iter = MakeHolder<TPartIndexIt>(Part , &Env, GroupId);
194
168
}
195
169
196
- ui32 rowId = RandomNumber<ui32>(Eggs.Lone ()->Stat .Rows );
197
- TVector<TCell> key{TCell::Make (rowId / 10000 ), TCell::Make (rowId / 100 % 100 ), TCell::Make (rowId % 100 )};
198
- iter->Seek (seek, key, Eggs.Scheme ->Keys .Get ());
170
+ state.PauseTiming ();
171
+ auto & row = *Mass->Saved .Any (Rnd);
172
+ auto key_ = rowTool.LookupKey (row);
173
+ const TCelled key (key_, *Subset->Scheme ->Keys , false );
174
+ state.ResumeTiming ();
175
+
176
+ iter->Seek (seek, key, Subset->Scheme ->Keys .Get ());
199
177
}
200
178
}
201
179
202
- BENCHMARK_DEFINE_F (TPartSubsetFixture , DoReads)(benchmark::State& state) {
180
+ BENCHMARK_DEFINE_F (TPartFixture , DoReads)(benchmark::State& state) {
203
181
const bool reverse = state.range (3 );
204
182
const ESeek seek = static_cast <ESeek>(state.range (4 ));
205
183
const ui32 items = state.range (5 );
@@ -221,7 +199,7 @@ BENCHMARK_DEFINE_F(TPartSubsetFixture, DoReads)(benchmark::State& state) {
221
199
}
222
200
}
223
201
224
- BENCHMARK_DEFINE_F (TPartSubsetFixture , DoCharge)(benchmark::State& state) {
202
+ BENCHMARK_DEFINE_F (TPartFixture , DoCharge)(benchmark::State& state) {
225
203
const bool reverse = state.range (3 );
226
204
const ui32 items = state.range (4 );
227
205
@@ -245,32 +223,43 @@ BENCHMARK_DEFINE_F(TPartSubsetFixture, DoCharge)(benchmark::State& state) {
245
223
}
246
224
}
247
225
248
- BENCHMARK_REGISTER_F (TPartEggsFixture, SeekRowId)
226
+ BENCHMARK_DEFINE_F (TPartFixture, BuildStats)(benchmark::State& state) {
227
+ for (auto _ : state) {
228
+ TStats stats;
229
+ BuildStats (*Subset, stats, NDataShard::gDbStatsRowCountResolution , NDataShard::gDbStatsDataSizeResolution , &Env);
230
+ }
231
+ }
232
+
233
+ BENCHMARK_REGISTER_F (TPartFixture, SeekRowId)
249
234
->ArgsProduct ({
250
235
/* b-tree */ {0 , 1 },
251
- /* groups: */ {0 , 1 }})
236
+ /* groups: */ {0 , 1 },
237
+ /* history: */ {0 }})
252
238
->Unit(benchmark::kMicrosecond );
253
239
254
- BENCHMARK_REGISTER_F (TPartEggsFixture , Next)
240
+ BENCHMARK_REGISTER_F (TPartFixture , Next)
255
241
->ArgsProduct ({
256
242
/* b-tree */ {0 , 1 },
257
- /* groups: */ {0 , 1 }})
243
+ /* groups: */ {0 , 1 },
244
+ /* history: */ {0 }})
258
245
->Unit(benchmark::kMicrosecond );
259
246
260
- BENCHMARK_REGISTER_F (TPartEggsFixture , Prev)
247
+ BENCHMARK_REGISTER_F (TPartFixture , Prev)
261
248
->ArgsProduct ({
262
249
/* b-tree */ {0 , 1 },
263
- /* groups: */ {0 , 1 }})
250
+ /* groups: */ {0 , 1 },
251
+ /* history: */ {0 }})
264
252
->Unit(benchmark::kMicrosecond );
265
253
266
- BENCHMARK_REGISTER_F (TPartEggsFixture , SeekKey)
254
+ BENCHMARK_REGISTER_F (TPartFixture , SeekKey)
267
255
->ArgsProduct ({
268
256
/* b-tree */ {0 , 1 },
269
257
/* groups: */ {0 , 1 },
258
+ /* history: */ {0 },
270
259
/* ESeek: */ {1 }})
271
260
->Unit(benchmark::kMicrosecond );
272
261
273
- BENCHMARK_REGISTER_F (TPartSubsetFixture , DoReads)
262
+ BENCHMARK_REGISTER_F (TPartFixture , DoReads)
274
263
->ArgsProduct ({
275
264
/* b-tree */ {0 , 1 },
276
265
/* groups: */ {1 },
@@ -280,7 +269,7 @@ BENCHMARK_REGISTER_F(TPartSubsetFixture, DoReads)
280
269
/* items */ {1 , 50 , 1000 }})
281
270
->Unit(benchmark::kMicrosecond );
282
271
283
- BENCHMARK_REGISTER_F (TPartSubsetFixture , DoCharge)
272
+ BENCHMARK_REGISTER_F (TPartFixture , DoCharge)
284
273
->ArgsProduct ({
285
274
/* b-tree */ {0 , 1 },
286
275
/* groups: */ {1 },
@@ -289,5 +278,11 @@ BENCHMARK_REGISTER_F(TPartSubsetFixture, DoCharge)
289
278
/* items */ {1 , 50 , 1000 }})
290
279
->Unit(benchmark::kMicrosecond );
291
280
292
- }
281
+ BENCHMARK_REGISTER_F (TPartFixture, BuildStats)
282
+ ->ArgsProduct ({
283
+ /* b-tree */ {0 , 1 },
284
+ /* groups: */ {0 , 1 },
285
+ /* history: */ {0 , 1 }})
286
+ ->Unit(benchmark::kMicrosecond );
287
+
293
288
}
0 commit comments