Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加本地虚拟机环境搭建和vscode开发配置教程 #509

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ FOREACH (F ${ALL_SRC})
ADD_EXECUTABLE(${prjName} ${F})
TARGET_LINK_LIBRARIES(${prjName} common pthread dl benchmark::benchmark)
if(NOT ${prjName} STREQUAL "memtracer_performance_test")
TARGET_LINK_LIBRARIES(${prjName} observer_static)
TARGET_LINK_LIBRARIES(${prjName} observer_static oblsm)
endif()

ENDFOREACH (F)
146 changes: 146 additions & 0 deletions benchmark/oblsm_performance_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

#include <benchmark/benchmark.h>
#include <inttypes.h>

#include "common/lang/stdexcept.h"
#include "common/lang/filesystem.h"
#include "common/log/log.h"
#include "common/math/integer_generator.h"
#include "oblsm/include/ob_lsm.h"

// TODO
// a simple benchmark to test oblsm concurrency put/get. more detail test can use `ob_lsm_bench` tool.
using namespace std;
using namespace common;
using namespace benchmark;
using namespace oceanbase;

class BenchmarkBase : public Fixture
{
public:
BenchmarkBase() {}

virtual ~BenchmarkBase() {}

virtual string Name() const = 0;

virtual void SetUp(const State &state)
{
if (0 != state.thread_index()) {
return;
}
filesystem::remove_all("oblsm_benchmark");
filesystem::create_directory("oblsm_benchmark");

RC rc = ObLsm::open(ObLsmOptions(), "oblsm_benchmark", &oblsm_);
if (rc != RC::SUCCESS) {
throw runtime_error("failed to open oblsm");
}

LOG_INFO("test %s setup done. threads=%d, thread index=%d",
this->Name().c_str(), state.threads(), state.thread_index());
}

virtual void TearDown(const State &state)
{
if (0 != state.thread_index()) {
return;
}
delete oblsm_;
LOG_INFO("test %s teardown done. threads=%d, thread index=%d",
this->Name().c_str(),
state.threads(),
state.thread_index());
}

void FillUp(uint32_t min, uint32_t max)
{
for (uint32_t value = min; value < max; ++value) {
string key = to_string(value);

[[maybe_unused]] RC rc = oblsm_->put(key, key);
ASSERT(rc == RC::SUCCESS, "failed to insert entry into btree. key=%" PRIu32, value);
}
}

uint32_t GetRangeMax(const State &state) const
{
uint32_t max = static_cast<uint32_t>(state.range(0) * 3);
if (max <= 0) {
max = (1 << 31);
}
return max;
}

void Insert(uint32_t value) { oblsm_->put(to_string(value), to_string(value)); }

void Scan(uint32_t begin, uint32_t end)
{
auto iter = oblsm_->new_iterator(ObLsmReadOptions());
iter->seek(to_string(begin));
while (iter->valid() && iter->key() != to_string(end)) {
iter->next();
}
delete iter;
}

protected:
oceanbase::ObLsm *oblsm_ = nullptr;
};

////////////////////////////////////////////////////////////////////////////////

struct DISABLED_MixtureBenchmark : public BenchmarkBase
{
string Name() const override { return "mixture"; }
};

BENCHMARK_DEFINE_F(DISABLED_MixtureBenchmark, Mixture)(State &state)
{
pair<uint32_t, uint32_t> insert_range{GetRangeMax(state) + 1, GetRangeMax(state) * 2};
pair<uint32_t, uint32_t> scan_range{1, 100};
pair<uint32_t, uint32_t> data_range{0, GetRangeMax(state) * 2};

IntegerGenerator data_generator(data_range.first, data_range.second);
IntegerGenerator insert_generator(insert_range.first, insert_range.second);
IntegerGenerator scan_range_generator(scan_range.first, scan_range.second);
IntegerGenerator operation_generator(0, 10);

for (auto _ : state) {
int64_t operation_type = operation_generator.next();
if (operation_type <= 9) {
operation_type = 0;
} else {
operation_type = 1;
}
switch (operation_type) {
case 0: { // insert
uint32_t value = static_cast<uint32_t>(insert_generator.next());
Insert(value);
} break;
case 1: { // scan
uint32_t begin = static_cast<uint32_t>(data_generator.next());
uint32_t end = begin + static_cast<uint32_t>(scan_range_generator.next());
Scan(begin, end);
} break;
default: {
ASSERT(false, "should not happen. operation=%ld", operation_type);
}
}
}
}

BENCHMARK_REGISTER_F(DISABLED_MixtureBenchmark, Mixture)->Threads(10)->Arg(1)->Arg(1000)->Arg(10000);

////////////////////////////////////////////////////////////////////////////////

BENCHMARK_MAIN();
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading