-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathinit_open_bench.cc
More file actions
131 lines (122 loc) · 4.04 KB
/
Copy pathinit_open_bench.cc
File metadata and controls
131 lines (122 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "absl/strings/str_cat.h"
#include "benchmark/benchmark.h"
#include "glog/logging.h"
#include "src/client/gfs_client.h"
const char kConfigFileName[] = "data/config.yml";
const char kMasterName[] = "master_server_01";
const bool kResolveHostname = true;
static std::string rand_string() {
// Make it as random as possible for multi-threaded create tests
// Not ideal, but works to avoid collisions among benchmark iterations
return absl::StrCat(rand(), "-", rand());
}
static void BM_INIT_CLIENT(benchmark::State& state) {
// Benchmark the init_client function
for (auto _ : state) {
auto init_status(gfs::client::init_client(kConfigFileName, kMasterName,
kResolveHostname));
// delete the cached client impl, so we can run it again
state.PauseTiming();
gfs::client::reset_client();
state.ResumeTiming();
}
}
static void BM_OPEN_WITH_READ_MODE(benchmark::State& state) {
auto init_status(
gfs::client::init_client(kConfigFileName, kMasterName, kResolveHostname));
// Benchmark the init_client function
uint64_t ok = 0;
uint64_t failed = 0;
for (auto _ : state) {
auto status_or = gfs::client::open("/open_with_read", gfs::OpenFlag::Read);
state.PauseTiming();
if (status_or.ok()) {
ok++;
} else {
failed++;
}
state.ResumeTiming();
}
state.counters["ok"] = ok;
state.counters["failed"] = failed;
}
static void BM_OPEN_WITH_WRITE_MODE(benchmark::State& state) {
auto init_status(
gfs::client::init_client(kConfigFileName, kMasterName, kResolveHostname));
// Benchmark the init_client function
uint64_t ok = 0;
uint64_t failed = 0;
for (auto _ : state) {
auto status_or =
gfs::client::open("/open_with_write", gfs::OpenFlag::Write);
state.PauseTiming();
if (status_or.ok()) {
ok++;
} else {
failed++;
}
state.ResumeTiming();
}
state.counters["ok"] = ok;
state.counters["failed"] = failed;
}
static void BM_OPEN_WITH_CREATE_MODE_SINGLE_THREADED(benchmark::State& state) {
auto init_status(
gfs::client::init_client(kConfigFileName, kMasterName, kResolveHostname));
// Benchmark the init_client function
uint64_t ok = 0;
uint64_t failed = 0;
for (auto _ : state) {
auto status_or = gfs::client::open(
absl::StrCat("/open_with_create_one_thread_", rand_string()).c_str(),
gfs::OpenFlag::Create);
state.PauseTiming();
if (status_or.ok()) {
ok++;
} else {
failed++;
}
state.ResumeTiming();
}
state.counters["ok"] = ok;
state.counters["failed"] = failed;
}
static void BM_OPEN_WITH_CREATE_MODE_MULTI_THREADED(benchmark::State& state) {
auto init_status(
gfs::client::init_client(kConfigFileName, kMasterName, kResolveHostname));
// Benchmark the init_client function
uint64_t ok = 0;
uint64_t failed = 0;
for (auto _ : state) {
auto status_or =
gfs::client::open(absl::StrCat("/open_with_create_t_",
state.thread_index(), "_", rand_string())
.c_str(),
gfs::OpenFlag::Create);
state.PauseTiming();
if (status_or.ok()) {
ok++;
} else {
failed++;
}
state.ResumeTiming();
}
state.counters["ok"] = ok;
state.counters["failed"] = failed;
}
// Register the function as a benchmark
BENCHMARK(BM_INIT_CLIENT);
BENCHMARK(BM_OPEN_WITH_READ_MODE);
BENCHMARK(BM_OPEN_WITH_WRITE_MODE);
BENCHMARK(BM_OPEN_WITH_CREATE_MODE_SINGLE_THREADED);
BENCHMARK(BM_OPEN_WITH_CREATE_MODE_MULTI_THREADED)
->ThreadRange(/*min_threads=*/2, /*max_threads=*/100);
// Instead of using BENCHMARK_MAIN, we manually write the main to allows
// use initialize the google logging, to surpress the INFO log being logged
// to stderr by default when glog is not explicitly initialized
int main(int argc, char** argv) {
google::InitGoogleLogging(/*program_name*/ argv[0]);
::benchmark::Initialize(&argc, argv);
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1;
::benchmark::RunSpecifiedBenchmarks();
}