Skip to content

Commit

Permalink
update leaderboard bench
Browse files Browse the repository at this point in the history
  • Loading branch information
connortsui20 committed Sep 11, 2024
1 parent 4bbeb91 commit fce877d
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions tools/bpm_bench/bpm_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,10 @@ auto main(int argc, char **argv) -> int {

for (size_t i = 0; i < bustub_page_cnt; i++) {
page_id_t page_id = bpm->NewPage();
auto guard = bpm->WritePage(page_id);

ModifyPage(guard.GetDataMut(), i, 0);
guard.Drop();

{
auto guard = bpm->WritePage(page_id);
ModifyPage(guard.GetDataMut(), i, 0);
}
page_ids.push_back(page_id);
}

Expand All @@ -226,8 +225,6 @@ auto main(int argc, char **argv) -> int {

for (size_t thread_id = 0; thread_id < scan_thread_n; thread_id++) {
threads.emplace_back([bustub_page_cnt, scan_thread_n, thread_id, &page_ids, &bpm, duration_ms, &total_metrics] {
ModifyRecord records;

BpmMetrics metrics(fmt::format("scan {:>2}", thread_id), duration_ms);
metrics.Begin();

Expand All @@ -237,11 +234,8 @@ auto main(int argc, char **argv) -> int {

while (!metrics.ShouldFinish()) {
{
auto page = bpm->WritePage(page_ids[page_idx], AccessType::Lookup);
auto &seed = records[page_idx];
CheckPageConsistent(page.GetData(), page_idx, seed);
seed = seed + 1;
ModifyPage(page.GetDataMut(), page_idx, seed);
auto page = bpm->ReadPage(page_ids[page_idx], AccessType::Scan);
CheckPageConsistentNoSeed(page.GetData(), page_idx);
}

page_idx += 1;
Expand All @@ -257,19 +251,24 @@ auto main(int argc, char **argv) -> int {
}

for (size_t thread_id = 0; thread_id < get_thread_n; thread_id++) {
threads.emplace_back([thread_id, &page_ids, &bpm, bustub_page_cnt, duration_ms, &total_metrics] {
threads.emplace_back([thread_id, &page_ids, &bpm, bustub_page_cnt, get_thread_n, duration_ms, &total_metrics] {
std::random_device r;
std::default_random_engine gen(r());
zipfian_int_distribution<size_t> dist(0, bustub_page_cnt - 1, 0.8);
ModifyRecord records;

BpmMetrics metrics(fmt::format("get {:>2}", thread_id), duration_ms);
BpmMetrics metrics(fmt::format("get {:>2}", thread_id), duration_ms);
metrics.Begin();

while (!metrics.ShouldFinish()) {
auto page_idx = dist(gen);
auto rand = dist(gen);
auto page_idx = std::min(rand / get_thread_n * get_thread_n + thread_id, bustub_page_cnt - 1);
{
auto page = bpm->ReadPage(page_ids[page_idx], AccessType::Scan);
CheckPageConsistentNoSeed(page.GetData(), page_idx);
auto page = bpm->WritePage(page_ids[page_idx], AccessType::Lookup);
auto &seed = records[page_idx];
CheckPageConsistent(page.GetData(), page_idx, seed);
seed = seed + 1;
ModifyPage(page.GetDataMut(), page_idx, seed);
}

metrics.Tick();
Expand Down

0 comments on commit fce877d

Please sign in to comment.