]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/tools/advisor/test/test_db_bench_runner.py
update ceph source to reef 18.1.2
[ceph.git] / 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).
5
6 import os
7 import unittest
8
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
12
13
14 class TestDBBenchRunnerMethods(unittest.TestCase):
15 def setUp(self):
16 self.pos_args = [
17 "./../../db_bench",
18 "overwrite",
19 "use_existing_db=true",
20 "duration=10",
21 ]
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)
26
27 def test_setup(self):
28 self.assertEqual(self.bench_runner.db_bench_binary, self.pos_args[0])
29 self.assertEqual(self.bench_runner.benchmark, self.pos_args[1])
30 self.assertSetEqual(
31 set(self.bench_runner.db_bench_args), set(self.pos_args[2:])
32 )
33
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")
37
38 log_file_name = DBBenchRunner.get_info_log_file_name(
39 "/dev/shm/", "/tmp/rocksdbtest-155919/dbbench/"
40 )
41 self.assertEqual(log_file_name, "tmp_rocksdbtest-155919_dbbench_LOG")
42
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")
47
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
51 update_dict = {
52 "DBOptions.db_log_dir": {NO_COL_FAMILY: "/dev/shm"},
53 "DBOptions.stats_dump_period_sec": {NO_COL_FAMILY: "20"},
54 }
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
58 )
59 self.assertEqual(log_file_prefix, "/dev/shm/tmp_rocksdb-155919_dbbench_LOG")
60 self.assertEqual(stats_freq, 20)
61
62 update_dict = {
63 "DBOptions.db_log_dir": {NO_COL_FAMILY: None},
64 "DBOptions.stats_dump_period_sec": {NO_COL_FAMILY: "30"},
65 }
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
69 )
70 self.assertEqual(log_file_prefix, "/tmp/rocksdb-155919/dbbench/LOG")
71 self.assertEqual(stats_freq, 30)
72
73 def test_build_experiment_command(self):
74 # add some misc_options to db_options
75 update_dict = {
76 "bloom_bits": {NO_COL_FAMILY: 2},
77 "rate_limiter_bytes_per_sec": {NO_COL_FAMILY: 128000000},
78 }
79 self.db_options.update_options(update_dict)
80 db_path = "/dev/shm"
81 experiment_command = self.bench_runner._build_experiment_command(
82 self.db_options, db_path
83 )
84 opt_args_str = DBBenchRunner.get_opt_args_str(
85 self.db_options.get_misc_options()
86 )
87 opt_args_str += " --options_file=" + self.db_options.generate_options_config(
88 "12345"
89 )
90 for arg in self.pos_args[2:]:
91 opt_args_str += " --" + arg
92 expected_command = (
93 self.pos_args[0]
94 + " --benchmarks="
95 + self.pos_args[1]
96 + " --statistics --perf_level=3 --db="
97 + db_path
98 + opt_args_str
99 )
100 self.assertEqual(experiment_command, expected_command)
101
102
103 class TestDBBenchRunner(unittest.TestCase):
104 def setUp(self):
105 # Note: the db_bench binary should be present in the rocksdb/ directory
106 self.pos_args = [
107 "./../../db_bench",
108 "overwrite",
109 "use_existing_db=true",
110 "duration=20",
111 ]
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)
116
117 def test_experiment_output(self):
118 update_dict = {"bloom_bits": {NO_COL_FAMILY: 2}}
119 self.db_options.update_options(update_dict)
120 db_path = "/dev/shm"
121 data_sources, throughput = self.bench_runner.run_experiment(
122 self.db_options, db_path
123 )
124 self.assertEqual(
125 data_sources[DataSource.Type.DB_OPTIONS][0].type, DataSource.Type.DB_OPTIONS
126 )
127 self.assertEqual(data_sources[DataSource.Type.LOG][0].type, DataSource.Type.LOG)
128 self.assertEqual(len(data_sources[DataSource.Type.TIME_SERIES]), 2)
129 self.assertEqual(
130 data_sources[DataSource.Type.TIME_SERIES][0].type,
131 DataSource.Type.TIME_SERIES,
132 )
133 self.assertEqual(
134 data_sources[DataSource.Type.TIME_SERIES][1].type,
135 DataSource.Type.TIME_SERIES,
136 )
137 self.assertEqual(data_sources[DataSource.Type.TIME_SERIES][1].stats_freq_sec, 0)
138
139
140 if __name__ == "__main__":
141 unittest.main()