1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 import yardstick.ssh as ssh
14 from yardstick.benchmark.scenarios import base
16 LOG = logging.getLogger(__name__)
19 class Fio(base.Scenario):
20 """Execute fio benchmark on host
23 filename - file name for fio workload
26 default: /home/ec2-user/data.raw
27 bs - block size used for the io units
31 iodepth - number of iobuffers to keep in flight
35 rw - type of io pattern [read, write, randwrite, randread, rw, randrw]
39 ramp_time - run time before logging any performance
44 Read link below for more fio args description:
45 http://www.bluestop.org/fio/HOWTO.txt
47 __scenario_type__ = "Fio"
49 TARGET_SCRIPT = "fio_benchmark.bash"
51 def __init__(self, context):
52 self.context = context
53 self.setup_done = False
57 self.target_script = pkg_resources.resource_filename(
58 "yardstick.benchmark.scenarios.storage",
60 user = self.context.get("user", "root")
61 host = self.context.get("host", None)
62 key_filename = self.context.get("key_filename", "~/.ssh/id_rsa")
64 LOG.info("user:%s, host:%s", user, host)
65 self.client = ssh.SSH(user, host, key_filename=key_filename)
66 self.client.wait(timeout=600)
69 self.client.run("cat > ~/fio.sh",
70 stdin=open(self.target_script, "rb"))
72 self.setup_done = True
75 """execute the benchmark"""
76 default_args = "-ioengine=libaio -direct=1 " \
77 "-group_reporting -numjobs=1 -time_based"
79 if not self.setup_done:
82 options = args["options"]
83 filename = options.get("filename", "/home/ec2-user/data.raw")
84 bs = options.get("bs", "4k")
85 iodepth = options.get("iodepth", "1")
86 rw = options.get("rw", "write")
87 ramp_time = options.get("ramp_time", 20)
88 name = "yardstick-fio"
89 # if run by a duration runner
90 duration_time = self.context.get("duration", None)
91 # if run by an arithmetic runner
92 arithmetic_time = options.get("duration", None)
94 runtime = duration_time
96 runtime = arithmetic_time
100 args = "-filename=%s -bs=%s -iodepth=%s -rw=%s -ramp_time=%s " \
101 "-runtime=%s -name=%s" \
102 % (filename, bs, iodepth, rw, ramp_time, runtime, name)
103 cmd = "sudo bash fio.sh %s %s %s" \
104 % (filename, args, default_args)
105 LOG.debug("Executing command: %s", cmd)
106 status, stdout, stderr = self.client.execute(cmd)
108 raise RuntimeError(stderr)
110 data = json.loads(stdout)
112 # TODO: add sla check
118 '''internal test function'''
119 key_filename = pkg_resources.resource_filename("yardstick.resources",
120 "files/yardstick_key")
122 "host": "10.0.0.101",
124 "key_filename": key_filename
127 logger = logging.getLogger("yardstick")
128 logger.setLevel(logging.DEBUG)
133 "filename": "/home/ec2-user/data.raw",
139 args = {"options": options}
141 result = fio.run(args)
144 if __name__ == '__main__':