Summary: A simple benchmark that simulates WAL append. It can be used to test different platform/file system's performance on WAL. Test Plan: run it. Reviewers: haobo, kailiu Reviewed By: haobo CC: igor, dhruba, i.am.jin.lei, yhchiang, leveldb, nkg- Differential Revision: https://reviews.facebook.net/D16239main
parent
18a7cdfba0
commit
01c27be5fb
@ -0,0 +1,69 @@ |
|||||||
|
// 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.
|
||||||
|
|
||||||
|
#include <gflags/gflags.h> |
||||||
|
|
||||||
|
#include "rocksdb/env.h" |
||||||
|
#include "util/histogram.h" |
||||||
|
#include "util/testharness.h" |
||||||
|
#include "util/testutil.h" |
||||||
|
|
||||||
|
// A simple benchmark to simulate transactional logs
|
||||||
|
|
||||||
|
DEFINE_int32(num_records, 6000, "Size of each record."); |
||||||
|
DEFINE_int32(record_size, 249, "Size of each record."); |
||||||
|
DEFINE_int32(record_interval, 10000, "Interval between records (microSec)"); |
||||||
|
DEFINE_int32(bytes_per_sync, 0, "bytes_per_sync parameter in EnvOptions"); |
||||||
|
DEFINE_bool(enable_sync, false, "sync after each write."); |
||||||
|
|
||||||
|
namespace rocksdb { |
||||||
|
void RunBenchmark() { |
||||||
|
std::string file_name = test::TmpDir() + "/log_write_bench.log"; |
||||||
|
Env* env = Env::Default(); |
||||||
|
EnvOptions env_options; |
||||||
|
env_options.use_mmap_writes = false; |
||||||
|
env_options.bytes_per_sync = FLAGS_bytes_per_sync; |
||||||
|
unique_ptr<WritableFile> file; |
||||||
|
env->NewWritableFile(file_name, &file, env_options); |
||||||
|
|
||||||
|
std::string record; |
||||||
|
record.assign('X', FLAGS_record_size); |
||||||
|
|
||||||
|
HistogramImpl hist; |
||||||
|
|
||||||
|
uint64_t start_time = env->NowMicros(); |
||||||
|
for (int i = 0; i < FLAGS_num_records; i++) { |
||||||
|
uint64_t start_nanos = env->NowNanos(); |
||||||
|
file->Append(record); |
||||||
|
file->Flush(); |
||||||
|
if (FLAGS_enable_sync) { |
||||||
|
file->Sync(); |
||||||
|
} |
||||||
|
hist.Add(env->NowNanos() - start_nanos); |
||||||
|
|
||||||
|
if (i % 1000 == 1) { |
||||||
|
fprintf(stderr, "Wrote %d records...\n", i); |
||||||
|
} |
||||||
|
|
||||||
|
int time_to_sleep = |
||||||
|
(i + 1) * FLAGS_record_interval - (env->NowMicros() - start_time); |
||||||
|
if (time_to_sleep > 0) { |
||||||
|
env->SleepForMicroseconds(time_to_sleep); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fprintf(stderr, "Distribution of latency of append+flush: \n%s", |
||||||
|
hist.ToString().c_str()); |
||||||
|
} |
||||||
|
} // namespace rocksdb
|
||||||
|
|
||||||
|
int main(int argc, char** argv) { |
||||||
|
google::SetUsageMessage(std::string("\nUSAGE:\n") + std::string(argv[0]) + |
||||||
|
" [OPTIONS]..."); |
||||||
|
google::ParseCommandLineFlags(&argc, &argv, true); |
||||||
|
|
||||||
|
rocksdb::RunBenchmark(); |
||||||
|
return 0; |
||||||
|
} |
Loading…
Reference in new issue