def benchmark(directory,
volume=BENCHMARK_VOLUME,
rw_type=BENCHMARK_RW_TYPE,
job_number=BENCHMARK_JOB_NUMBER,
thread_number=BENCHMARK_THREAD_NUMBER,
block_size=BENCHMARK_IOPS_BLOCK_SIZE,
max_seconds=BENCHMARK_MAX_SECONDS):
"""Use fio to do benchmark.
"""
result = {}
config_file = os.path.join(directory, _BENCHMARK_CONFIG_FILE)
result_file = os.path.join(directory, _BENCHMARK_RESULT_FILE)
# prepare fio config
config = configparser.SafeConfigParser()
global_section = 'global'
config.add_section(global_section)
config.set(global_section, 'group_reporting', '1')
config.set(global_section, 'unlink', '1')
config.set(global_section, 'time_based', '1')
config.set(global_section, 'direct', '1')
config.set(global_section, 'size', volume)
config.set(global_section, 'rw', rw_type)
config.set(global_section, 'numjobs', job_number)
config.set(global_section, 'iodepth', thread_number)
config.set(global_section, 'bs', block_size)
config.set(global_section, 'runtime', max_seconds)
drive_section = 'drive'
config.add_section(drive_section)
config.set(drive_section, 'directory', directory)
fs.write_safe(
config_file,
lambda f: config.write(EqualSpaceRemover(f))
)
# start fio
ret = subproc.call(
['fio', config_file, '--norandommap',
'--minimal', '--output', result_file]
)
# parse fio terse result
# http://fio.readthedocs.io/en/latest/fio_doc.html#terse-output
if ret == 0:
with io.open(result_file) as fp:
metric_list = fp.read().split(';')
result[Metrics.READ_BPS.value] = int(
float(metric_list[6]) * 1024
)
result[Metrics.READ_IOPS.value] = int(metric_list[7])
result[Metrics.WRITE_BPS.value] = int(
float(metric_list[47]) * 1024
)
result[Metrics.WRITE_IOPS.value] = int(metric_list[48])
return result
评论列表
文章目录