Created
August 17, 2024 23:02
-
-
Save Mstaaravin/1df9546ebe27e5896cdaf250d1c8d645 to your computer and use it in GitHub Desktop.
IOzone benchmark disk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Global variables for output unit and IOzone parameters | |
OUTPUT_UNIT="MB/s" | |
FILE_SIZE="4G" | |
RECORD_SIZE_MIN="4k" | |
RECORD_SIZE_MAX="16M" | |
TEST_TYPES="-a -i 0 -i 1 -i 2" | |
TEST_FILE="$PWD/iozone_test_file" | |
ITERATIONS=3 | |
# Function to display IOzone parameters | |
show_parameters() { | |
echo "IOzone Parameters:" | |
echo "------------------" | |
echo "File size: $FILE_SIZE" | |
echo "Record sizes: $RECORD_SIZE_MIN to $RECORD_SIZE_MAX" | |
echo "Test types: $TEST_TYPES" | |
echo "Output Unit: $OUTPUT_UNIT" | |
echo "Test file location: $TEST_FILE" | |
echo "Current directory: $PWD" | |
echo "Number of iterations: $ITERATIONS" | |
echo "------------------" | |
} | |
# Function to convert and format results | |
convert_and_format() { | |
local value=$1 | |
case $OUTPUT_UNIT in | |
"KB/s") | |
echo "$value" | |
;; | |
"MB/s") | |
awk -v val="$value" 'BEGIN {printf "%.2f", val/1024}' | |
;; | |
"GB/s") | |
awk -v val="$value" 'BEGIN {printf "%.3f", val/(1024*1024)}' | |
;; | |
*) | |
echo "Invalid unit" | |
exit 1 | |
;; | |
esac | |
} | |
# Function to run IOzone and process results | |
run_iozone_and_show_results() { | |
echo "Running IOzone benchmark..." | |
echo "Command: iozone $TEST_TYPES -s $FILE_SIZE -r $RECORD_SIZE_MIN -r $RECORD_SIZE_MAX -I -o -B -f $TEST_FILE" | |
# Arrays to store results | |
declare -a write_speeds re_write_speeds read_speeds re_read_speeds random_read_speeds random_write_speeds | |
for ((i=1; i<=ITERATIONS; i++)); do | |
echo "Running iteration $i of $ITERATIONS" | |
results=$(iozone $TEST_TYPES -s $FILE_SIZE -r $RECORD_SIZE_MIN -r $RECORD_SIZE_MAX -I -o -B -f $TEST_FILE) | |
file_size_kb=$(echo $FILE_SIZE | sed 's/G/048576/') | |
values=$(echo "$results" | awk -v fs="$file_size_kb" '$1 == fs && $2 == "16384" {print $3, $4, $5, $6, $7, $8}') | |
write_speeds[$i]=$(echo $values | awk '{print $1}') | |
re_write_speeds[$i]=$(echo $values | awk '{print $2}') | |
read_speeds[$i]=$(echo $values | awk '{print $3}') | |
re_read_speeds[$i]=$(echo $values | awk '{print $4}') | |
random_read_speeds[$i]=$(echo $values | awk '{print $5}') | |
random_write_speeds[$i]=$(echo $values | awk '{print $6}') | |
done | |
echo "IOzone Benchmark Results (Average of $ITERATIONS runs):" | |
echo "-------------------------" | |
echo "Write Speed ($OUTPUT_UNIT): $(convert_and_format $(echo ${write_speeds[@]} | awk '{sum=0; for(i=1;i<=NF;i++)sum+=$i; print sum/NF}'))" | |
echo "Re-write Speed ($OUTPUT_UNIT): $(convert_and_format $(echo ${re_write_speeds[@]} | awk '{sum=0; for(i=1;i<=NF;i++)sum+=$i; print sum/NF}'))" | |
echo "Read Speed ($OUTPUT_UNIT): $(convert_and_format $(echo ${read_speeds[@]} | awk '{sum=0; for(i=1;i<=NF;i++)sum+=$i; print sum/NF}'))" | |
echo "Re-read Speed ($OUTPUT_UNIT): $(convert_and_format $(echo ${re_read_speeds[@]} | awk '{sum=0; for(i=1;i<=NF;i++)sum+=$i; print sum/NF}'))" | |
echo "Random Read Speed ($OUTPUT_UNIT): $(convert_and_format $(echo ${random_read_speeds[@]} | awk '{sum=0; for(i=1;i<=NF;i++)sum+=$i; print sum/NF}'))" | |
echo "Random Write Speed ($OUTPUT_UNIT): $(convert_and_format $(echo ${random_write_speeds[@]} | awk '{sum=0; for(i=1;i<=NF;i++)sum+=$i; print sum/NF}'))" | |
echo "-------------------------" | |
} | |
# Main script | |
echo "Starting IOzone Disk Benchmark" | |
show_parameters | |
run_iozone_and_show_results | |
# Clean up | |
rm -f $TEST_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment