]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/tools/advisor/test/test_db_bench_runner.py
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 from advisor
.db_bench_runner
import DBBenchRunner
10 from advisor
.db_log_parser
import DataSource
, NO_COL_FAMILY
11 from advisor
.db_options_parser
import DatabaseOptions
14 class TestDBBenchRunnerMethods(unittest
.TestCase
):
19 "use_existing_db=true",
22 self
.bench_runner
= DBBenchRunner(self
.pos_args
)
23 this_path
= os
.path
.abspath(os
.path
.dirname(__file__
))
24 options_path
= os
.path
.join(this_path
, "input_files/OPTIONS-000005")
25 self
.db_options
= DatabaseOptions(options_path
)
28 self
.assertEqual(self
.bench_runner
.db_bench_binary
, self
.pos_args
[0])
29 self
.assertEqual(self
.bench_runner
.benchmark
, self
.pos_args
[1])
31 set(self
.bench_runner
.db_bench_args
), set(self
.pos_args
[2:])
34 def test_get_info_log_file_name(self
):
35 log_file_name
= DBBenchRunner
.get_info_log_file_name(None, "random_path")
36 self
.assertEqual(log_file_name
, "LOG")
38 log_file_name
= DBBenchRunner
.get_info_log_file_name(
39 "/dev/shm/", "/tmp/rocksdbtest-155919/dbbench/"
41 self
.assertEqual(log_file_name
, "tmp_rocksdbtest-155919_dbbench_LOG")
43 def test_get_opt_args_str(self
):
44 misc_opt_dict
= {"bloom_bits": 2, "empty_opt": None, "rate_limiter": 3}
45 optional_args_str
= DBBenchRunner
.get_opt_args_str(misc_opt_dict
)
46 self
.assertEqual(optional_args_str
, " --bloom_bits=2 --rate_limiter=3")
48 def test_get_log_options(self
):
49 db_path
= "/tmp/rocksdb-155919/dbbench"
50 # when db_log_dir is present in the db_options
52 "DBOptions.db_log_dir": {NO_COL_FAMILY
: "/dev/shm"},
53 "DBOptions.stats_dump_period_sec": {NO_COL_FAMILY
: "20"},
55 self
.db_options
.update_options(update_dict
)
56 log_file_prefix
, stats_freq
= self
.bench_runner
.get_log_options(
57 self
.db_options
, db_path
59 self
.assertEqual(log_file_prefix
, "/dev/shm/tmp_rocksdb-155919_dbbench_LOG")
60 self
.assertEqual(stats_freq
, 20)
63 "DBOptions.db_log_dir": {NO_COL_FAMILY
: None},
64 "DBOptions.stats_dump_period_sec": {NO_COL_FAMILY
: "30"},
66 self
.db_options
.update_options(update_dict
)
67 log_file_prefix
, stats_freq
= self
.bench_runner
.get_log_options(
68 self
.db_options
, db_path
70 self
.assertEqual(log_file_prefix
, "/tmp/rocksdb-155919/dbbench/LOG")
71 self
.assertEqual(stats_freq
, 30)
73 def test_build_experiment_command(self
):
74 # add some misc_options to db_options
76 "bloom_bits": {NO_COL_FAMILY
: 2},
77 "rate_limiter_bytes_per_sec": {NO_COL_FAMILY
: 128000000},
79 self
.db_options
.update_options(update_dict
)
81 experiment_command
= self
.bench_runner
._build
_experiment
_command
(
82 self
.db_options
, db_path
84 opt_args_str
= DBBenchRunner
.get_opt_args_str(
85 self
.db_options
.get_misc_options()
87 opt_args_str
+= " --options_file=" + self
.db_options
.generate_options_config(
90 for arg
in self
.pos_args
[2:]:
91 opt_args_str
+= " --" + arg
96 + " --statistics --perf_level=3 --db="
100 self
.assertEqual(experiment_command
, expected_command
)
103 class TestDBBenchRunner(unittest
.TestCase
):
105 # Note: the db_bench binary should be present in the rocksdb/ directory
109 "use_existing_db=true",
112 self
.bench_runner
= DBBenchRunner(self
.pos_args
)
113 this_path
= os
.path
.abspath(os
.path
.dirname(__file__
))
114 options_path
= os
.path
.join(this_path
, "input_files/OPTIONS-000005")
115 self
.db_options
= DatabaseOptions(options_path
)
117 def test_experiment_output(self
):
118 update_dict
= {"bloom_bits": {NO_COL_FAMILY
: 2}}
119 self
.db_options
.update_options(update_dict
)
121 data_sources
, throughput
= self
.bench_runner
.run_experiment(
122 self
.db_options
, db_path
125 data_sources
[DataSource
.Type
.DB_OPTIONS
][0].type, DataSource
.Type
.DB_OPTIONS
127 self
.assertEqual(data_sources
[DataSource
.Type
.LOG
][0].type, DataSource
.Type
.LOG
)
128 self
.assertEqual(len(data_sources
[DataSource
.Type
.TIME_SERIES
]), 2)
130 data_sources
[DataSource
.Type
.TIME_SERIES
][0].type,
131 DataSource
.Type
.TIME_SERIES
,
134 data_sources
[DataSource
.Type
.TIME_SERIES
][1].type,
135 DataSource
.Type
.TIME_SERIES
,
137 self
.assertEqual(data_sources
[DataSource
.Type
.TIME_SERIES
][1].stats_freq_sec
, 0)
140 if __name__
== "__main__":