Skip to content

Commit

Permalink
Merge 971eba6 into f672e57
Browse files Browse the repository at this point in the history
  • Loading branch information
kunga authored Feb 13, 2024
2 parents f672e57 + 971eba6 commit 1981e75
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 280 deletions.
153 changes: 0 additions & 153 deletions ydb/core/tablet_flat/benchmark/b_charge.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace {
return conf;
}

struct TPartIndexSeekFixture : public benchmark::Fixture {
struct TPartEggsFixture : public benchmark::Fixture {
using TGroupId = NPage::TGroupId;

void SetUp(const ::benchmark::State& state)
Expand Down Expand Up @@ -84,7 +84,7 @@ namespace {
TGroupId GroupId;
};

struct TPartIndexIteratorFixture : public benchmark::Fixture {
struct TPartSubsetFixture : public benchmark::Fixture {
using TGroupId = NPage::TGroupId;

void SetUp(const ::benchmark::State& state)
Expand All @@ -96,6 +96,14 @@ namespace {
Mass = new NTest::TMass(new NTest::TModelStd(groups), history ? 1000000 : 300000);
Subset = TMake(*Mass, PageConf(Mass->Model->Scheme->Families.size(), useBTree)).Mixed(0, 1, TMixerOne{ }, history ? 0.7 : 0);

for (const auto& part : Subset->Flatten) {
Cerr << "DataBytes = " << part->Stat.Bytes << " DataPages = " << IndexTools::CountMainPages(*part) << Endl;
Cerr << "FlatIndexBytes = " << part->GetPageSize(part->IndexPages.Groups[groups ? 1 : 0], {}) << " BTreeIndexBytes = " << (useBTree ? part->IndexPages.BTreeGroups[groups ? 1 : 0].IndexSize : 0) << Endl;
if (useBTree) {
Cerr << "Levels = " << part->IndexPages.BTreeGroups[groups ? 1 : 0].LevelCount << Endl;
}
}

if (history) {
Checker = new TCheckIt(*Subset, {new TTestEnv()}, TRowVersion(0, 8));
CheckerReverse = new TCheckReverseIt(*Subset, {new TTestEnv()}, TRowVersion(0, 8));
Expand All @@ -110,10 +118,11 @@ namespace {
TAutoPtr<TSubset> Subset;
TAutoPtr<TCheckIt> Checker;
TAutoPtr<TCheckReverseIt> CheckerReverse;
TTestEnv Env;
};
}

BENCHMARK_DEFINE_F(TPartIndexSeekFixture, SeekRowId)(benchmark::State& state) {
BENCHMARK_DEFINE_F(TPartEggsFixture, SeekRowId)(benchmark::State& state) {
const bool useBTree = state.range(0);

for (auto _ : state) {
Expand All @@ -129,7 +138,7 @@ BENCHMARK_DEFINE_F(TPartIndexSeekFixture, SeekRowId)(benchmark::State& state) {
}
}

BENCHMARK_DEFINE_F(TPartIndexSeekFixture, Next)(benchmark::State& state) {
BENCHMARK_DEFINE_F(TPartEggsFixture, Next)(benchmark::State& state) {
const bool useBTree = state.range(0);

THolder<IIndexIter> iter;
Expand All @@ -150,7 +159,7 @@ BENCHMARK_DEFINE_F(TPartIndexSeekFixture, Next)(benchmark::State& state) {
}
}

BENCHMARK_DEFINE_F(TPartIndexSeekFixture, Prev)(benchmark::State& state) {
BENCHMARK_DEFINE_F(TPartEggsFixture, Prev)(benchmark::State& state) {
const bool useBTree = state.range(0);

THolder<IIndexIter> iter;
Expand All @@ -171,7 +180,7 @@ BENCHMARK_DEFINE_F(TPartIndexSeekFixture, Prev)(benchmark::State& state) {
}
}

BENCHMARK_DEFINE_F(TPartIndexSeekFixture, SeekKey)(benchmark::State& state) {
BENCHMARK_DEFINE_F(TPartEggsFixture, SeekKey)(benchmark::State& state) {
const bool useBTree = state.range(0);
const ESeek seek = ESeek(state.range(2));

Expand All @@ -190,7 +199,7 @@ BENCHMARK_DEFINE_F(TPartIndexSeekFixture, SeekKey)(benchmark::State& state) {
}
}

BENCHMARK_DEFINE_F(TPartIndexIteratorFixture, DoReads)(benchmark::State& state) {
BENCHMARK_DEFINE_F(TPartSubsetFixture, DoReads)(benchmark::State& state) {
const bool reverse = state.range(3);
const ESeek seek = static_cast<ESeek>(state.range(4));
const ui32 items = state.range(5);
Expand All @@ -212,39 +221,72 @@ BENCHMARK_DEFINE_F(TPartIndexIteratorFixture, DoReads)(benchmark::State& state)
}
}

BENCHMARK_REGISTER_F(TPartIndexSeekFixture, SeekRowId)
BENCHMARK_DEFINE_F(TPartSubsetFixture, DoCharge)(benchmark::State& state) {
const bool reverse = state.range(3);
const ui32 items = state.range(4);

auto tags = TVector<TTag>();
for (auto c : Subset->Scheme->Cols) {
tags.push_back(c.Tag);
}
TRun run(*Subset->Scheme->Keys);
NTest::TRowTool tool(*Subset->Scheme);

for (auto _ : state) {
auto row1 = Rnd.Uniform(Mass->Saved.Size());
auto row2 = Min(row1 + items, Mass->Saved.Size() - 1);
auto key1 = tool.KeyCells(Mass->Saved[row1]);
auto key2 = tool.KeyCells(Mass->Saved[row2]);
if (reverse) {
ChargeRangeReverse(&Env, key1, key2, run, *Subset->Scheme->Keys, tags, items, 0);
} else {
ChargeRange(&Env, key1, key2, run, *Subset->Scheme->Keys, tags, items, 0);
}
}
}

BENCHMARK_REGISTER_F(TPartEggsFixture, SeekRowId)
->ArgsProduct({
/* b-tree */ {0, 1},
/* groups: */ {0, 1}})
->Unit(benchmark::kMicrosecond);

BENCHMARK_REGISTER_F(TPartIndexSeekFixture, Next)
BENCHMARK_REGISTER_F(TPartEggsFixture, Next)
->ArgsProduct({
/* b-tree */ {0, 1},
/* groups: */ {0, 1}})
->Unit(benchmark::kMicrosecond);

BENCHMARK_REGISTER_F(TPartIndexSeekFixture, Prev)
BENCHMARK_REGISTER_F(TPartEggsFixture, Prev)
->ArgsProduct({
/* b-tree */ {0, 1},
/* groups: */ {0, 1}})
->Unit(benchmark::kMicrosecond);

BENCHMARK_REGISTER_F(TPartIndexSeekFixture, SeekKey)
BENCHMARK_REGISTER_F(TPartEggsFixture, SeekKey)
->ArgsProduct({
/* b-tree */ {0, 1},
/* groups: */ {0, 1},
/* ESeek: */ {0, 1, 2}})
/* ESeek: */ {1}})
->Unit(benchmark::kMicrosecond);

BENCHMARK_REGISTER_F(TPartIndexIteratorFixture, DoReads)
BENCHMARK_REGISTER_F(TPartSubsetFixture, DoReads)
->ArgsProduct({
/* b-tree */ {0, 1},
/* groups: */ {1},
/* history: */ {1},
/* reverse: */ {0},
/* ESeek: */ {1},
/* items */ {1, 10, 100}})
/* items */ {1, 50, 1000}})
->Unit(benchmark::kMicrosecond);

BENCHMARK_REGISTER_F(TPartSubsetFixture, DoCharge)
->ArgsProduct({
/* b-tree */ {0, 1},
/* groups: */ {1},
/* history: */ {1},
/* reverse: */ {0},
/* items */ {1, 50, 1000}})
->Unit(benchmark::kMicrosecond);

}
Expand Down
3 changes: 1 addition & 2 deletions ydb/core/tablet_flat/benchmark/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ SIZE(LARGE)
TIMEOUT(1200)

SRCS(
b_charge.cpp
b_part_index.cpp
b_part.cpp
)

PEERDIR(
Expand Down
8 changes: 4 additions & 4 deletions ydb/core/tablet_flat/flat_part_charge_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ bool ChargeRange(IPages *env, const TCells key1, const TCells key2,
if (r.Overshot && ++pos != run.end()) {
// Unfortunately first key > key2 might be at the start of the next slice
TRowId firstRow = pos->Slice.BeginRowId();
// Precharge the first row on the next slice
ready &= CreateCharge(env, *pos->Part, tags, includeHistory)->Do(firstRow, firstRow, keyDefaults, items, bytes);
// Precharge the first row main key on the next slice
ready &= CreateCharge(env, *pos->Part, { }, false)->Do(firstRow, firstRow, keyDefaults, items, bytes);
}

break;
Expand Down Expand Up @@ -98,8 +98,8 @@ bool ChargeRangeReverse(IPages *env, const TCells key1, const TCells key2,
--pos;
// Unfortunately first key <= key2 might be at the end of the previous slice
TRowId lastRow = pos->Slice.EndRowId() - 1;
// Precharge the last row on the previous slice
ready &= CreateCharge(env, *pos->Part, tags, includeHistory)->DoReverse(lastRow, lastRow, keyDefaults, items, bytes);
// Precharge the last row main key on the previous slice
ready &= CreateCharge(env, *pos->Part, { }, false)->DoReverse(lastRow, lastRow, keyDefaults, items, bytes);
}

break;
Expand Down
12 changes: 6 additions & 6 deletions ydb/core/tablet_flat/test/libs/table/test_part.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace NTest {
namespace IndexTools {
using TGroupId = NPage::TGroupId;

inline size_t CountMainPages(const TPartStore& part) {
inline size_t CountMainPages(const TPart& part) {
size_t result = 0;

TTestEnv env;
Expand All @@ -165,20 +165,20 @@ namespace NTest {
return result;
}

inline TRowId GetEndRowId(const TPartStore& part) {
inline TRowId GetEndRowId(const TPart& part) {
TTestEnv env;
TPartIndexIt index(&part, &env, { });
return index.GetEndRowId();
}

inline const TPartIndexIt::TRecord * GetLastRecord(const TPartStore& part) {
inline const TPartIndexIt::TRecord * GetLastRecord(const TPart& part) {
TTestEnv env;
TPartIndexIt index(&part, &env, { });
Y_ABORT_UNLESS(index.SeekLast() == EReady::Data);
return index.GetLastRecord();
}

inline const TPartIndexIt::TRecord * GetRecord(const TPartStore& part, ui32 pageIndex) {
inline const TPartIndexIt::TRecord * GetRecord(const TPart& part, ui32 pageIndex) {
TTestEnv env;
TPartIndexIt index(&part, &env, { });

Expand All @@ -190,14 +190,14 @@ namespace NTest {
return index.GetRecord();
}

inline TPageId GetFirstPageId(const TPartStore& part, TGroupId groupId) {
inline TPageId GetFirstPageId(const TPart& part, TGroupId groupId) {
TTestEnv env;
TPartIndexIt index(&part, &env, groupId);
index.Seek(0);
return index.GetPageId();
}

inline TPageId GetLastPageId(const TPartStore& part, TGroupId groupId) {
inline TPageId GetLastPageId(const TPart& part, TGroupId groupId) {
TTestEnv env;
TPartIndexIt index(&part, &env, groupId);
index.Seek(index.GetEndRowId() - 1);
Expand Down
Loading

0 comments on commit 1981e75

Please sign in to comment.