# Benchmarking

## fio

### Description

> Flexible IO Tester (Fio) is a benchmarking and workload simulation tool for Linux/Unix created by Jens Axboe, who also maintains the block layer of the Linux kernel. Fio is highly tunable and widely used for storage performance benchmarking.
> <br />...<br />
> There are also ways to run Fio on Windows, but generally other tools that are better suited for Windows OS, such as IOmeter or CrystalDiskMark are recommended.

[Performance benchmarking with Fio on Nutanix](https://portal.nutanix.com/page/documents/kbs/details?targetId=kA07V000000LX7xSAG)


### Usage
| Fio Argument       | Description |
|--------------------|-------------|
| <span style="white-space: pre; display: inline-block; width: 10em">`--name=str`</span> | Fio will create a file with the specified name to run the test. The file will be created at the specified path or in the current working directory if only a short name is provided.                                                                                            |
| `--ioengine=str`   | Defines how the job issues I/O to the test file. Key engines include `libaio` (Linux native), `solarisaio` (Solaris native), `posixaio` (POSIX), `windowsaio` (Windows native), and `nfs` (asynchronous I/O to NFS).                                                              |
| `--size=int`       | The size of the file on which Fio will run the benchmarking test.                                                                                                                                                                                                                 |
| `--rw=str`         | Specifies the I/O pattern. Options include `read`, `write`, `randread`, `randwrite`, `rw`, and `randrw`. Fio defaults to a 50/50 read/write mix for `rw` and `randrw`, adjustable with `--rwmixread`.                                                                             |
| `--bs=int`         | Defines the block size for the I/O generation. Default is 4k, but it is recommended to specify the block size explicitly for more accurate testing.                                                                                                                              |
| `--direct=bool`    | Use `true=1` for non-buffered I/O, which bypasses the OS filesystem cache. This setting is recommended for fair testing.                                                                                                                                                         |
| `--numjobs=int`    | Number of threads spawned by the test. Use `--group_reporting` to aggregate results across threads.                                                                                                                                                                               |
| `--iodepth=int`    | Number of I/O units to keep in flight against the file, representing the amount of outstanding I/O per thread.                                                                                                                                                                   |
| `--runtime=int`    | Specifies the duration (in seconds) for which the test will run.                                                                                                                                                                                                                  |
| `--time_based`     | If set, the test will run for the specified `runtime`, repeating the workload as many times as possible within that duration.                                                                                                                                                    |
| `--startdelay`     | Adds a delay (in seconds) between the test file creation and the actual test.                                                                                         |
| `--sync`           | Forces Fio to use synchronized I/O. This ensures that I/O operations are completed before proceeding, which can be used to simulate workloads that require strict data consistency.

| Test Description                                              | Fio Command                                                                                                                                                                                                                      |
|---------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Sequential writes with 1Mb block size. Imitates write backup activity or large file copies. | <code style="display: inline-block">fio --name=fiotest --filename=test1 --size=4Gb --rw=write --bs=1M --direct=1 --numjobs=8 --ioengine=libaio --iodepth=8 --group_reporting --runtime=30 --startdelay=60</code>   |
| Sequential reads with 1Mb block size. Imitates read backup activity or large file copies.  | <code style="display: inline-block">fio --name=fiotest --filename=test1 --size=4Gb --rw=read --bs=1M --direct=1 --numjobs=8 --ioengine=libaio --iodepth=8 --group_reporting --runtime=30 --startdelay=60</code>    |
| Random writes with 64Kb block size. Medium block size workload for writes.                | <code style="display: inline-block">fio --name=fiotest --filename=test1 --size=4Gb --rw=randwrite --bs=64k --direct=1 --numjobs=8 --ioengine=libaio --iodepth=16 --group_reporting --runtime=30 --startdelay=60</code> |
| Random reads with 64Kb block size. Medium block size workload for reads.                 | <code style="display: inline-block">fio --name=fiotest --filename=test1 --size=4Gb --rw=randread --bs=64k --direct=1 --numjobs=8 --ioengine=libaio --iodepth=16 --group_reporting --runtime=30 --startdelay=60</code>  |
| Random writes with 8Kb block size. Common database workload simulation for writes.       | <code style="display: inline-block">fio --name=fiotest --filename=test1 --size=4Gb --rw=randwrite --bs=8k --direct=1 --numjobs=8 --ioengine=libaio --iodepth=32 --group_reporting --runtime=30 --startdelay=60</code>  |
| Random reads with 8Kb block size. Common database workload simulation for reads.         | <code style="display: inline-block">fio --name=fiotest --filename=test1 --size=4Gb --rw=randread --bs=8k --direct=1 --numjobs=8 --ioengine=libaio --iodepth=32 --group_reporting --runtime=30 --startdelay=60</code>   |

### Additional Reading

- [fio.readthedocs.io](https://fio.readthedocs.io/en/latest/)
- [How fast are your disks? Find out the open source way, with fio](https://arstechnica.com/gadgets/2020/02/how-fast-are-your-disks-find-out-the-open-source-way-with-fio/)
- [Performance benchmarking with Fio on Nutanix](https://portal.nutanix.com/page/documents/kbs/details?targetId=kA07V000000LX7xSAG)