]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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). | |
7c673cae FG |
5 | |
6 | #ifndef GFLAGS | |
7 | #include <cstdio> | |
8 | int main() { | |
9 | fprintf(stderr, "Please install gflags to run rocksdb tools\n"); | |
10 | return 1; | |
11 | } | |
12 | #else | |
13 | ||
f67539c2 | 14 | #include "file/writable_file_writer.h" |
7c673cae FG |
15 | #include "monitoring/histogram.h" |
16 | #include "rocksdb/env.h" | |
1e59de90 | 17 | #include "rocksdb/system_clock.h" |
f67539c2 TL |
18 | #include "test_util/testharness.h" |
19 | #include "test_util/testutil.h" | |
11fdf7f2 | 20 | #include "util/gflags_compat.h" |
7c673cae | 21 | |
11fdf7f2 TL |
22 | using GFLAGS_NAMESPACE::ParseCommandLineFlags; |
23 | using GFLAGS_NAMESPACE::SetUsageMessage; | |
7c673cae FG |
24 | |
25 | // A simple benchmark to simulate transactional logs | |
26 | ||
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."); | |
32 | ||
f67539c2 | 33 | namespace ROCKSDB_NAMESPACE { |
7c673cae | 34 | void RunBenchmark() { |
11fdf7f2 | 35 | std::string file_name = test::PerThreadDBPath("log_write_benchmark.log"); |
f67539c2 | 36 | DBOptions options; |
7c673cae | 37 | Env* env = Env::Default(); |
1e59de90 | 38 | const auto& clock = env->GetSystemClock(); |
f67539c2 | 39 | EnvOptions env_options = env->OptimizeForLogWrite(EnvOptions(), options); |
7c673cae | 40 | env_options.bytes_per_sync = FLAGS_bytes_per_sync; |
494da23a | 41 | std::unique_ptr<WritableFile> file; |
7c673cae | 42 | env->NewWritableFile(file_name, &file, env_options); |
494da23a | 43 | std::unique_ptr<WritableFileWriter> writer; |
f67539c2 | 44 | writer.reset(new WritableFileWriter(std::move(file), file_name, env_options, |
1e59de90 | 45 | clock, nullptr /* stats */, |
f67539c2 | 46 | options.listeners)); |
7c673cae FG |
47 | |
48 | std::string record; | |
49 | record.assign(FLAGS_record_size, 'X'); | |
50 | ||
51 | HistogramImpl hist; | |
52 | ||
1e59de90 | 53 | uint64_t start_time = clock->NowMicros(); |
7c673cae | 54 | for (int i = 0; i < FLAGS_num_records; i++) { |
1e59de90 | 55 | uint64_t start_nanos = clock->NowNanos(); |
7c673cae FG |
56 | writer->Append(record); |
57 | writer->Flush(); | |
58 | if (FLAGS_enable_sync) { | |
59 | writer->Sync(false); | |
60 | } | |
1e59de90 | 61 | hist.Add(clock->NowNanos() - start_nanos); |
7c673cae FG |
62 | |
63 | if (i % 1000 == 1) { | |
64 | fprintf(stderr, "Wrote %d records...\n", i); | |
65 | } | |
66 | ||
67 | int time_to_sleep = | |
1e59de90 | 68 | (i + 1) * FLAGS_record_interval - (clock->NowMicros() - start_time); |
7c673cae | 69 | if (time_to_sleep > 0) { |
1e59de90 | 70 | clock->SleepForMicroseconds(time_to_sleep); |
7c673cae FG |
71 | } |
72 | } | |
73 | ||
74 | fprintf(stderr, "Distribution of latency of append+flush: \n%s", | |
75 | hist.ToString().c_str()); | |
76 | } | |
f67539c2 | 77 | } // namespace ROCKSDB_NAMESPACE |
7c673cae FG |
78 | |
79 | int main(int argc, char** argv) { | |
80 | SetUsageMessage(std::string("\nUSAGE:\n") + std::string(argv[0]) + | |
81 | " [OPTIONS]..."); | |
82 | ParseCommandLineFlags(&argc, &argv, true); | |
83 | ||
f67539c2 | 84 | ROCKSDB_NAMESPACE::RunBenchmark(); |
7c673cae FG |
85 | return 0; |
86 | } | |
87 | ||
88 | #endif // GFLAGS |