Skip to content

Commit 01c27be

Browse files
committed
A simple benchmark to measure WAL append latency
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/D16239
1 parent 18a7cdf commit 01c27be

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ crc32c_test: util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS)
285285
db_test: db/db_test.o $(LIBOBJECTS) $(TESTHARNESS)
286286
$(CXX) db/db_test.o $(LIBOBJECTS) $(TESTHARNESS) $(EXEC_LDFLAGS) -o $@ $(LDFLAGS) $(COVERAGEFLAGS)
287287

288+
log_write_bench: util/log_write_bench.o $(LIBOBJECTS) $(TESTHARNESS)
289+
$(CXX) util/log_write_bench.o $(LIBOBJECTS) $(TESTHARNESS) $(EXEC_LDFLAGS) -o $@ $(LDFLAGS) $(COVERAGEFLAGS) -pg
290+
288291
plain_table_db_test: db/plain_table_db_test.o $(LIBOBJECTS) $(TESTHARNESS)
289292
$(CXX) db/plain_table_db_test.o $(LIBOBJECTS) $(TESTHARNESS) $(EXEC_LDFLAGS) -o $@ $(LDFLAGS) $(COVERAGEFLAGS)
290293

util/log_write_bench.cc

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under the BSD-style license found in the
3+
// LICENSE file in the root directory of this source tree. An additional grant
4+
// of patent rights can be found in the PATENTS file in the same directory.
5+
6+
#include <gflags/gflags.h>
7+
8+
#include "rocksdb/env.h"
9+
#include "util/histogram.h"
10+
#include "util/testharness.h"
11+
#include "util/testutil.h"
12+
13+
// A simple benchmark to simulate transactional logs
14+
15+
DEFINE_int32(num_records, 6000, "Size of each record.");
16+
DEFINE_int32(record_size, 249, "Size of each record.");
17+
DEFINE_int32(record_interval, 10000, "Interval between records (microSec)");
18+
DEFINE_int32(bytes_per_sync, 0, "bytes_per_sync parameter in EnvOptions");
19+
DEFINE_bool(enable_sync, false, "sync after each write.");
20+
21+
namespace rocksdb {
22+
void RunBenchmark() {
23+
std::string file_name = test::TmpDir() + "/log_write_bench.log";
24+
Env* env = Env::Default();
25+
EnvOptions env_options;
26+
env_options.use_mmap_writes = false;
27+
env_options.bytes_per_sync = FLAGS_bytes_per_sync;
28+
unique_ptr<WritableFile> file;
29+
env->NewWritableFile(file_name, &file, env_options);
30+
31+
std::string record;
32+
record.assign('X', FLAGS_record_size);
33+
34+
HistogramImpl hist;
35+
36+
uint64_t start_time = env->NowMicros();
37+
for (int i = 0; i < FLAGS_num_records; i++) {
38+
uint64_t start_nanos = env->NowNanos();
39+
file->Append(record);
40+
file->Flush();
41+
if (FLAGS_enable_sync) {
42+
file->Sync();
43+
}
44+
hist.Add(env->NowNanos() - start_nanos);
45+
46+
if (i % 1000 == 1) {
47+
fprintf(stderr, "Wrote %d records...\n", i);
48+
}
49+
50+
int time_to_sleep =
51+
(i + 1) * FLAGS_record_interval - (env->NowMicros() - start_time);
52+
if (time_to_sleep > 0) {
53+
env->SleepForMicroseconds(time_to_sleep);
54+
}
55+
}
56+
57+
fprintf(stderr, "Distribution of latency of append+flush: \n%s",
58+
hist.ToString().c_str());
59+
}
60+
} // namespace rocksdb
61+
62+
int main(int argc, char** argv) {
63+
google::SetUsageMessage(std::string("\nUSAGE:\n") + std::string(argv[0]) +
64+
" [OPTIONS]...");
65+
google::ParseCommandLineFlags(&argc, &argv, true);
66+
67+
rocksdb::RunBenchmark();
68+
return 0;
69+
}

0 commit comments

Comments
 (0)