]>
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 both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
9 fprintf(stderr
, "Please install gflags to run rocksdb tools\n");
14 #include "monitoring/histogram.h"
15 #include "rocksdb/env.h"
16 #include "util/file_reader_writer.h"
17 #include "util/gflags_compat.h"
18 #include "util/testharness.h"
19 #include "util/testutil.h"
21 using GFLAGS_NAMESPACE::ParseCommandLineFlags
;
22 using GFLAGS_NAMESPACE::SetUsageMessage
;
24 // A simple benchmark to simulate transactional logs
26 DEFINE_int32(num_records
, 6000, "Number of records.");
27 DEFINE_int32(record_size
, 249, "Size of each record.");
28 DEFINE_int32(record_interval
, 10000, "Interval between records (microSec)");
29 DEFINE_int32(bytes_per_sync
, 0, "bytes_per_sync parameter in EnvOptions");
30 DEFINE_bool(enable_sync
, false, "sync after each write.");
34 std::string file_name
= test::PerThreadDBPath("log_write_benchmark.log");
35 Env
* env
= Env::Default();
36 EnvOptions env_options
= env
->OptimizeForLogWrite(EnvOptions());
37 env_options
.bytes_per_sync
= FLAGS_bytes_per_sync
;
38 std::unique_ptr
<WritableFile
> file
;
39 env
->NewWritableFile(file_name
, &file
, env_options
);
40 std::unique_ptr
<WritableFileWriter
> writer
;
41 writer
.reset(new WritableFileWriter(std::move(file
), env_options
));
44 record
.assign(FLAGS_record_size
, 'X');
48 uint64_t start_time
= env
->NowMicros();
49 for (int i
= 0; i
< FLAGS_num_records
; i
++) {
50 uint64_t start_nanos
= env
->NowNanos();
51 writer
->Append(record
);
53 if (FLAGS_enable_sync
) {
56 hist
.Add(env
->NowNanos() - start_nanos
);
59 fprintf(stderr
, "Wrote %d records...\n", i
);
63 (i
+ 1) * FLAGS_record_interval
- (env
->NowMicros() - start_time
);
64 if (time_to_sleep
> 0) {
65 env
->SleepForMicroseconds(time_to_sleep
);
69 fprintf(stderr
, "Distribution of latency of append+flush: \n%s",
70 hist
.ToString().c_str());
72 } // namespace rocksdb
74 int main(int argc
, char** argv
) {
75 SetUsageMessage(std::string("\nUSAGE:\n") + std::string(argv
[0]) +
77 ParseCommandLineFlags(&argc
, &argv
, true);
79 rocksdb::RunBenchmark();