]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/util/log_write_bench.cc
1 // Copyright (c) 2011-present, 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.
9 fprintf(stderr
, "Please install gflags to run rocksdb tools\n");
14 #include <gflags/gflags.h>
16 #include "monitoring/histogram.h"
17 #include "rocksdb/env.h"
18 #include "util/file_reader_writer.h"
19 #include "util/testharness.h"
20 #include "util/testutil.h"
22 using GFLAGS::ParseCommandLineFlags
;
23 using GFLAGS::SetUsageMessage
;
25 // A simple benchmark to simulate transactional logs
27 DEFINE_int32(num_records
, 6000, "Number of records.");
28 DEFINE_int32(record_size
, 249, "Size of each record.");
29 DEFINE_int32(record_interval
, 10000, "Interval between records (microSec)");
30 DEFINE_int32(bytes_per_sync
, 0, "bytes_per_sync parameter in EnvOptions");
31 DEFINE_bool(enable_sync
, false, "sync after each write.");
35 std::string file_name
= test::TmpDir() + "/log_write_benchmark.log";
36 Env
* env
= Env::Default();
37 EnvOptions env_options
= env
->OptimizeForLogWrite(EnvOptions());
38 env_options
.bytes_per_sync
= FLAGS_bytes_per_sync
;
39 unique_ptr
<WritableFile
> file
;
40 env
->NewWritableFile(file_name
, &file
, env_options
);
41 unique_ptr
<WritableFileWriter
> writer
;
42 writer
.reset(new WritableFileWriter(std::move(file
), env_options
));
45 record
.assign(FLAGS_record_size
, 'X');
49 uint64_t start_time
= env
->NowMicros();
50 for (int i
= 0; i
< FLAGS_num_records
; i
++) {
51 uint64_t start_nanos
= env
->NowNanos();
52 writer
->Append(record
);
54 if (FLAGS_enable_sync
) {
57 hist
.Add(env
->NowNanos() - start_nanos
);
60 fprintf(stderr
, "Wrote %d records...\n", i
);
64 (i
+ 1) * FLAGS_record_interval
- (env
->NowMicros() - start_time
);
65 if (time_to_sleep
> 0) {
66 env
->SleepForMicroseconds(time_to_sleep
);
70 fprintf(stderr
, "Distribution of latency of append+flush: \n%s",
71 hist
.ToString().c_str());
73 } // namespace rocksdb
75 int main(int argc
, char** argv
) {
76 SetUsageMessage(std::string("\nUSAGE:\n") + std::string(argv
[0]) +
78 ParseCommandLineFlags(&argc
, &argv
, true);
80 rocksdb::RunBenchmark();