mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-25 22:44:05 +00:00
e6de02103a
Summary: Add a function GetOptions(), where based on four parameters users give: read/write amplification threshold, memory budget for mem tables and target DB size, it picks up a compaction style and parameters for them. Background threads are not touched yet. One limit of this algorithm: since compression rate and key/value size are hard to predict, it's hard to predict level 0 file size from write buffer size. Simply make 1:1 ratio here. Sample results: https://reviews.facebook.net/P477 Test Plan: Will add some a unit test where some sample scenarios are given and see they pick the results that make sense Reviewers: yhchiang, dhruba, haobo, igor, ljin Reviewed By: ljin Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D18741
81 lines
2.6 KiB
C++
81 lines
2.6 KiB
C++
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under the BSD-style license found in the
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
//
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
#define __STDC_FORMAT_MACROS
|
|
#include <inttypes.h>
|
|
#include <gflags/gflags.h>
|
|
|
|
#include "rocksdb/options.h"
|
|
#include "util/testharness.h"
|
|
|
|
using GFLAGS::ParseCommandLineFlags;
|
|
DEFINE_bool(enable_print, false, "Print options generated to console.");
|
|
|
|
namespace rocksdb {
|
|
|
|
class OptionsTest {};
|
|
|
|
class StderrLogger : public Logger {
|
|
public:
|
|
virtual void Logv(const char* format, va_list ap) override {
|
|
vprintf(format, ap);
|
|
printf("\n");
|
|
}
|
|
};
|
|
|
|
Options PrintAndGetOptions(size_t total_write_buffer_limit,
|
|
int read_amplification_threshold,
|
|
int write_amplification_threshold,
|
|
uint64_t target_db_size = 68719476736) {
|
|
StderrLogger logger;
|
|
|
|
if (FLAGS_enable_print) {
|
|
printf(
|
|
"---- total_write_buffer_limit: %zu "
|
|
"read_amplification_threshold: %d write_amplification_threshold: %d "
|
|
"target_db_size %" PRIu64 " ----\n",
|
|
total_write_buffer_limit, read_amplification_threshold,
|
|
write_amplification_threshold, target_db_size);
|
|
}
|
|
|
|
Options options =
|
|
GetOptions(total_write_buffer_limit, read_amplification_threshold,
|
|
write_amplification_threshold, target_db_size);
|
|
if (FLAGS_enable_print) {
|
|
options.Dump(&logger);
|
|
printf("-------------------------------------\n\n\n");
|
|
}
|
|
return options;
|
|
}
|
|
|
|
TEST(OptionsTest, LooseCondition) {
|
|
Options options;
|
|
PrintAndGetOptions(static_cast<size_t>(10) * 1024 * 1024 * 1024, 100, 100);
|
|
|
|
// Less mem table memory budget
|
|
PrintAndGetOptions(32 * 1024 * 1024, 100, 100);
|
|
|
|
// Tight read amplification
|
|
options = PrintAndGetOptions(128 * 1024 * 1024, 8, 100);
|
|
ASSERT_EQ(options.compaction_style, kCompactionStyleLevel);
|
|
|
|
// Tight write amplification
|
|
options = PrintAndGetOptions(128 * 1024 * 1024, 64, 10);
|
|
ASSERT_EQ(options.compaction_style, kCompactionStyleUniversal);
|
|
|
|
// Both tight amplifications
|
|
PrintAndGetOptions(128 * 1024 * 1024, 4, 8);
|
|
}
|
|
} // namespace rocksdb
|
|
|
|
int main(int argc, char** argv) {
|
|
ParseCommandLineFlags(&argc, &argv, true);
|
|
return rocksdb::test::RunAllTests();
|
|
}
|