2018-09-11 13:26:14 +00:00
|
|
|
#!/usr/bin/env python3
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-08-24 18:39:24 +00:00
|
|
|
from subprocess import check_call, call, check_output, Popen, PIPE, CalledProcessError
|
2016-08-03 21:37:16 +00:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import signal
|
2019-05-14 11:47:34 +00:00
|
|
|
import os.path
|
|
|
|
import time
|
2019-05-24 22:58:19 +00:00
|
|
|
import argparse
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
fio_template = """
|
|
|
|
[global]
|
|
|
|
thread=1
|
|
|
|
invalidate=1
|
|
|
|
rw=%(testtype)s
|
|
|
|
time_based=1
|
|
|
|
runtime=%(runtime)s
|
|
|
|
ioengine=libaio
|
|
|
|
direct=1
|
|
|
|
bs=%(blocksize)d
|
|
|
|
iodepth=%(iodepth)d
|
2018-06-28 06:26:48 +00:00
|
|
|
norandommap=%(norandommap)d
|
2019-04-22 18:37:52 +00:00
|
|
|
numjobs=%(numjobs)s
|
2016-08-03 21:37:16 +00:00
|
|
|
%(verify)s
|
|
|
|
verify_dump=1
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
verify_template = """
|
|
|
|
do_verify=1
|
|
|
|
verify=crc32c-intel
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
fio_job_template = """
|
|
|
|
[job%(jobnumber)d]
|
|
|
|
filename=%(device)s
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2018-02-14 21:34:55 +00:00
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
def interrupt_handler(signum, frame):
|
|
|
|
fio.terminate()
|
2018-05-11 21:39:35 +00:00
|
|
|
print("FIO terminated")
|
2016-08-03 21:37:16 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
2018-02-14 21:34:55 +00:00
|
|
|
|
2019-05-24 22:58:19 +00:00
|
|
|
def main(io_size, protocol, queue_depth, test_type, runtime, num_jobs, verify):
|
2016-08-03 21:37:16 +00:00
|
|
|
global fio
|
|
|
|
|
2019-05-24 22:58:19 +00:00
|
|
|
if protocol == "nvmf":
|
2019-03-21 16:57:37 +00:00
|
|
|
devices = get_nvmf_target_devices()
|
2019-05-24 22:58:19 +00:00
|
|
|
elif protocol == "iscsi":
|
2019-03-21 16:57:37 +00:00
|
|
|
devices = get_iscsi_target_devices()
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
configure_devices(devices)
|
2018-08-22 07:47:55 +00:00
|
|
|
try:
|
2019-04-03 07:47:43 +00:00
|
|
|
fio_executable = check_output("which fio", shell=True).split()[0]
|
2018-08-24 18:39:24 +00:00
|
|
|
except CalledProcessError as e:
|
2019-04-03 07:47:43 +00:00
|
|
|
sys.stderr.write(str(e))
|
|
|
|
sys.stderr.write("\nCan't find the fio binary, please install it.\n")
|
|
|
|
sys.exit(1)
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
device_paths = ['/dev/' + dev for dev in devices]
|
2019-03-21 16:57:37 +00:00
|
|
|
print("Device paths:")
|
|
|
|
print(device_paths)
|
2016-08-03 21:37:16 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
signal.signal(signal.SIGTERM, interrupt_handler)
|
|
|
|
signal.signal(signal.SIGINT, interrupt_handler)
|
|
|
|
fio = Popen([fio_executable, '-'], stdin=PIPE)
|
2019-04-22 18:37:52 +00:00
|
|
|
fio.communicate(create_fio_config(io_size, queue_depth, device_paths, test_type, runtime, num_jobs, verify).encode())
|
2016-08-03 21:37:16 +00:00
|
|
|
fio.stdin.close()
|
|
|
|
rc = fio.wait()
|
2018-05-11 21:39:35 +00:00
|
|
|
print("FIO completed with code %d\n" % rc)
|
2016-08-03 21:37:16 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
sys.exit(rc)
|
|
|
|
|
2018-02-14 21:34:55 +00:00
|
|
|
|
2019-03-21 16:57:37 +00:00
|
|
|
def get_iscsi_target_devices():
|
2016-08-03 21:37:16 +00:00
|
|
|
output = check_output('iscsiadm -m session -P 3', shell=True)
|
2018-05-11 21:39:35 +00:00
|
|
|
return re.findall("Attached scsi disk (sd[a-z]+)", output.decode("ascii"))
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-02-14 21:34:55 +00:00
|
|
|
|
2019-03-21 16:57:37 +00:00
|
|
|
def get_nvmf_target_devices():
|
|
|
|
output = str(check_output('lsblk -l -o NAME', shell=True).decode())
|
|
|
|
return re.findall("(nvme[0-9]+n[0-9]+)\n", output)
|
|
|
|
|
|
|
|
|
2019-04-22 18:37:52 +00:00
|
|
|
def create_fio_config(size, q_depth, devices, test, run_time, num_jobs, verify):
|
2018-06-28 06:26:48 +00:00
|
|
|
norandommap = 0
|
2016-08-03 21:37:16 +00:00
|
|
|
if not verify:
|
|
|
|
verifyfio = ""
|
2018-06-28 06:26:48 +00:00
|
|
|
norandommap = 1
|
2016-08-03 21:37:16 +00:00
|
|
|
else:
|
|
|
|
verifyfio = verify_template
|
|
|
|
fiofile = fio_template % {"blocksize": size, "iodepth": q_depth,
|
2018-06-28 06:26:48 +00:00
|
|
|
"testtype": test, "runtime": run_time,
|
2019-04-22 18:37:52 +00:00
|
|
|
"norandommap": norandommap, "verify": verifyfio,
|
|
|
|
"numjobs": num_jobs}
|
2016-08-03 21:37:16 +00:00
|
|
|
for (i, dev) in enumerate(devices):
|
|
|
|
fiofile += fio_job_template % {"jobnumber": i, "device": dev}
|
|
|
|
return fiofile
|
|
|
|
|
2018-02-14 21:34:55 +00:00
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
def set_device_parameter(devices, filename_template, value):
|
2018-05-11 21:51:54 +00:00
|
|
|
valid_value = True
|
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
for dev in devices:
|
|
|
|
filename = filename_template % dev
|
|
|
|
f = open(filename, 'r+b')
|
2018-05-11 21:51:54 +00:00
|
|
|
try:
|
|
|
|
f.write(value.encode())
|
|
|
|
f.close()
|
|
|
|
except OSError:
|
|
|
|
valid_value = False
|
|
|
|
continue
|
|
|
|
|
|
|
|
return valid_value
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-02-14 21:34:55 +00:00
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
def configure_devices(devices):
|
2019-05-14 11:47:34 +00:00
|
|
|
|
|
|
|
for dev in devices:
|
|
|
|
retry = 30
|
|
|
|
while retry > 0:
|
|
|
|
if os.path.exists("/sys/block/%s/queue/nomerges" % dev):
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
retry = retry - 1
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
set_device_parameter(devices, "/sys/block/%s/queue/nomerges", "2")
|
|
|
|
set_device_parameter(devices, "/sys/block/%s/queue/nr_requests", "128")
|
|
|
|
requested_qd = 128
|
|
|
|
qd = requested_qd
|
|
|
|
while qd > 0:
|
|
|
|
try:
|
|
|
|
set_device_parameter(devices, "/sys/block/%s/device/queue_depth", str(qd))
|
|
|
|
break
|
|
|
|
except IOError:
|
|
|
|
qd = qd - 1
|
|
|
|
if qd == 0:
|
2018-05-11 21:39:35 +00:00
|
|
|
print("Could not set block device queue depths.")
|
2019-04-25 11:07:41 +00:00
|
|
|
elif qd < requested_qd:
|
2018-05-11 21:39:35 +00:00
|
|
|
print("Requested queue_depth {} but only {} is supported.".format(str(requested_qd), str(qd)))
|
2018-05-11 21:51:54 +00:00
|
|
|
if not set_device_parameter(devices, "/sys/block/%s/queue/scheduler", "noop"):
|
|
|
|
set_device_parameter(devices, "/sys/block/%s/queue/scheduler", "none")
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-02-14 21:34:55 +00:00
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
if __name__ == "__main__":
|
2019-05-24 22:58:19 +00:00
|
|
|
parser = argparse.ArgumentParser(description="fio.py")
|
|
|
|
parser.add_argument("-i", "--io-size", type=int, help="The desired I/O size in bytes.", required=True)
|
|
|
|
parser.add_argument("-p", "--protocol", type=str, help="The protocol we are testing against. One of iscsi or nvmf.", required=True)
|
|
|
|
parser.add_argument("-d", "--queue-depth", type=int, help="The desired queue depth for each job.", required=True)
|
|
|
|
parser.add_argument("-t", "--test-type", type=str, help="The fio I/O pattern to run. e.g. read, randwrite, randrw.", required=True)
|
|
|
|
parser.add_argument("-r", "--runtime", type=int, help="Time in seconds to run the workload.", required=True)
|
|
|
|
parser.add_argument("-n", "--num-jobs", type=int, help="The number of fio jobs to run in your workload. default 1.", default=1)
|
|
|
|
parser.add_argument("-v", "--verify", action="store_true", help="Supply this argument to verify the I/O.", default=False)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.protocol.lower() != "nvmf" and args.protocol.lower() != "iscsi":
|
|
|
|
parser.error("Protocol must be one of the following: nvmf, iscsi.")
|
|
|
|
|
|
|
|
main(args.io_size, args.protocol, args.queue_depth, args.test_type, args.runtime, args.num_jobs, args.verify)
|