Replaced dd with fio in the disk write subcommand; added subcommand for disk random writes
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-08-06 01:27:15 -04:00
parent e41a4dfffb
commit 9856c59da9
2 changed files with 61 additions and 25 deletions

View File

@ -46,12 +46,21 @@ enum DiskCommands {
size: u8, size: u8,
}, },
// disk write subcommand // sequential disk write subcommand
#[clap(name = "write-test", about = "Write a large file to determine sequential disk write speeds.")] #[clap(name = "write_seq", about = "Write a large file to determine sequential disk write speeds.")]
WriteTest { WriteSeqTest {
#[clap(short = 't', default_value_t = String::from("/tmp/disk-test.tmp"))] #[clap(short = 't', default_value_t = String::from("/tmp/disk-test.tmp"))]
tempfile: String, tempfile: String,
#[clap(short = 's', default_value_t = 5)] #[clap(short = 's', default_value_t = 15)]
size: u8,
},
// random 4K disk write subcommand
#[clap(name = "write_rand", about = "Write a bunch of smallfiles to determine random disk write speeds.")]
WriteRandTest {
#[clap(short = 't', default_value_t = String::from("/tmp/disk-test.tmp"))]
tempfile: String,
#[clap(short = 's', default_value_t = 15)]
size: u8, size: u8,
}, },
} }
@ -91,7 +100,8 @@ fn main() {
Commands::Disk(args) => match &args.disk_commands { Commands::Disk(args) => match &args.disk_commands {
DiskCommands::ReadSeqTest { tempfile, size } => tests::disk::disk_read_seq_test(tempfile, 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::ReadRandTest { tempfile, size } => tests::disk::disk_read_rand_test(tempfile, size),
DiskCommands::WriteTest { tempfile, size } => tests::disk::disk_write_test(tempfile, size), DiskCommands::WriteSeqTest { tempfile, size } => tests::disk::disk_write_seq_test(tempfile, size),
DiskCommands::WriteRandTest { tempfile, size } => tests::disk::disk_write_rand_test(tempfile, size),
} }
Commands::Net(args) => match &args.net_commands { Commands::Net(args) => match &args.net_commands {

View File

@ -1,4 +1,3 @@
use std::fs;
use std::process::Command; use std::process::Command;
// test disk sequential read speeds w/ fio // test disk sequential read speeds w/ fio
@ -40,6 +39,33 @@ pub fn disk_read_rand_test(tempfile: &str, size: &u8) {
.arg("--blocksize=4k") .arg("--blocksize=4k")
.arg("--ioengine=libaio") .arg("--ioengine=libaio")
.arg("--fsync=1") .arg("--fsync=1")
.arg("--iodepth=1")
.arg("--direct=1")
.arg("--numjobs=32")
.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 sequential disk write speeds w/ fio
pub fn disk_write_seq_test(tempfile: &str, size: &u8) {
// run the fio command
let output = Command::new("fio")
.arg("--name=TEST")
.arg(format!("--filename={}", tempfile))
.arg("--rw=write")
.arg("--size=2g")
.arg(format!("--io_size={}g", size))
.arg("--blocksize=1024k")
.arg("--ioengine=libaio")
.arg("--fsync=10000")
.arg("--iodepth=32") .arg("--iodepth=32")
.arg("--direct=1") .arg("--direct=1")
.arg("--numjobs=1") .arg("--numjobs=1")
@ -55,29 +81,29 @@ pub fn disk_read_rand_test(tempfile: &str, size: &u8) {
println!("{}", String::from_utf8_lossy(&output.stdout)); println!("{}", String::from_utf8_lossy(&output.stdout));
} }
// test disk write speeds by continually writing zeroes to it // test random 4K disk write speeds w/ fio
pub fn disk_write_test(tempfile: &str, size: &u8) { pub fn disk_write_rand_test(tempfile: &str, size: &u8) {
// convert size in Gigabytes down to Megabytes // run the fio command
let size_gigs: u32 = (*size as u32 * 1024).into(); let output = Command::new("fio")
.arg("--name=TEST")
// run the dd command with a block size of 1 MB .arg(format!("--filename={}", tempfile))
let output = Command::new("dd") .arg("--rw=randrw")
.arg("bs=1M") .arg("--size=2g")
.arg(format!("count={}", size_gigs)) .arg(format!("--io_size={}g", size))
.arg("if=/dev/zero") .arg("--blocksize=4k")
.arg(format!("of={}", tempfile)) .arg("--ioengine=libaio")
.arg("--fsync=1")
.arg("--iodepth=1")
.arg("--direct=1")
.arg("--numjobs=32")
.arg("--runtime=60")
.arg("--group_reporting")
.output() .output()
.expect("Failed to execute command"); .expect("Failed to execute command");
// check that the command succeeded // check that the command succeeded
assert!(output.status.success()); assert!(output.status.success());
// for whatever reason, `dd` output ends up in stderr // print the test's output
println!("{}", String::from_utf8_lossy(&output.stderr)); println!("{}", String::from_utf8_lossy(&output.stdout));
// remove the test file
match fs::remove_file(tempfile) {
Ok(()) => println!("Cleaning up..."),
Err(e) => println!("There was a problem during cleanup - {}", e),
}
} }