koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 1 | import array |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 2 | import os.path |
| 3 | import logging |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 4 | from typing import cast, Any |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 5 | |
koder aka kdanilov | 6ab4d43 | 2015-06-22 00:26:28 +0300 | [diff] [blame] | 6 | import wally |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 7 | |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 8 | from ...utils import StopTestError, get_os, ssize2b |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 9 | from ...node_interfaces import IRPCNode |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 10 | from ..itest import ThreadedTest, IterationConfig, NodeTestResults |
| 11 | from ...result_classes import TimeSerie |
| 12 | from .fio_task_parser import execution_time, fio_cfg_compile, FioJobSection, FioParams, get_log_files, get_test_summary |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 13 | from . import rpc_plugin |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 14 | from .fio_hist import expected_lat_bins |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 15 | |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 16 | |
| 17 | logger = logging.getLogger("wally") |
| 18 | |
| 19 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 20 | class IOPerfTest(ThreadedTest): |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 21 | soft_runcycle = 5 * 60 |
Michael Semenov | 8ba6e23 | 2015-08-28 10:57:18 +0000 | [diff] [blame] | 22 | retry_time = 30 |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 23 | configs_dir = os.path.dirname(__file__) # type: str |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 24 | name = 'fio' |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 25 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 26 | def __init__(self, *args, **kwargs) -> None: |
| 27 | super().__init__(*args, **kwargs) |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 28 | |
| 29 | get = self.config.params.get |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 30 | |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 31 | self.remote_task_file = self.join_remote("task.fio") |
| 32 | self.remote_output_file = self.join_remote("fio_result.json") |
| 33 | self.use_system_fio = get('use_system_fio', False) # type: bool |
| 34 | self.use_sudo = get("use_sudo", True) # type: bool |
| 35 | self.force_prefill = get('force_prefill', False) # type: bool |
| 36 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 37 | self.load_profile_name = self.config.params['load'] # type: str |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 38 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 39 | if os.path.isfile(self.load_profile_name): |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 40 | self.load_profile_path = self.load_profile_name # type: str |
koder aka kdanilov | 6ab4d43 | 2015-06-22 00:26:28 +0300 | [diff] [blame] | 41 | else: |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 42 | self.load_profile_path = os.path.join(self.configs_dir, self.load_profile_name+ '.cfg') |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 43 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 44 | self.load_profile = open(self.load_profile_path, 'rt').read() # type: str |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 45 | |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 46 | if self.use_system_fio: |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 47 | self.fio_path = "fio" # type: str |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 48 | else: |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 49 | self.fio_path = os.path.join(self.config.remote_dir, "fio") |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 50 | |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 51 | self.load_params = self.config.params['params'] |
| 52 | self.file_name = self.load_params['FILENAME'] |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 53 | |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 54 | if 'FILESIZE' not in self.load_params: |
| 55 | logger.debug("Getting test file sizes on all nodes") |
| 56 | try: |
| 57 | sizes = {node.conn.fs.file_stat(self.file_name)['size'] |
| 58 | for node in self.config.nodes} |
| 59 | except Exception: |
| 60 | logger.exception("FILESIZE is not set in config file and fail to detect it." + |
| 61 | "Set FILESIZE or fix error and rerun test") |
| 62 | raise StopTestError() |
koder aka kdanilov | a94dfe1 | 2015-08-19 13:04:51 +0300 | [diff] [blame] | 63 | |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 64 | if len(sizes) != 1: |
| 65 | logger.error("IO target file %r has different sizes on test nodes - %r", |
| 66 | self.file_name, sizes) |
| 67 | raise StopTestError() |
koder aka kdanilov | a94dfe1 | 2015-08-19 13:04:51 +0300 | [diff] [blame] | 68 | |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 69 | self.file_size = list(sizes)[0] |
| 70 | logger.info("Detected test file size is %s", self.file_size) |
| 71 | self.load_params['FILESIZE'] = self.file_size |
| 72 | else: |
| 73 | self.file_size = ssize2b(self.load_params['FILESIZE']) |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 74 | |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 75 | self.fio_configs = list(fio_cfg_compile(self.load_profile, self.load_profile_path, |
| 76 | cast(FioParams, self.load_params))) |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 77 | |
| 78 | if len(self.fio_configs) == 0: |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 79 | logger.error("Empty fio config provided") |
| 80 | raise StopTestError() |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 81 | |
| 82 | self.iterations_configs = self.fio_configs # type: ignore |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 83 | self.exec_folder = self.config.remote_dir |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 84 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 85 | def config_node(self, node: IRPCNode) -> None: |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 86 | plugin_code = open(rpc_plugin.__file__.rsplit(".", 1)[0] + ".py", "rb").read() # type: bytes |
| 87 | node.upload_plugin("fio", plugin_code) |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 88 | |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 89 | try: |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 90 | node.conn.fs.rmtree(self.config.remote_dir) |
| 91 | except Exception: |
| 92 | pass |
| 93 | |
| 94 | try: |
| 95 | node.conn.fs.makedirs(self.config.remote_dir) |
| 96 | except Exception: |
| 97 | msg = "Failed to recreate folder {} on remote {}.".format(self.config.remote_dir, node) |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 98 | logger.exception(msg) |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 99 | raise StopTestError() |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 100 | |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 101 | self.install_utils(node) |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 102 | |
| 103 | mb = int(self.file_size / 1024 ** 2) |
| 104 | logger.info("Filling test file %s with %sMiB of random data", self.file_name, mb) |
| 105 | fill_bw = node.conn.fio.fill_file(self.file_name, mb, force=self.force_prefill, fio_path=self.fio_path) |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 106 | if fill_bw is not None: |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 107 | logger.info("Initial fio fill bw is {} MiBps for {}".format(fill_bw, node)) |
| 108 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 109 | def install_utils(self, node: IRPCNode) -> None: |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 110 | os_info = get_os(node) |
koder aka kdanilov | 6ab4d43 | 2015-06-22 00:26:28 +0300 | [diff] [blame] | 111 | if self.use_system_fio: |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 112 | if os_info.distro != 'ubuntu': |
| 113 | logger.error("Only ubuntu supported on test VM") |
| 114 | raise StopTestError() |
| 115 | node.conn.fio.install('fio', binary='fio') |
| 116 | else: |
| 117 | node.conn.fio.install('bzip2', binary='bzip2') |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 118 | fio_dir = os.path.dirname(os.path.dirname(wally.__file__)) # type: str |
| 119 | fio_dir = os.path.join(os.getcwd(), fio_dir) |
| 120 | fio_dir = os.path.join(fio_dir, 'fio_binaries') |
| 121 | fname = 'fio_{0.release}_{0.arch}.bz2'.format(os_info) |
| 122 | fio_path = os.path.join(fio_dir, fname) # type: str |
| 123 | |
| 124 | if not os.path.exists(fio_path): |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 125 | logger.error("No prebuild fio binary available for {0}".format(os_info)) |
| 126 | raise StopTestError() |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 127 | |
| 128 | bz_dest = self.join_remote('fio.bz2') # type: str |
| 129 | node.copy_file(fio_path, bz_dest) |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 130 | node.run("bzip2 --decompress {} ; chmod a+x {}".format(bz_dest, self.join_remote("fio"))) |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 131 | |
| 132 | def get_expected_runtime(self, iteration_info: IterationConfig) -> int: |
| 133 | return execution_time(cast(FioJobSection, iteration_info)) |
| 134 | |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 135 | def prepare_iteration(self, node: IRPCNode, iter_config: IterationConfig) -> None: |
| 136 | node.put_to_file(self.remote_task_file, str(iter_config).encode("utf8")) |
| 137 | |
| 138 | # TODO: get a link to substorage as a parameter |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 139 | def run_iteration(self, node: IRPCNode, iter_config: IterationConfig, stor_prefix: str) -> NodeTestResults: |
| 140 | f_iter_config = cast(FioJobSection, iter_config) |
| 141 | exec_time = execution_time(f_iter_config) |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 142 | |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 143 | fio_cmd_templ = "cd {exec_folder}; " + \ |
| 144 | "{fio_path} --output-format=json --output={out_file} --alloc-size=262144 {job_file}" |
| 145 | |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 146 | cmd = fio_cmd_templ.format(exec_folder=self.exec_folder, |
| 147 | fio_path=self.fio_path, |
| 148 | out_file=self.remote_output_file, |
| 149 | job_file=self.remote_task_file) |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 150 | must_be_empty = node.run(cmd, timeout=exec_time + max(300, exec_time), check_timeout=1).strip() |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 151 | |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 152 | if must_be_empty: |
| 153 | logger.error("Unexpected fio output: %r", must_be_empty) |
koder aka kdanilov | bc2c898 | 2015-06-13 02:50:43 +0300 | [diff] [blame] | 154 | |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 155 | res = NodeTestResults(self.__class__.__name__, node.info.node_id(), get_test_summary(f_iter_config)) |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 156 | |
| 157 | res.extra_logs['fio'] = node.get_file_content(self.remote_output_file) |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 158 | self.store_data(res.extra_logs['fio'], "raw", stor_prefix, "fio_raw") |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 159 | node.conn.fs.unlink(self.remote_output_file) |
| 160 | |
| 161 | files = [name for name in node.conn.fs.listdir(self.exec_folder)] |
| 162 | |
| 163 | expected_time_delta = 1000 # 1000ms == 1s |
| 164 | max_time_diff = 50 # 50ms - 5% |
| 165 | |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 166 | for name, path in get_log_files(f_iter_config): |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 167 | log_files = [fname for fname in files if fname.startswith(path)] |
| 168 | if len(log_files) != 1: |
| 169 | logger.error("Found %s files, match log pattern %s(%s) - %s", |
| 170 | len(log_files), path, name, ",".join(log_files[10:])) |
| 171 | raise StopTestError() |
| 172 | |
| 173 | fname = os.path.join(self.exec_folder, log_files[0]) |
| 174 | raw_result = node.get_file_content(fname) # type: bytes |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 175 | self.store_data(raw_result, "raw", stor_prefix, "{}_raw".format(name)) |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 176 | node.conn.fs.unlink(fname) |
| 177 | |
| 178 | try: |
| 179 | log_data = raw_result.decode("utf8").split("\n") |
| 180 | except UnicodeEncodeError: |
| 181 | logger.exception("Error during parse %s fio log file - can't decode usint UTF8", name) |
| 182 | raise StopTestError() |
| 183 | |
| 184 | parsed = array.array('L' if name == 'lat' else 'Q') |
| 185 | prev_ts = None |
| 186 | load_start_at = None |
| 187 | |
| 188 | # TODO: need to adjust vals for timedelta |
| 189 | for idx, line in enumerate(log_data): |
| 190 | line = line.strip() |
| 191 | if line: |
| 192 | try: |
| 193 | time_ms_s, val_s, _, *rest = line.split(",") |
| 194 | time_ms = int(time_ms_s.strip()) |
koder aka kdanilov | ffaf48d | 2016-12-27 02:25:29 +0200 | [diff] [blame^] | 195 | |
| 196 | if not prev_ts: |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 197 | prev_ts = time_ms - expected_time_delta |
| 198 | load_start_at = time_ms |
koder aka kdanilov | ffaf48d | 2016-12-27 02:25:29 +0200 | [diff] [blame^] | 199 | elif abs(time_ms - prev_ts - expected_time_delta) > max_time_diff: |
| 200 | logger.warning("Too large gap in {} log at {} - {}ms" |
| 201 | .format(name, time_ms, time_ms - prev_ts)) |
| 202 | |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 203 | if name == 'lat': |
| 204 | vals = [int(i.strip()) for i in rest] |
| 205 | |
| 206 | if len(vals) != expected_lat_bins: |
| 207 | logger.error("Expect {} bins in latency histogram, but found {} at time {}" |
| 208 | .format(expected_lat_bins, len(vals), time_ms_s)) |
| 209 | raise StopTestError() |
| 210 | |
| 211 | parsed.extend(vals) |
| 212 | else: |
| 213 | parsed.append(int(val_s.strip())) |
| 214 | except ValueError: |
| 215 | logger.exception("Error during parse %s fio log file in line %s: %r", name, idx, line) |
| 216 | raise StopTestError() |
koder aka kdanilov | ffaf48d | 2016-12-27 02:25:29 +0200 | [diff] [blame^] | 217 | |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 218 | prev_ts += expected_time_delta |
| 219 | |
| 220 | res.series[name] = TimeSerie(name=name, |
| 221 | raw=raw_result, |
| 222 | second_axis_size=expected_lat_bins if name == 'lat' else 1, |
| 223 | start_at=load_start_at, |
| 224 | step=expected_time_delta, |
| 225 | data=parsed) |
| 226 | |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 227 | self.store_data(parsed, "array", stor_prefix, "{}_data".format(name)) |
| 228 | self.store_data(res.series[name].meta(), "yaml", stor_prefix, "{}_meta".format(name)) |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 229 | |
| 230 | return res |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 231 | |
| 232 | def format_for_console(self, data: Any) -> str: |
| 233 | raise NotImplementedError() |