From 39feb56aa00deaf900b96e386c9a7117f4fb9c48 Mon Sep 17 00:00:00 2001
From: ddomingu <ddomingu@users.noreply.github.com>
Date: Wed, 8 Jan 2025 18:50:29 +0100
Subject: [PATCH] Add a feature to enable workload loops with varying iodepth
 values (#836)

---
 config/samples/fio/cr.yaml                    |  3 +-
 config/samples/fio/vm-cr.yaml                 |  3 +-
 docs/fio_distributed.md                       | 31 ++++++++++---------
 roles/fio_distributed/templates/client.yaml   |  6 ++--
 .../templates/configmap.yml.j2                |  6 ++--
 5 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/config/samples/fio/cr.yaml b/config/samples/fio/cr.yaml
index c6e1c19c5..fbeccc1a8 100644
--- a/config/samples/fio/cr.yaml
+++ b/config/samples/fio/cr.yaml
@@ -38,7 +38,8 @@ spec:
       numjobs:
         - 1
       # with libaio ioengine, number of in-flight requests per process
-      iodepth: 4
+      iodepth:
+        - 4
       # how long to run read tests, this is TOO SHORT DURATION
       read_runtime: 15
       # how long to run write tests, this is TOO SHORT DURATION
diff --git a/config/samples/fio/vm-cr.yaml b/config/samples/fio/vm-cr.yaml
index 2a39af1a9..94a594497 100644
--- a/config/samples/fio/vm-cr.yaml
+++ b/config/samples/fio/vm-cr.yaml
@@ -51,7 +51,8 @@ spec:
       numjobs:
         - 1
       # with libaio ioengine, number of in-flight requests per process
-      iodepth: 4
+      iodepth:
+        - 4
       # how long to run write tests, this is TOO SHORT DURATION
       read_runtime: 15
       # how long to run read tests, this is TOO SHORT DURATION
diff --git a/docs/fio_distributed.md b/docs/fio_distributed.md
index 7f5576e0b..feb0de634 100644
--- a/docs/fio_distributed.md
+++ b/docs/fio_distributed.md
@@ -48,19 +48,22 @@ or even days to complete, and the jobs will continue through the nested loops un
 The workload loops are nested as such from the CR options:
 
 ```
-+-------->numjobs---------+
-|                         |
-| +------>bs|bsrange----+ |
-| |                     | |
-| | +---->job---------+ | |
-| | |                 | | |
-| | | +-->samples---+ | | |
-| | | |             | | | |
-| | | |             | | | |
-| | | +-------------+ | | |
-| | +-----------------+ | |
-| +---------------------+ |
-+-------------------------+
++---------->iodepth-----------+
+|                             |
+| +-------->numjobs---------+ |
+| |                         | |
+| | +------>bs|bsrange----+ | |
+| | |                     | | |
+| | | +---->job---------+ | | |
+| | | |                 | | | |
+| | | | +-->samples---+ | | | |
+| | | | |             | | | | |
+| | | | |             | | | | |
+| | | | +-------------+ | | | |
+| | | +-----------------+ | | |
+| | +---------------------+ | |
++---------------------------+ |
++-----------------------------+
 ```
 
 ### Understanding the CR options
@@ -131,7 +134,7 @@ The workload loops are nested as such from the CR options:
     - 256KiB-4096KiB
   ```
 - **numjobs**: (list) Number of clones of the job to run on each server -- Total jobs will be `numjobs * servers`
-- **iodepth**: Number of I/O units to keep in flight against a file; see `fio(1)`
+- **iodepth**: (list) Number of I/O units to keep in flight against a file; see `fio(1)`
 - **read_runtime**: Amount of time in seconds to run `read` workloads (including `readwrite` workloads)
 - **read_ramp_time**: Amount of time in seconds to ramp up `read` workloads (i.e., executing the workload without recording the data)
   > Note: We intentionally run `write` workloads to completion of the file size specified in order to ensure
diff --git a/roles/fio_distributed/templates/client.yaml b/roles/fio_distributed/templates/client.yaml
index 51df759a2..04fb65330 100644
--- a/roles/fio_distributed/templates/client.yaml
+++ b/roles/fio_distributed/templates/client.yaml
@@ -79,8 +79,9 @@ spec:
 {% for numjobs in workload_args.numjobs %}
 {% for i in loopvar %}
 {% for job in workload_args.jobs %}
-             cat /tmp/fio/fiojob-{{job}}-{{i}}-{{numjobs}}; mkdir -p /tmp/fiod-{{uuid}}/fiojob-{{job}}-{{i}}-{{numjobs}};
-             run_snafu -t fio -H /tmp/host/hosts -j /tmp/fio/fiojob-{{job}}-{{i}}-{{numjobs}} -s {{workload_args.samples}} -d /tmp/fiod-{{ uuid }}/fiojob-{{job}}-{{i}}-{{numjobs}} \
+{% for iodepth in workload_args.iodepth %}
+             cat /tmp/fio/fiojob-{{job}}-{{i}}-{{numjobs}}-{{iodepth}}; mkdir -p /tmp/fiod-{{uuid}}/fiojob-{{job}}-{{i}}-{{numjobs}}-{{iodepth}};
+             run_snafu -t fio -H /tmp/host/hosts -j /tmp/fio/fiojob-{{job}}-{{i}}-{{numjobs}}-{{iodepth}} -s {{workload_args.samples}} -d /tmp/fiod-{{ uuid }}/fiojob-{{job}}-{{i}}-{{numjobs}}-{{iodepth}} \
 {% if workload_args.debug is defined and workload_args.debug %}
              -v \
 {% endif %}
@@ -93,6 +94,7 @@ spec:
 {% endif %}
 {% endfor %}
 {% endfor %}
+{% endfor %}
 {% endfor %}
              echo run finished"
         volumeMounts:
diff --git a/roles/fio_distributed/templates/configmap.yml.j2 b/roles/fio_distributed/templates/configmap.yml.j2
index d39af63b6..a6bce0f17 100644
--- a/roles/fio_distributed/templates/configmap.yml.j2
+++ b/roles/fio_distributed/templates/configmap.yml.j2
@@ -50,7 +50,8 @@ data:
 {% endif %}
 {% for i in loopvar %}
 {% for job in workload_args.jobs %}
-  fiojob-{{job}}-{{i}}-{{numjobs}}: |
+{% for iodepth in workload_args.iodepth %}
+  fiojob-{{job}}-{{i}}-{{numjobs}}-{{iodepth}}: |
     [global]
 {% if workload_args.kind is defined and workload_args.kind == "vm" %}
     directory={{fio_path}}
@@ -76,7 +77,7 @@ data:
     ioengine=libaio
     size={{workload_args.filesize}}
     {{loopvar_str}}={{i}}
-    iodepth={{workload_args.iodepth}}
+    iodepth={{iodepth}}
     direct=1
     numjobs={{numjobs}}
 
@@ -99,3 +100,4 @@ data:
 {% endfor %}
 {% endfor %}
 {% endfor %}
+{% endfor %}