From e41a4dfffb008f72472b884f817d1091445b49b3 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Sat, 6 Aug 2022 01:10:13 -0400 Subject: [PATCH] Updated the disk read test to use fio instead of dd; added new test for 4k random reads (previous test was for sequential reads) --- src/main.rs | 20 ++++++++++++--- src/tests/disk.rs | 63 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 61 insertions(+), 22 deletions(-) diff --git a/src/main.rs b/src/main.rs index c55678f..75f2f29 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,9 +28,20 @@ struct Disk { #[derive(Subcommand)] enum DiskCommands { - // disk read subcommand - #[clap(name = "read-test", about = "Read from /dev/zero to determine sequential disk read speeds.")] - ReadTest { + // sequential disk read subcommand + #[clap(name = "read_seq", about = "Sequential disk read speed test.")] + ReadSeqTest { + #[clap(short = 'f', default_value_t = String::from("/tmp/disk-test.tmp"))] + tempfile: String, + #[clap(short = 's', default_value_t = 15)] + size: u8, + }, + + // random disk read subcommand + #[clap(name = "read_rand", about = "Random 4K disk read speed test.")] + ReadRandTest { + #[clap(short = 'f', default_value_t = String::from("/tmp/disk-test.tmp"))] + tempfile: String, #[clap(short = 's', default_value_t = 15)] size: u8, }, @@ -78,7 +89,8 @@ fn main() { // map subcommands back to the main command match &cli.command { Commands::Disk(args) => match &args.disk_commands { - DiskCommands::ReadTest { size } => tests::disk::disk_read_test(size), + DiskCommands::ReadSeqTest { tempfile, size } => tests::disk::disk_read_seq_test(tempfile, size), + DiskCommands::ReadRandTest { tempfile, size } => tests::disk::disk_read_rand_test(tempfile, size), DiskCommands::WriteTest { tempfile, size } => tests::disk::disk_write_test(tempfile, size), } diff --git a/src/tests/disk.rs b/src/tests/disk.rs index c9c3480..8fc2208 100644 --- a/src/tests/disk.rs +++ b/src/tests/disk.rs @@ -1,31 +1,58 @@ use std::fs; use std::process::Command; -// test disk read speeds by reading for /dev/zero and writing it to /dev/null -pub fn disk_read_test(size: &u8) { - // convert size in Gigabytes down to Megabytes - let size_gigs: u32 = (*size as u32 * 1024 * 8).into(); - - // run sync to clear out any disk caches prior to running - Command::new("sync"); - - // run the dd command - let output = Command::new("dd") - .arg("bs=128k") - .arg(format!("count={}", size_gigs)) - .arg("if=/dev/zero") - .arg("of=/dev/null") +// test disk sequential read speeds w/ fio +pub fn disk_read_seq_test(tempfile: &str, size: &u8) { + // run the fio command + let output = Command::new("fio") + .arg("--name=TEST") + .arg(format!("--filename={}", tempfile)) + .arg("--rw=read") + .arg("--size=2g") + .arg(format!("--io_size={}g", size)) + .arg("--blocksize=1024k") + .arg("--ioengine=libaio") + .arg("--fsync=10000") + .arg("--iodepth=32") + .arg("--direct=1") + .arg("--numjobs=1") + .arg("--runtime=60") + .arg("--group_reporting") .output() .expect("Failed to execute command"); // check that the command succeeded assert!(output.status.success()); - // dd's output ends up in stderr - println!("{}", String::from_utf8_lossy(&output.stderr)); + // print the test's output + println!("{}", String::from_utf8_lossy(&output.stdout)); +} - // run another sync to clear out the disk's cache - Command::new("sync"); +// test disk 4K random read speeds w/ fio +pub fn disk_read_rand_test(tempfile: &str, size: &u8) { + // run the fio command + let output = Command::new("fio") + .arg("--name=TEST") + .arg(format!("--filename={}", tempfile)) + .arg("--rw=randread") + .arg("--size=2g") + .arg(format!("--io_size={}g", size)) + .arg("--blocksize=4k") + .arg("--ioengine=libaio") + .arg("--fsync=1") + .arg("--iodepth=32") + .arg("--direct=1") + .arg("--numjobs=1") + .arg("--runtime=60") + .arg("--group_reporting") + .output() + .expect("Failed to execute command"); + + // check that the command succeeded + assert!(output.status.success()); + + // print the test's output + println!("{}", String::from_utf8_lossy(&output.stdout)); } // test disk write speeds by continually writing zeroes to it