blob: e86b5cd116bf4b0eb4a08de8509c2a7f616fb4a1 [file] [log] [blame]
koder aka kdanilovbc2c8982015-06-13 02:50:43 +03001import re
2import time
3import json
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03004import stat
koder aka kdanilov6ab4d432015-06-22 00:26:28 +03005import random
koder aka kdanilov76471642015-08-14 11:44:43 +03006import shutil
koder aka kdanilovbc2c8982015-06-13 02:50:43 +03007import os.path
8import logging
9import datetime
10import functools
11import subprocess
12import collections
13
14import yaml
15import paramiko
16import texttable
17from paramiko.ssh_exception import SSHException
koder aka kdanilova94dfe12015-08-19 13:04:51 +030018from concurrent.futures import ThreadPoolExecutor, wait
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030019
koder aka kdanilov6ab4d432015-06-22 00:26:28 +030020import wally
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030021from wally.pretty_yaml import dumps
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +030022from wally.statistic import round_3_digit, data_property, average
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030023from wally.utils import ssize2b, sec_to_str, StopTestError, Barrier, get_os
24from wally.ssh_utils import (save_to_remote, read_from_remote, BGSSHTask, reconnect)
25
26from .fio_task_parser import (execution_time, fio_cfg_compile,
koder aka kdanilovf236b9c2015-06-24 18:17:22 +030027 get_test_summary, get_test_summary_tuple,
28 get_test_sync_mode, FioJobSection)
29
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +030030from ..itest import (TimeSeriesValue, PerfTest, TestResults,
31 run_on_node, TestConfig, MeasurementMatrix)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030032
33logger = logging.getLogger("wally")
34
35
36# Results folder structure
37# results/
38# {loadtype}_{num}/
39# config.yaml
40# ......
41
42
43class NoData(object):
44 pass
45
46
47def cached_prop(func):
48 @property
49 @functools.wraps(func)
50 def closure(self):
51 val = getattr(self, "_" + func.__name__)
52 if val is NoData:
53 val = func(self)
54 setattr(self, "_" + func.__name__, val)
55 return val
56 return closure
57
58
59def load_fio_log_file(fname):
60 with open(fname) as fd:
61 it = [ln.split(',')[:2] for ln in fd]
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +030062
63 vals = [(float(off) / 1000, # convert us to ms
64 float(val.strip()) + 0.5) # add 0.5 to compemsate average value
65 # as fio trimm all values in log to integer
66 for off, val in it]
67
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030068 return TimeSeriesValue(vals)
69
70
koder aka kdanilova94dfe12015-08-19 13:04:51 +030071READ_IOPS_DISCSTAT_POS = 3
72WRITE_IOPS_DISCSTAT_POS = 7
73
74
75def load_sys_log_file(ftype, fname):
76 assert ftype == 'iops'
77 pval = None
78 with open(fname) as fd:
79 iops = []
80 for ln in fd:
81 params = ln.split()
82 cval = int(params[WRITE_IOPS_DISCSTAT_POS]) + \
83 int(params[READ_IOPS_DISCSTAT_POS])
84 if pval is not None:
85 iops.append(cval - pval)
86 pval = cval
87
88 vals = [(idx * 1000, val) for idx, val in enumerate(iops)]
89 return TimeSeriesValue(vals)
90
91
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030092def load_test_results(folder, run_num):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030093 res = {}
94 params = None
95
96 fn = os.path.join(folder, str(run_num) + '_params.yaml')
97 params = yaml.load(open(fn).read())
98
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +030099 conn_ids_set = set()
100 rr = r"{0}_(?P<conn_id>.*?)_(?P<type>[^_.]*)\.\d+\.log$".format(run_num)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300101 for fname in os.listdir(folder):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300102 rm = re.match(rr, fname)
103 if rm is None:
104 continue
105
106 conn_id_s = rm.group('conn_id')
107 conn_id = conn_id_s.replace('_', ':')
108 ftype = rm.group('type')
109
110 if ftype not in ('iops', 'bw', 'lat'):
111 continue
112
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300113 ts = load_fio_log_file(os.path.join(folder, fname))
114 res.setdefault(ftype, {}).setdefault(conn_id, []).append(ts)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300115
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300116 conn_ids_set.add(conn_id)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300117
koder aka kdanilova94dfe12015-08-19 13:04:51 +0300118 rr = r"{0}_(?P<conn_id>.*?)_(?P<type>[^_.]*)\.sys\.log$".format(run_num)
119 for fname in os.listdir(folder):
120 rm = re.match(rr, fname)
121 if rm is None:
122 continue
123
124 conn_id_s = rm.group('conn_id')
125 conn_id = conn_id_s.replace('_', ':')
126 ftype = rm.group('type')
127
128 if ftype not in ('iops', 'bw', 'lat'):
129 continue
130
131 ts = load_sys_log_file(ftype, os.path.join(folder, fname))
132 res.setdefault(ftype + ":sys", {}).setdefault(conn_id, []).append(ts)
133
134 conn_ids_set.add(conn_id)
135
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300136 mm_res = {}
137
koder aka kdanilov9e0512a2015-08-10 14:51:59 +0300138 if len(res) == 0:
139 raise ValueError("No data was found")
140
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300141 for key, data in res.items():
142 conn_ids = sorted(conn_ids_set)
143 matr = [data[conn_id] for conn_id in conn_ids]
144
145 mm_res[key] = MeasurementMatrix(matr, conn_ids)
146
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300147 raw_res = {}
148 for conn_id in conn_ids:
149 fn = os.path.join(folder, "{0}_{1}_rawres.json".format(run_num, conn_id_s))
150
151 # remove message hack
152 fc = "{" + open(fn).read().split('{', 1)[1]
153 raw_res[conn_id] = json.loads(fc)
154
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300155 fio_task = FioJobSection(params['name'])
156 fio_task.vals.update(params['vals'])
157
158 config = TestConfig('io', params, None, params['nodes'], folder, None)
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300159 return FioRunResult(config, fio_task, mm_res, raw_res, params['intervals'], run_num)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300160
161
162class Attrmapper(object):
163 def __init__(self, dct):
164 self.__dct = dct
165
166 def __getattr__(self, name):
167 try:
168 return self.__dct[name]
169 except KeyError:
170 raise AttributeError(name)
171
172
173class DiskPerfInfo(object):
174 def __init__(self, name, summary, params, testnodes_count):
175 self.name = name
176 self.bw = None
177 self.iops = None
178 self.lat = None
179 self.lat_50 = None
180 self.lat_95 = None
koder aka kdanilov170936a2015-06-27 22:51:17 +0300181 self.lat_avg = None
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300182
183 self.raw_bw = []
184 self.raw_iops = []
185 self.raw_lat = []
186
187 self.params = params
188 self.testnodes_count = testnodes_count
189 self.summary = summary
190 self.p = Attrmapper(self.params['vals'])
191
192 self.sync_mode = get_test_sync_mode(self.params['vals'])
193 self.concurence = self.params['vals'].get('numjobs', 1)
194
195
196def get_lat_perc_50_95(lat_mks):
197 curr_perc = 0
198 perc_50 = None
199 perc_95 = None
200 pkey = None
201 for key, val in sorted(lat_mks.items()):
202 if curr_perc + val >= 50 and perc_50 is None:
203 if pkey is None or val < 1.:
204 perc_50 = key
205 else:
206 perc_50 = (50. - curr_perc) / val * (key - pkey) + pkey
207
208 if curr_perc + val >= 95:
209 if pkey is None or val < 1.:
210 perc_95 = key
211 else:
212 perc_95 = (95. - curr_perc) / val * (key - pkey) + pkey
213 break
214
215 pkey = key
216 curr_perc += val
217
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300218 # for k, v in sorted(lat_mks.items()):
219 # if k / 1000 > 0:
220 # print "{0:>4}".format(k / 1000), v
221
222 # print perc_50 / 1000., perc_95 / 1000.
223 # exit(1)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300224 return perc_50 / 1000., perc_95 / 1000.
225
226
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300227class IOTestResults(object):
228 def __init__(self, suite_name, fio_results, log_directory):
229 self.suite_name = suite_name
230 self.fio_results = fio_results
231 self.log_directory = log_directory
232
233 def __iter__(self):
234 return iter(self.fio_results)
235
236 def __len__(self):
237 return len(self.fio_results)
238
239 def get_yamable(self):
240 items = [(fio_res.summary(), fio_res.idx) for fio_res in self]
241 return {self.suite_name: [self.log_directory] + items}
242
243
244class FioRunResult(TestResults):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300245 """
246 Fio run results
247 config: TestConfig
248 fio_task: FioJobSection
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300249 ts_results: {str: MeasurementMatrix[TimeSeriesValue]}
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300250 raw_result: ????
251 run_interval:(float, float) - test tun time, used for sensors
252 """
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300253 def __init__(self, config, fio_task, ts_results, raw_result, run_interval, idx):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300254
koder aka kdanilov170936a2015-06-27 22:51:17 +0300255 self.name = fio_task.name.rsplit("_", 1)[0]
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300256 self.fio_task = fio_task
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300257 self.idx = idx
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300258
koder aka kdanilova94dfe12015-08-19 13:04:51 +0300259 self.bw = ts_results['bw']
260 self.lat = ts_results['lat']
261 self.iops = ts_results['iops']
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300262
koder aka kdanilova94dfe12015-08-19 13:04:51 +0300263 if 'iops:sys' in ts_results:
264 self.iops_sys = ts_results['iops:sys']
265 else:
266 self.iops_sys = None
267
268 res = {"bw": self.bw,
269 "lat": self.lat,
270 "iops": self.iops,
271 "iops:sys": self.iops_sys}
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300272
273 self.sensors_data = None
274 self._pinfo = None
275 TestResults.__init__(self, config, res, raw_result, run_interval)
276
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300277 def get_params_from_fio_report(self):
278 nodes = self.bw.connections_ids
279
280 iops = [self.raw_result[node]['jobs'][0]['mixed']['iops'] for node in nodes]
281 total_ios = [self.raw_result[node]['jobs'][0]['mixed']['total_ios'] for node in nodes]
282 runtime = [self.raw_result[node]['jobs'][0]['mixed']['runtime'] / 1000 for node in nodes]
283 flt_iops = [float(ios) / rtime for ios, rtime in zip(total_ios, runtime)]
284
285 bw = [self.raw_result[node]['jobs'][0]['mixed']['bw'] for node in nodes]
286 total_bytes = [self.raw_result[node]['jobs'][0]['mixed']['io_bytes'] for node in nodes]
287 flt_bw = [float(tbytes) / rtime for tbytes, rtime in zip(total_bytes, runtime)]
288
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300289 return {'iops': iops,
290 'flt_iops': flt_iops,
291 'bw': bw,
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300292 'flt_bw': flt_bw}
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300293
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300294 def summary(self):
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300295 return get_test_summary(self.fio_task, len(self.config.nodes))
296
297 def summary_tpl(self):
298 return get_test_summary_tuple(self.fio_task, len(self.config.nodes))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300299
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300300 def get_lat_perc_50_95_multy(self):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300301 lat_mks = collections.defaultdict(lambda: 0)
302 num_res = 0
303
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300304 for result in self.raw_result.values():
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300305 num_res += len(result['jobs'])
306 for job_info in result['jobs']:
307 for k, v in job_info['latency_ms'].items():
308 if isinstance(k, basestring) and k.startswith('>='):
309 lat_mks[int(k[2:]) * 1000] += v
310 else:
311 lat_mks[int(k) * 1000] += v
312
313 for k, v in job_info['latency_us'].items():
314 lat_mks[int(k)] += v
315
316 for k, v in lat_mks.items():
317 lat_mks[k] = float(v) / num_res
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300318 return get_lat_perc_50_95(lat_mks)
319
320 def disk_perf_info(self, avg_interval=2.0):
321
322 if self._pinfo is not None:
323 return self._pinfo
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300324
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300325 testnodes_count = len(self.config.nodes)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300326
327 pinfo = DiskPerfInfo(self.name,
328 self.summary(),
329 self.params,
330 testnodes_count)
331
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300332 def prepare(data, drop=1):
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300333 if data is None:
334 return data
335
336 res = []
337 for ts_data in data:
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300338 if ts_data.average_interval() < avg_interval:
339 ts_data = ts_data.derived(avg_interval)
340
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300341 # drop last value on bounds
342 # as they may contains ranges without activities
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300343 assert len(ts_data.values) >= drop + 1, str(drop) + " " + str(ts_data.values)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300344
345 if drop > 0:
346 res.append(ts_data.values[:-drop])
347 else:
348 res.append(ts_data.values)
349
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300350 return res
351
352 def agg_data(matr):
353 arr = sum(matr, [])
354 min_len = min(map(len, arr))
355 res = []
356 for idx in range(min_len):
357 res.append(sum(dt[idx] for dt in arr))
358 return res
359
koder aka kdanilov170936a2015-06-27 22:51:17 +0300360 pinfo.raw_lat = map(prepare, self.lat.per_vm())
361 num_th = sum(map(len, pinfo.raw_lat))
362 lat_avg = [val / num_th for val in agg_data(pinfo.raw_lat)]
363 pinfo.lat_avg = data_property(lat_avg).average / 1000 # us to ms
364
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300365 pinfo.lat_50, pinfo.lat_95 = self.get_lat_perc_50_95_multy()
366 pinfo.lat = pinfo.lat_50
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300367
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300368 pinfo.raw_bw = map(prepare, self.bw.per_vm())
369 pinfo.raw_iops = map(prepare, self.iops.per_vm())
370
koder aka kdanilova94dfe12015-08-19 13:04:51 +0300371 if self.iops_sys is not None:
372 pinfo.raw_iops_sys = map(prepare, self.iops_sys.per_vm())
373 pinfo.iops_sys = data_property(agg_data(pinfo.raw_iops_sys))
374 else:
375 pinfo.raw_iops_sys = None
376 pinfo.iops_sys = None
377
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300378 fparams = self.get_params_from_fio_report()
379 fio_report_bw = sum(fparams['flt_bw'])
380 fio_report_iops = sum(fparams['flt_iops'])
381
382 agg_bw = agg_data(pinfo.raw_bw)
383 agg_iops = agg_data(pinfo.raw_iops)
384
385 log_bw_avg = average(agg_bw)
386 log_iops_avg = average(agg_iops)
387
388 # update values to match average from fio report
389 coef_iops = fio_report_iops / float(log_iops_avg)
390 coef_bw = fio_report_bw / float(log_bw_avg)
391
392 bw_log = data_property([val * coef_bw for val in agg_bw])
393 iops_log = data_property([val * coef_iops for val in agg_iops])
394
395 bw_report = data_property([fio_report_bw])
396 iops_report = data_property([fio_report_iops])
397
398 # When IOPS/BW per thread is too low
399 # data from logs is rounded to match
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300400 iops_per_th = sum(sum(pinfo.raw_iops, []), [])
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300401 if average(iops_per_th) > 10:
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300402 pinfo.iops = iops_log
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300403 pinfo.iops2 = iops_report
404 else:
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300405 pinfo.iops = iops_report
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300406 pinfo.iops2 = iops_log
407
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300408 bw_per_th = sum(sum(pinfo.raw_bw, []), [])
409 if average(bw_per_th) > 10:
410 pinfo.bw = bw_log
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300411 pinfo.bw2 = bw_report
koder aka kdanilov170936a2015-06-27 22:51:17 +0300412 else:
413 pinfo.bw = bw_report
414 pinfo.bw2 = bw_log
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300415
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300416 self._pinfo = pinfo
417
418 return pinfo
419
420
421class IOPerfTest(PerfTest):
422 tcp_conn_timeout = 30
423 max_pig_timeout = 5
424 soft_runcycle = 5 * 60
425
426 def __init__(self, config):
427 PerfTest.__init__(self, config)
428
429 get = self.config.params.get
430 do_get = self.config.params.__getitem__
431
432 self.config_fname = do_get('cfg')
433
434 if '/' not in self.config_fname and '.' not in self.config_fname:
435 cfgs_dir = os.path.dirname(__file__)
436 self.config_fname = os.path.join(cfgs_dir,
437 self.config_fname + '.cfg')
438
439 self.alive_check_interval = get('alive_check_interval')
440 self.use_system_fio = get('use_system_fio', False)
441
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300442 if get('prefill_files') is not None:
443 logger.warning("prefill_files option is depricated. Use force_prefill instead")
444
445 self.force_prefill = get('force_prefill', False)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300446 self.config_params = get('params', {}).copy()
447
448 self.io_py_remote = self.join_remote("agent.py")
449 self.results_file = self.join_remote("results.json")
450 self.pid_file = self.join_remote("pid")
451 self.task_file = self.join_remote("task.cfg")
452 self.sh_file = self.join_remote("cmd.sh")
453 self.err_out_file = self.join_remote("fio_err_out")
koder aka kdanilova94dfe12015-08-19 13:04:51 +0300454 self.io_log_file = self.join_remote("io_log.txt")
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300455 self.exit_code_file = self.join_remote("exit_code")
456
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300457 self.max_latency = get("max_lat", None)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300458 self.min_bw_per_thread = get("min_bw", None)
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300459
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300460 self.use_sudo = get("use_sudo", True)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300461
462 self.raw_cfg = open(self.config_fname).read()
koder aka kdanilova94dfe12015-08-19 13:04:51 +0300463 self.fio_configs = None
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300464
465 @classmethod
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300466 def load(cls, suite_name, folder):
467 res = []
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300468 for fname in os.listdir(folder):
469 if re.match("\d+_params.yaml$", fname):
470 num = int(fname.split('_')[0])
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300471 res.append(load_test_results(folder, num))
472 return IOTestResults(suite_name, res, folder)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300473
474 def cleanup(self):
475 # delete_file(conn, self.io_py_remote)
476 # Need to remove tempo files, used for testing
477 pass
478
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300479 # size is megabytes
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300480 def check_prefill_required(self, rossh, fname, size, num_blocks=16):
koder aka kdanilov170936a2015-06-27 22:51:17 +0300481 try:
482 with rossh.connection.open_sftp() as sftp:
483 fstats = sftp.stat(fname)
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300484
koder aka kdanilov170936a2015-06-27 22:51:17 +0300485 if stat.S_ISREG(fstats.st_mode) and fstats.st_size < size * 1024 ** 2:
486 return True
487 except EnvironmentError:
koder aka kdanilovf95cfc12015-06-23 03:33:19 +0300488 return True
489
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300490 cmd = 'python -c "' + \
491 "import sys;" + \
492 "fd = open('{0}', 'rb');" + \
493 "fd.seek({1});" + \
494 "data = fd.read(1024); " + \
495 "sys.stdout.write(data + ' ' * ( 1024 - len(data)))\" | md5sum"
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300496
497 if self.use_sudo:
498 cmd = "sudo " + cmd
499
koder aka kdanilovf95cfc12015-06-23 03:33:19 +0300500 zero_md5 = '0f343b0931126a20f133d67c2b018a3b'
koder aka kdanilov8fbb27f2015-07-17 22:23:31 +0300501 bsize = size * (1024 ** 2)
502 offsets = [random.randrange(bsize - 1024) for _ in range(num_blocks)]
503 offsets.append(bsize - 1024)
504 offsets.append(0)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300505
koder aka kdanilovf95cfc12015-06-23 03:33:19 +0300506 for offset in offsets:
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300507 data = rossh(cmd.format(fname, offset), nolog=True)
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300508
509 md = ""
510 for line in data.split("\n"):
511 if "unable to resolve" not in line:
512 md = line.split()[0].strip()
513 break
koder aka kdanilovf95cfc12015-06-23 03:33:19 +0300514
515 if len(md) != 32:
516 logger.error("File data check is failed - " + data)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300517 return True
koder aka kdanilovf95cfc12015-06-23 03:33:19 +0300518
519 if zero_md5 == md:
520 return True
521
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300522 return False
523
524 def prefill_test_files(self, rossh, files, force=False):
525 if self.use_system_fio:
526 cmd_templ = "fio "
527 else:
528 cmd_templ = "{0}/fio ".format(self.config.remote_dir)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300529
530 if self.use_sudo:
531 cmd_templ = "sudo " + cmd_templ
532
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300533 cmd_templ += "--name=xxx --filename={0} --direct=1" + \
534 " --bs=4m --size={1}m --rw=write"
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300535
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300536 ssize = 0
537
538 if force:
539 logger.info("File prefilling is forced")
540
541 ddtime = 0
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300542 for fname, curr_sz in files.items():
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300543 if not force:
544 if not self.check_prefill_required(rossh, fname, curr_sz):
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300545 logger.debug("prefill is skipped")
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300546 continue
547
548 logger.info("Prefilling file {0}".format(fname))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300549 cmd = cmd_templ.format(fname, curr_sz)
550 ssize += curr_sz
551
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300552 stime = time.time()
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300553 rossh(cmd, timeout=curr_sz)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300554 ddtime += time.time() - stime
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300555
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300556 if ddtime > 1.0:
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300557 fill_bw = int(ssize / ddtime)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300558 mess = "Initiall fio fill bw is {0} MiBps for this vm"
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300559 logger.info(mess.format(fill_bw))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300560
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300561 def install_utils(self, node, rossh, max_retry=3, timeout=5):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300562 need_install = []
563 packs = [('screen', 'screen')]
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300564 os_info = get_os(rossh)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300565
566 if self.use_system_fio:
567 packs.append(('fio', 'fio'))
568 else:
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300569 packs.append(('bzip2', 'bzip2'))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300570
571 for bin_name, package in packs:
572 if bin_name is None:
573 need_install.append(package)
574 continue
575
576 try:
577 rossh('which ' + bin_name, nolog=True)
578 except OSError:
579 need_install.append(package)
580
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300581 if len(need_install) != 0:
582 if 'redhat' == os_info.distro:
583 cmd = "sudo yum -y install " + " ".join(need_install)
584 else:
585 cmd = "sudo apt-get -y install " + " ".join(need_install)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300586
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300587 for _ in range(max_retry):
588 try:
589 rossh(cmd)
590 break
591 except OSError as err:
592 time.sleep(timeout)
593 else:
594 raise OSError("Can't install - " + str(err))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300595
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300596 if not self.use_system_fio:
597 fio_dir = os.path.dirname(os.path.dirname(wally.__file__))
598 fio_dir = os.path.join(os.getcwd(), fio_dir)
599 fio_dir = os.path.join(fio_dir, 'fio_binaries')
600 fname = 'fio_{0.release}_{0.arch}.bz2'.format(os_info)
601 fio_path = os.path.join(fio_dir, fname)
602
603 if not os.path.exists(fio_path):
604 raise RuntimeError("No prebuild fio available for {0}".format(os_info))
605
606 bz_dest = self.join_remote('fio.bz2')
607 with node.connection.open_sftp() as sftp:
608 sftp.put(fio_path, bz_dest)
609
610 rossh("bzip2 --decompress " + bz_dest, nolog=True)
611 rossh("chmod a+x " + self.join_remote("fio"), nolog=True)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300612
613 def pre_run(self):
koder aka kdanilova94dfe12015-08-19 13:04:51 +0300614 if 'FILESIZE' not in self.config_params:
615 # need to detect file size
616 pass
617
618 self.fio_configs = fio_cfg_compile(self.raw_cfg,
619 self.config_fname,
620 self.config_params)
621 self.fio_configs = list(self.fio_configs)
622
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300623 files = {}
624 for section in self.fio_configs:
625 sz = ssize2b(section.vals['size'])
626 msz = sz / (1024 ** 2)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300627
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300628 if sz % (1024 ** 2) != 0:
629 msz += 1
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300630
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300631 fname = section.vals['filename']
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300632
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300633 # if already has other test with the same file name
634 # take largest size
635 files[fname] = max(files.get(fname, 0), msz)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300636
637 with ThreadPoolExecutor(len(self.config.nodes)) as pool:
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300638 fc = functools.partial(self.pre_run_th,
639 files=files,
640 force=self.force_prefill)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300641 list(pool.map(fc, self.config.nodes))
642
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300643 def pre_run_th(self, node, files, force):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300644 try:
koder aka kdanilov8fbb27f2015-07-17 22:23:31 +0300645 # fill files with pseudo-random data
646 rossh = run_on_node(node)
647 rossh.connection = node.connection
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300648
koder aka kdanilov8fbb27f2015-07-17 22:23:31 +0300649 try:
650 cmd = 'mkdir -p "{0}"'.format(self.config.remote_dir)
651 if self.use_sudo:
652 cmd = "sudo " + cmd
653 cmd += " ; sudo chown {0} {1}".format(node.get_user(),
654 self.config.remote_dir)
655 rossh(cmd, nolog=True)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300656
koder aka kdanilov8fbb27f2015-07-17 22:23:31 +0300657 assert self.config.remote_dir != "" and self.config.remote_dir != "/"
658 rossh("rm -rf {0}/*".format(self.config.remote_dir), nolog=True)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300659
koder aka kdanilov8fbb27f2015-07-17 22:23:31 +0300660 except Exception as exc:
661 msg = "Failed to create folder {0} on remote {1}. Error: {2!s}"
662 msg = msg.format(self.config.remote_dir, node.get_conn_id(), exc)
663 logger.exception(msg)
664 raise StopTestError(msg, exc)
665
666 self.install_utils(node, rossh)
667 self.prefill_test_files(rossh, files, force)
668 except:
669 logger.exception("XXXX")
670 raise
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300671
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300672 def show_test_execution_time(self):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300673 if len(self.fio_configs) > 1:
674 # +10% - is a rough estimation for additional operations
675 # like sftp, etc
676 exec_time = int(sum(map(execution_time, self.fio_configs)) * 1.1)
677 exec_time_s = sec_to_str(exec_time)
678 now_dt = datetime.datetime.now()
679 end_dt = now_dt + datetime.timedelta(0, exec_time)
680 msg = "Entire test should takes aroud: {0} and finished at {1}"
681 logger.info(msg.format(exec_time_s,
682 end_dt.strftime("%H:%M:%S")))
683
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300684 def run(self):
685 logger.debug("Run preparation")
686 self.pre_run()
687 self.show_test_execution_time()
688
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300689 tname = os.path.basename(self.config_fname)
690 if tname.endswith('.cfg'):
691 tname = tname[:-4]
692
693 barrier = Barrier(len(self.config.nodes))
694 results = []
695
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300696 # set of Operation_Mode_BlockSize str's
697 # which should not be tested anymore, as
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300698 # they already too slow with previous thread count
699 lat_bw_limit_reached = set()
700
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300701 with ThreadPoolExecutor(len(self.config.nodes)) as pool:
702 for pos, fio_cfg in enumerate(self.fio_configs):
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300703 test_descr = get_test_summary(fio_cfg.vals).split("th")[0]
704 if test_descr in lat_bw_limit_reached:
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300705 continue
706 else:
707 logger.info("Will run {0} test".format(fio_cfg.name))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300708
709 templ = "Test should takes about {0}." + \
710 " Should finish at {1}," + \
711 " will wait at most till {2}"
712 exec_time = execution_time(fio_cfg)
713 exec_time_str = sec_to_str(exec_time)
714 timeout = int(exec_time + max(300, exec_time))
715
716 now_dt = datetime.datetime.now()
717 end_dt = now_dt + datetime.timedelta(0, exec_time)
718 wait_till = now_dt + datetime.timedelta(0, timeout)
719
720 logger.info(templ.format(exec_time_str,
721 end_dt.strftime("%H:%M:%S"),
722 wait_till.strftime("%H:%M:%S")))
723
724 func = functools.partial(self.do_run,
725 barrier=barrier,
726 fio_cfg=fio_cfg,
727 pos=pos)
728
729 max_retr = 3
730 for idx in range(max_retr):
731 try:
732 intervals = list(pool.map(func, self.config.nodes))
koder aka kdanilov76471642015-08-14 11:44:43 +0300733 if None not in intervals:
734 break
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300735 except (EnvironmentError, SSHException) as exc:
736 logger.exception("During fio run")
737 if idx == max_retr - 1:
738 raise StopTestError("Fio failed", exc)
739
koder aka kdanilova94dfe12015-08-19 13:04:51 +0300740 logger.info("Reconnectiongm, sleeping %ss and retrying", self.retry_time)
741
742 wait(pool.submit(node.connection.close)
743 for node in self.config.nodes)
744
745 time.sleep(self.retry_time)
746
747 wait(pool.submit(reconnect, node.connection, node.conn_url)
748 for node in self.config.nodes)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300749
750 fname = "{0}_task.fio".format(pos)
751 with open(os.path.join(self.config.log_directory, fname), "w") as fd:
752 fd.write(str(fio_cfg))
753
754 params = {'vm_count': len(self.config.nodes)}
755 params['name'] = fio_cfg.name
756 params['vals'] = dict(fio_cfg.vals.items())
757 params['intervals'] = intervals
758 params['nodes'] = [node.get_conn_id() for node in self.config.nodes]
759
760 fname = "{0}_params.yaml".format(pos)
761 with open(os.path.join(self.config.log_directory, fname), "w") as fd:
762 fd.write(dumps(params))
763
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300764 res = load_test_results(self.config.log_directory, pos)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300765 results.append(res)
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300766
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300767 if self.max_latency is not None:
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300768 lat_50, _ = res.get_lat_perc_50_95_multy()
769
770 # conver us to ms
771 if self.max_latency < lat_50:
772 logger.info(("Will skip all subsequent tests of {0} " +
773 "due to lat/bw limits").format(fio_cfg.name))
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300774 lat_bw_limit_reached.add(test_descr)
775
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300776 test_res = res.get_params_from_fio_report()
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300777 if self.min_bw_per_thread is not None:
778 if self.min_bw_per_thread > average(test_res['bw']):
779 lat_bw_limit_reached.add(test_descr)
780
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300781 return IOTestResults(self.config.params['cfg'],
782 results, self.config.log_directory)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300783
784 def do_run(self, node, barrier, fio_cfg, pos, nolog=False):
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300785 if self.use_sudo:
786 sudo = "sudo "
787 else:
788 sudo = ""
789
koder aka kdanilova94dfe12015-08-19 13:04:51 +0300790 bash_file = """
791#!/bin/bash
792
793function get_dev() {{
794 if [ -b "$1" ] ; then
795 echo $1
796 else
797 echo $(df "$1" | tail -1 | awk '{{print $1}}')
798 fi
799}}
800
801function log_io_activiti(){{
802 local dest="$1"
803 local dev=$(get_dev "$2")
804 local sleep_time="$3"
805 dev=$(basename "$dev")
806
807 echo $dev
808
809 for (( ; ; )) ; do
810 grep -E "\\b$dev\\b" /proc/diskstats >> "$dest"
811 sleep $sleep_time
812 done
813}}
814
815sync
816cd {exec_folder}
817
818log_io_activiti {io_log_file} {test_file} 1 &
819local pid="$!"
820
821{fio_path}fio --output-format=json --output={out_file} --alloc-size=262144 {job_file} >{err_out_file} 2>&1
822echo $? >{res_code_file}
823kill -9 $pid
824
825"""
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300826
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300827 exec_folder = self.config.remote_dir
828
829 if self.use_system_fio:
830 fio_path = ""
831 else:
832 if not exec_folder.endswith("/"):
833 fio_path = exec_folder + "/"
834 else:
835 fio_path = exec_folder
836
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300837 bash_file = bash_file.format(out_file=self.results_file,
838 job_file=self.task_file,
839 err_out_file=self.err_out_file,
840 res_code_file=self.exit_code_file,
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300841 exec_folder=exec_folder,
koder aka kdanilova94dfe12015-08-19 13:04:51 +0300842 fio_path=fio_path,
843 test_file=self.config_params['FILENAME'],
844 io_log_file=self.io_log_file).strip()
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300845
846 with node.connection.open_sftp() as sftp:
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300847 save_to_remote(sftp, self.task_file, str(fio_cfg))
848 save_to_remote(sftp, self.sh_file, bash_file)
849
850 exec_time = execution_time(fio_cfg)
851
852 timeout = int(exec_time + max(300, exec_time))
853 soft_tout = exec_time
854
855 begin = time.time()
856
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300857 fnames_before = run_on_node(node)("ls -1 " + exec_folder, nolog=True)
858
859 barrier.wait()
860
koder aka kdanilov5414a992015-06-13 03:07:25 +0300861 task = BGSSHTask(node, self.use_sudo)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300862 task.start(sudo + "bash " + self.sh_file)
863
864 while True:
865 try:
866 task.wait(soft_tout, timeout)
867 break
868 except paramiko.SSHException:
869 pass
870
871 try:
872 node.connection.close()
873 except:
874 pass
875
876 reconnect(node.connection, node.conn_url)
877
878 end = time.time()
879 rossh = run_on_node(node)
880 fnames_after = rossh("ls -1 " + exec_folder, nolog=True)
881
882 conn_id = node.get_conn_id().replace(":", "_")
883 if not nolog:
884 logger.debug("Test on node {0} is finished".format(conn_id))
885
886 log_files_pref = []
887 if 'write_lat_log' in fio_cfg.vals:
888 fname = fio_cfg.vals['write_lat_log']
889 log_files_pref.append(fname + '_clat')
890 log_files_pref.append(fname + '_lat')
891 log_files_pref.append(fname + '_slat')
892
893 if 'write_iops_log' in fio_cfg.vals:
894 fname = fio_cfg.vals['write_iops_log']
895 log_files_pref.append(fname + '_iops')
896
897 if 'write_bw_log' in fio_cfg.vals:
898 fname = fio_cfg.vals['write_bw_log']
899 log_files_pref.append(fname + '_bw')
900
901 files = collections.defaultdict(lambda: [])
902 all_files = [os.path.basename(self.results_file)]
903 new_files = set(fnames_after.split()) - set(fnames_before.split())
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300904
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300905 for fname in new_files:
906 if fname.endswith('.log') and fname.split('.')[0] in log_files_pref:
907 name, _ = os.path.splitext(fname)
908 if fname.count('.') == 1:
909 tp = name.split("_")[-1]
910 cnt = 0
911 else:
912 tp_cnt = name.split("_")[-1]
913 tp, cnt = tp_cnt.split('.')
914 files[tp].append((int(cnt), fname))
915 all_files.append(fname)
koder aka kdanilova94dfe12015-08-19 13:04:51 +0300916 elif fname == os.path.basename(self.io_log_file):
917 files['iops'].append(('sys', fname))
918 all_files.append(fname)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300919
920 arch_name = self.join_remote('wally_result.tar.gz')
921 tmp_dir = os.path.join(self.config.log_directory, 'tmp_' + conn_id)
koder aka kdanilov76471642015-08-14 11:44:43 +0300922
923 if os.path.exists(tmp_dir):
924 shutil.rmtree(tmp_dir)
925
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300926 os.mkdir(tmp_dir)
927 loc_arch_name = os.path.join(tmp_dir, 'wally_result.{0}.tar.gz'.format(conn_id))
928 file_full_names = " ".join(all_files)
929
930 try:
931 os.unlink(loc_arch_name)
932 except:
933 pass
934
935 with node.connection.open_sftp() as sftp:
koder aka kdanilov76471642015-08-14 11:44:43 +0300936 try:
937 exit_code = read_from_remote(sftp, self.exit_code_file)
938 except IOError:
939 logger.error("No exit code file found on %s. Looks like process failed to start",
940 conn_id)
941 return None
942
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300943 err_out = read_from_remote(sftp, self.err_out_file)
944 exit_code = exit_code.strip()
945
946 if exit_code != '0':
947 msg = "fio exit with code {0}: {1}".format(exit_code, err_out)
948 logger.critical(msg.strip())
949 raise StopTestError("fio failed")
950
951 rossh("rm -f {0}".format(arch_name), nolog=True)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300952 pack_files_cmd = "cd {0} ; tar zcvf {1} {2}".format(exec_folder, arch_name, file_full_names)
953 rossh(pack_files_cmd, nolog=True)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300954 sftp.get(arch_name, loc_arch_name)
955
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300956 unpack_files_cmd = "cd {0} ; tar xvzf {1} >/dev/null".format(tmp_dir, loc_arch_name)
957 subprocess.check_call(unpack_files_cmd, shell=True)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300958 os.unlink(loc_arch_name)
959
960 for ftype, fls in files.items():
961 for idx, fname in fls:
962 cname = os.path.join(tmp_dir, fname)
963 loc_fname = "{0}_{1}_{2}.{3}.log".format(pos, conn_id, ftype, idx)
964 loc_path = os.path.join(self.config.log_directory, loc_fname)
965 os.rename(cname, loc_path)
966
967 cname = os.path.join(tmp_dir,
968 os.path.basename(self.results_file))
969 loc_fname = "{0}_{1}_rawres.json".format(pos, conn_id)
970 loc_path = os.path.join(self.config.log_directory, loc_fname)
971 os.rename(cname, loc_path)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300972 os.rmdir(tmp_dir)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300973
974 remove_remote_res_files_cmd = "cd {0} ; rm -f {1} {2}".format(exec_folder,
975 arch_name,
976 file_full_names)
977 rossh(remove_remote_res_files_cmd, nolog=True)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300978 return begin, end
979
980 @classmethod
koder aka kdanilov6b872662015-06-23 01:58:36 +0300981 def prepare_data(cls, results):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300982 """
983 create a table with io performance report
984 for console
985 """
986
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300987 def key_func(data):
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300988 tpl = data.summary_tpl()
koder aka kdanilov170936a2015-06-27 22:51:17 +0300989 return (data.name,
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300990 tpl.oper,
991 tpl.mode,
koder aka kdanilov170936a2015-06-27 22:51:17 +0300992 ssize2b(tpl.bsize),
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300993 int(tpl.th_count) * int(tpl.vm_count))
koder aka kdanilov6b872662015-06-23 01:58:36 +0300994 res = []
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300995
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300996 for item in sorted(results, key=key_func):
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300997 test_dinfo = item.disk_perf_info()
koder aka kdanilova94dfe12015-08-19 13:04:51 +0300998 testnodes_count = len(item.config.nodes)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300999
1000 iops, _ = test_dinfo.iops.rounded_average_conf()
1001
koder aka kdanilova94dfe12015-08-19 13:04:51 +03001002 if test_dinfo.iops_sys is not None:
1003 iops_sys, iops_sys_conf = test_dinfo.iops_sys.rounded_average_conf()
1004 _, iops_sys_dev = test_dinfo.iops_sys.rounded_average_dev()
1005 iops_sys_per_vm = round_3_digit(iops_sys / testnodes_count)
1006 iops_sys = round_3_digit(iops_sys)
1007 else:
1008 iops_sys = None
1009 iops_sys_per_vm = None
1010 iops_sys_dev = None
1011 iops_sys_conf = None
1012
koder aka kdanilovbc2c8982015-06-13 02:50:43 +03001013 bw, bw_conf = test_dinfo.bw.rounded_average_conf()
1014 _, bw_dev = test_dinfo.bw.rounded_average_dev()
1015 conf_perc = int(round(bw_conf * 100 / bw))
1016 dev_perc = int(round(bw_dev * 100 / bw))
1017
koder aka kdanilov6b872662015-06-23 01:58:36 +03001018 lat_50 = round_3_digit(int(test_dinfo.lat_50))
1019 lat_95 = round_3_digit(int(test_dinfo.lat_95))
koder aka kdanilov170936a2015-06-27 22:51:17 +03001020 lat_avg = round_3_digit(int(test_dinfo.lat_avg))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +03001021
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +03001022 iops_per_vm = round_3_digit(iops / testnodes_count)
1023 bw_per_vm = round_3_digit(bw / testnodes_count)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +03001024
1025 iops = round_3_digit(iops)
1026 bw = round_3_digit(bw)
1027
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03001028 summ = "{0.oper}{0.mode} {0.bsize:>4} {0.th_count:>3}th {0.vm_count:>2}vm".format(item.summary_tpl())
1029
1030 res.append({"name": key_func(item)[0],
1031 "key": key_func(item)[:4],
1032 "summ": summ,
koder aka kdanilov6b872662015-06-23 01:58:36 +03001033 "iops": int(iops),
1034 "bw": int(bw),
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03001035 "conf": str(conf_perc),
1036 "dev": str(dev_perc),
koder aka kdanilov6b872662015-06-23 01:58:36 +03001037 "iops_per_vm": int(iops_per_vm),
1038 "bw_per_vm": int(bw_per_vm),
1039 "lat_50": lat_50,
koder aka kdanilov170936a2015-06-27 22:51:17 +03001040 "lat_95": lat_95,
koder aka kdanilova94dfe12015-08-19 13:04:51 +03001041 "lat_avg": lat_avg,
1042
1043 "iops_sys": iops_sys,
1044 "iops_sys_per_vm": iops_sys_per_vm,
1045 "sys_conf": iops_sys_conf,
1046 "sys_dev": iops_sys_dev})
koder aka kdanilovbc2c8982015-06-13 02:50:43 +03001047
koder aka kdanilov6b872662015-06-23 01:58:36 +03001048 return res
1049
1050 Field = collections.namedtuple("Field", ("header", "attr", "allign", "size"))
1051 fiels_and_header = [
1052 Field("Name", "name", "l", 7),
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03001053 Field("Description", "summ", "l", 19),
koder aka kdanilov6b872662015-06-23 01:58:36 +03001054 Field("IOPS\ncum", "iops", "r", 3),
koder aka kdanilova94dfe12015-08-19 13:04:51 +03001055 # Field("IOPS_sys\ncum", "iops_sys", "r", 3),
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03001056 Field("KiBps\ncum", "bw", "r", 6),
1057 Field("Cnf %\n95%", "conf", "r", 3),
1058 Field("Dev%", "dev", "r", 3),
1059 Field("iops\n/vm", "iops_per_vm", "r", 3),
1060 Field("KiBps\n/vm", "bw_per_vm", "r", 6),
koder aka kdanilov6b872662015-06-23 01:58:36 +03001061 Field("lat ms\nmedian", "lat_50", "r", 3),
koder aka kdanilov170936a2015-06-27 22:51:17 +03001062 Field("lat ms\n95%", "lat_95", "r", 3),
1063 Field("lat\navg", "lat_avg", "r", 3),
koder aka kdanilov6b872662015-06-23 01:58:36 +03001064 ]
1065
1066 fiels_and_header_dct = dict((item.attr, item) for item in fiels_and_header)
1067
1068 @classmethod
1069 def format_for_console(cls, results):
1070 """
1071 create a table with io performance report
1072 for console
1073 """
1074
1075 tab = texttable.Texttable(max_width=120)
1076 tab.set_deco(tab.HEADER | tab.VLINES | tab.BORDER)
1077 tab.set_cols_align([f.allign for f in cls.fiels_and_header])
1078 sep = ["-" * f.size for f in cls.fiels_and_header]
1079 tab.header([f.header for f in cls.fiels_and_header])
koder aka kdanilov6b872662015-06-23 01:58:36 +03001080 prev_k = None
1081 for item in cls.prepare_data(results):
koder aka kdanilov6b872662015-06-23 01:58:36 +03001082 if prev_k is not None:
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03001083 if prev_k != item["key"]:
koder aka kdanilov6b872662015-06-23 01:58:36 +03001084 tab.add_row(sep)
1085
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03001086 prev_k = item["key"]
koder aka kdanilov6b872662015-06-23 01:58:36 +03001087 tab.add_row([item[f.attr] for f in cls.fiels_and_header])
1088
1089 return tab.draw()
1090
1091 @classmethod
1092 def format_diff_for_console(cls, list_of_results):
1093 """
1094 create a table with io performance report
1095 for console
1096 """
1097
1098 tab = texttable.Texttable(max_width=200)
1099 tab.set_deco(tab.HEADER | tab.VLINES | tab.BORDER)
1100
1101 header = [
1102 cls.fiels_and_header_dct["name"].header,
1103 cls.fiels_and_header_dct["summ"].header,
1104 ]
1105 allign = ["l", "l"]
1106
1107 header.append("IOPS ~ Cnf% ~ Dev%")
1108 allign.extend(["r"] * len(list_of_results))
1109 header.extend(
1110 "IOPS_{0} %".format(i + 2) for i in range(len(list_of_results[1:]))
1111 )
1112
1113 header.append("BW")
1114 allign.extend(["r"] * len(list_of_results))
1115 header.extend(
1116 "BW_{0} %".format(i + 2) for i in range(len(list_of_results[1:]))
1117 )
1118
1119 header.append("LAT")
1120 allign.extend(["r"] * len(list_of_results))
1121 header.extend(
1122 "LAT_{0}".format(i + 2) for i in range(len(list_of_results[1:]))
1123 )
1124
1125 tab.header(header)
1126 sep = ["-" * 3] * len(header)
1127 processed_results = map(cls.prepare_data, list_of_results)
1128
1129 key2results = []
1130 for res in processed_results:
1131 key2results.append(dict(
1132 ((item["name"], item["summ"]), item) for item in res
1133 ))
1134
1135 prev_k = None
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03001136 iops_frmt = "{0[iops]} ~ {0[conf]:>2} ~ {0[dev]:>2}"
koder aka kdanilov6b872662015-06-23 01:58:36 +03001137 for item in processed_results[0]:
koder aka kdanilov6b872662015-06-23 01:58:36 +03001138 if prev_k is not None:
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03001139 if prev_k != item["key"]:
koder aka kdanilov6b872662015-06-23 01:58:36 +03001140 tab.add_row(sep)
1141
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03001142 prev_k = item["key"]
koder aka kdanilov6b872662015-06-23 01:58:36 +03001143
1144 key = (item['name'], item['summ'])
1145 line = list(key)
1146 base = key2results[0][key]
1147
1148 line.append(iops_frmt.format(base))
1149
1150 for test_results in key2results[1:]:
1151 val = test_results.get(key)
1152 if val is None:
1153 line.append("-")
1154 elif base['iops'] == 0:
1155 line.append("Nan")
1156 else:
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03001157 prc_val = {'dev': val['dev'], 'conf': val['conf']}
koder aka kdanilov6b872662015-06-23 01:58:36 +03001158 prc_val['iops'] = int(100 * val['iops'] / base['iops'])
1159 line.append(iops_frmt.format(prc_val))
1160
1161 line.append(base['bw'])
1162
1163 for test_results in key2results[1:]:
1164 val = test_results.get(key)
1165 if val is None:
1166 line.append("-")
1167 elif base['bw'] == 0:
1168 line.append("Nan")
1169 else:
1170 line.append(int(100 * val['bw'] / base['bw']))
1171
1172 for test_results in key2results:
1173 val = test_results.get(key)
1174 if val is None:
1175 line.append("-")
1176 else:
1177 line.append("{0[lat_50]} - {0[lat_95]}".format(val))
1178
1179 tab.add_row(line)
1180
1181 tab.set_cols_align(allign)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +03001182 return tab.draw()