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
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
def main():
|
|
|
|
|
|
|
|
global fio
|
2019-04-22 18:37:52 +00:00
|
|
|
if (len(sys.argv) < 7):
|
2018-05-11 21:39:35 +00:00
|
|
|
print("usage:")
|
2019-04-22 18:37:52 +00:00
|
|
|
print(" " + sys.argv[0] + " <nvmf/iscsi> <io_size> <queue_depth> <test_type> <runtime> <num_jobs>")
|
2018-05-11 21:39:35 +00:00
|
|
|
print("advanced usage:")
|
|
|
|
print("If you want to run fio with verify, please add verify string after runtime.")
|
|
|
|
print("Currently fio.py only support write rw randwrite randrw with verify enabled.")
|
2016-08-03 21:37:16 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2019-03-21 16:57:37 +00:00
|
|
|
app = str(sys.argv[1])
|
|
|
|
io_size = int(sys.argv[2])
|
|
|
|
queue_depth = int(sys.argv[3])
|
|
|
|
test_type = sys.argv[4]
|
|
|
|
runtime = sys.argv[5]
|
2019-04-22 18:37:52 +00:00
|
|
|
num_jobs = sys.argv[6]
|
|
|
|
|
2019-03-21 16:57:37 +00:00
|
|
|
verify = False
|
2019-04-22 18:37:52 +00:00
|
|
|
if len(sys.argv) > 7:
|
2016-08-03 21:37:16 +00:00
|
|
|
verify = True
|
|
|
|
|
2019-03-21 16:57:37 +00:00
|
|
|
if app == "nvmf":
|
|
|
|
devices = get_nvmf_target_devices()
|
|
|
|
elif app == "iscsi":
|
|
|
|
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):
|
|
|
|
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.")
|
2016-08-03 21:37:16 +00:00
|
|
|
else:
|
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__":
|
|
|
|
main()
|