How to Use the Command 'fio' (with Examples)

How to Use the Command 'fio' (with Examples)

fio, short for Flexible I/O Tester, is an essential tool for anyone needing to perform advanced input/output operations testing. It allows users to simulate and measure the performance of storage devices by executing a wide array of I/O patterns. With its versatile nature, fio suits both routine performance checks and comprehensive stress testing of storage systems. It can emulate different workloads by varying the read/write mix, block size, access patterns, and more, making it indispensable for system administrators, developers, and quality assurance teams.

Use Case 1: Test Random Reads

Code:

fio --filename=path/to/file --direct=1 --rw=randread --bs=4k --ioengine=libaio --iodepth=256 --runtime=120 --numjobs=4 --time_based --group_reporting --name=job_name --eta-newline=1 --readonly

Motivation:

Testing random read performance is crucial for environments where applications rely on scattered data access, such as database servers. Random reads can stress a storage system in different ways compared to sequential access and reveal important aspects of latency and throughput.

Explanation:

  • --filename=path/to/file: Specifies the file or device to be tested.
  • --direct=1: Enables direct I/O, bypassing the cache to ensure the results reflect the raw performance of the underlying storage.
  • --rw=randread: Configures the operation to perform random read tests.
  • --bs=4k: Sets the block size for I/O operations to 4 kilobytes, a common size reflecting typical system page size.
  • --ioengine=libaio: Utilizes the Linux asynchronous I/O engine for efficient non-blocking I/O.
  • --iodepth=256: Specifies the number of I/O operations to queue at once, allowing deeper queues to test how well the SSD handles concurrency.
  • --runtime=120: Runs the test for 120 seconds.
  • --numjobs=4: Spawns four separate jobs, emulating multiple processes accessing the storage concurrently.
  • --time_based: Runs the job for the specified runtime duration.
  • --group_reporting: Collates and simplifies output data across all jobs.
  • --name=job_name: Specifies a label for the job.
  • --eta-newline=1: Configures –eta display inline with new lines.
  • --readonly: Ensures no writes happen, thus making sure only read performance is measured.

Example Output:

job_name: (groupid=0, jobs=4): err= 0: pid=1234: Sun Oct 10 12:34:56 2023
  read: IOPS=250k, BW=976MiB/s, Latency=2.00ms
      ...

Use Case 2: Test Sequential Reads

Code:

fio --filename=path/to/file --direct=1 --rw=read --bs=4k --ioengine=libaio --iodepth=256 --runtime=120 --numjobs=4 --time_based --group_reporting --name=job_name --eta-newline=1 --readonly

Motivation:

Sequential read performance is critical for applications that process large datasets, such as video streaming or data migration tasks. Understanding sequential access performance helps administrators optimize throughput for such workloads.

Explanation:

  • --filename=path/to/file: Directs the test to a specific file or device.
  • --direct=1: Uses direct I/O, bypassing the system cache.
  • --rw=read: Sets the operation to perform sequential read tests.
  • --bs=4k: Specifies 4k block size for the operation.
  • --ioengine=libaio: Chooses the asynchronous I/O engine for Linux systems.
  • --iodepth=256: Test intensive concurrency with I/O operation depth set to 256.
  • --runtime=120: Executes the test for 2 minutes.
  • --numjobs=4: Employs four concurrent job threads.
  • --time_based: The job runs for a fixed time span.
  • --group_reporting: Simplifies reporting by grouping data from all threads.
  • --name=job_name: Assigns a name to this particular test scenario.
  • --eta-newline=1: Ensures continuous generation of new lines for ETA.
  • --readonly: Prevents write operations, focusing purely on read actions.

Example Output:

job_name: (groupid=0, jobs=4): err= 0: pid=1235: Mon Oct 11 13:00:00 2023
  read: IOPS=500k, BW=1952MiB/s, Latency=1.00ms
       ...

Use Case 3: Test Random Read/Write

Code:

fio --filename=path/to/file --direct=1 --rw=randrw --bs=4k --ioengine=libaio --iodepth=256 --runtime=120 --numjobs=4 --time_based --group_reporting --name=job_name --eta-newline=1

Motivation:

A mixed random read/write test is essential for applications that involve both input and output operations, such as transactional databases. This test can reveal how well a storage device balances concurrent read/write performance.

Explanation:

  • --filename=path/to/file: Targets a file or storage device for testing.
  • --direct=1: Conducts direct I/O, bypassing the system buffer to reflect actual storage behavior.
  • --rw=randrw: Configures the test to perform mixed random reads and writes.
  • --bs=4k: Uses a block size of 4k.
  • --ioengine=libaio: Employing asynchronous I/O operations for efficiency.
  • --iodepth=256: Tests with an I/O depth of 256, enabling high concurrency.
  • --runtime=120: Indicating the test should last 120 seconds.
  • --numjobs=4: Utilizes four workers in parallel.
  • --time_based: Establishes a fixed runtime for the test.
  • --group_reporting: Consolidating output data for clearer results.
  • --name=job_name: Identifies the job by assigning a name.
  • --eta-newline=1: Updates ETA on a new line for readability.

Example Output:

job_name: (groupid=0, jobs=4): err= 0: pid=1236: Tue Oct 12 14:45:00 2023
  read: IOPS=150k, BW=732MiB/s, Latency=2.20ms
  write: IOPS=100k, BW=488MiB/s, Latency=3.00ms
       ...

Use Case 4: Test with Parameters from a Job File

Code:

fio path/to/job_file

Motivation:

Utilizing a job file streamlines tests, especially when configurations are complex or need to be consistently recreated. It enables the organization and reusability of test parameters for ongoing performance assessments.

Explanation:

  • path/to/job_file: The path to a predefined job file containing all test parameters.

Example Output:

job_file_test: (groupid=0, jobs=1): err= 0: pid=1237: Wed Oct 13 15:23:00 2023
  read: IOPS=200k, BW=800MiB/s, Latency=2.50ms
       ...

Use Case 5: Convert a Specific Job File to Command-Line Options

Code:

fio --showcmd path/to/job_file

Motivation:

Converting a job file into command-line options is useful for understanding what each job file setting means in the context of fio commands. It aids in transparency and debugging, allowing users to know precisely what will be executed.

Explanation:

  • --showcmd path/to/job_file: Outputs the equivalent command line for the specified job file.

Example Output:

fio: ver=3.25, job_class=FIO_CMD, modified=Sat Oct 14 16:10:00 2023
Command Line: fio --filename=/dev/sdb --rw=read --bs=1m --iodepth=32 --runtime=300 --name=test

Conclusion

The fio command is a powerful, flexible tool that facilitates detailed testing of I/O performance for storage devices. Whether bolstering your knowledge of how random and sequential operations fare, managing complex testing through job files, or demystifying job configurations, fio provides a robust framework for evaluating and optimizing storage performance effectively.

Related Posts

How to Use the Command 'mosh' (with Examples)

How to Use the Command 'mosh' (with Examples)

Mobile Shell (mosh) is a progressive application designed to offer a resilient and interactive replacement for Secure Shell (SSH).

Read More
How to Use the 'git update-index' Command (with Examples)

How to Use the 'git update-index' Command (with Examples)

The git update-index command is a crucial tool within Git for directly manipulating the index, which serves as a staging area between the working directory and the repository.

Read More
How to Use the 'balena' Command (with Examples)

How to Use the 'balena' Command (with Examples)

Balena is a versatile command-line interface (CLI) tool designed to interact seamlessly with the balenaCloud, openBalena, and the balena API.

Read More