website-scripts/Linux/Debian/Testing/fio-testdiskspeed.sh

136 lines
5.3 KiB
Bash

#!/bin/bash
#Copyright 2023 Robert Fauls. Licensed under the GNU GPLv3 License.
#This script will test disk performance and report results.
#It is ONLY tested on Debian!
#Based off of guide from Google: https://cloud.google.com/compute/docs/disks/benchmarking-pd-performance
#Scripted to provide all tests at once, with a little bit of customization/tuning for individual requirements.
#Clear the screen
clear
#Set colors for text formatting
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
RESET='\033[0m' # No Color
echo -e "${RED}This script will automatically install fio if it is not already installed.${RESET}"
echo -e "${BLUE}Press Enter to continue...${RESET}"
read -p ""
# Check if the script is running as root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Please run this script as root or use sudo.${RESET}"
exit 1
fi
# Check if 'fio' is installed
if ! command -v fio &>/dev/null; then
# 'fio' is not installed; Install it
echo -e "${YELLOW}fio is not installed. Installing fio...${RESET}"
apt-get update
apt-get install -y fio
else
# 'fio' is already installed; Do nothing and proceed
:
fi
#Check if fio installation was successful
if ! command -v fio &>/dev/null; then
echo "fio installation failed. Exiting."
exit 1
fi
# Prompt the user to enter a directory path
echo -e "${YELLOW}We need a place to put the fio test files."
echo "If the directory does not exist, it will be created for you."
echo "PLEASE USE AN EMPTY DIRECTORY!"
echo -e "${RED}If you don't specify an EMPTY directory, some of your files may be deleted.${RESET}"
echo -e "${BLUE}Please enter the directory you would like to use (or press Enter to use ${HOME}/disktestdir): ${RESET}"
read -p "" TEST_DIR
# Check if the user has entered a path
if [ -z "$TEST_DIR" ]; then
# User pressed Enter without specifying a path; Use the default directory
TEST_DIR="${HOME}/disktestdir"
fi
# Check if the specified directory exists
if [ ! -d "$TEST_DIR" ]; then
# Directory does not exist; Create it
echo -e "${GREEN}The directory $TEST_DIR does not exist. Creating it...${RESET}"
mkdir -p "$TEST_DIR"
fi
# Print the directory that will be used for the rest of the script
echo -e "${GREEN}The script will use the following directory: $TEST_DIR ${RESET}"
# Use the 'df' command to get the available space in GB
AVAILABLE_SPACE=$(df -BG "$TEST_DIR" | awk 'NR==2 {print $4}')
# Print the available space
echo "Available space in $TEST_DIR: $AVAILABLE_SPACE"
# Extract the numerical part of the available space and divide it by 16
NUMERIC_SPACE=${AVAILABLE_SPACE%G}
FILE_SIZE=$((NUMERIC_SPACE / 16))
echo -e "${GREEN}This script uses 16 threads for IOPS testing. Your current available disk space is: "${AVAILABLE_SPACE%G}"G"
echo -e "We will use "$FILE_SIZE"G for the test files."
echo -e "Each test will take approximately 1 minute to complete.${RESET}"
echo -e "${YELLOW}While executing the tests, it may be difficult to ctrl+c. Please be patient!${RESET}"
echo -e "${GREEN}BEGIN Write Throughput (1/4)${RESET}"
echo "BEGIN Write Throughput (1/4)" > $TEST_DIR/fio_output.txt
fio --name=write_throughput --directory=$TEST_DIR --numjobs=16 \
--size=$FILE_SIZE\G --time_based --runtime=60s --ramp_time=2s --ioengine=libaio \
--direct=1 --verify=0 --bs=1M --iodepth=64 --rw=write \
--group_reporting=1 --iodepth_batch_submit=64 \
--iodepth_batch_complete_max=64 >> $TEST_DIR/fio_output.txt 2> /dev/null
rm $TEST_DIR\/write_throughput*
echo -e "${RED}END Write Throughput${RESET}"
echo "END Write Throughput" >>$TEST_DIR/fio_output.txt
echo ""
echo -e "${GREEN}BEGIN Write IOPS (2/4)${RESET}"
echo "BEGIN Write IOPS (2/4)" >>$TEST_DIR/fio_output.txt
fio --name=write_iops --directory=$TEST_DIR --size=$FILE_SIZE\G \
--time_based --runtime=60s --ramp_time=2s --ioengine=libaio --direct=1 \
--verify=0 --bs=4K --iodepth=256 --rw=randwrite --group_reporting=1 \
--iodepth_batch_submit=256 --iodepth_batch_complete_max=256 >> $TEST_DIR/fio_output.txt 2> /dev/null
rm $TEST_DIR\/write_iops*
echo -e "${RED}END Write IOPS ${RESET}"
echo "END Write IOPS" >>$TEST_DIR/fio_output.txt
echo ""
echo -e "${GREEN}BEGIN Read Throughput (3/4)${RESET}"
echo "BEGIN Read Throughput (3/4)" >>$TEST_DIR/fio_output.txt
fio --name=read_throughput --directory=$TEST_DIR --numjobs=16 \
--size=$FILE_SIZE\G --time_based --runtime=60s --ramp_time=2s --ioengine=libaio \
--direct=1 --verify=0 --bs=1M --iodepth=64 --rw=read \
--group_reporting=1 \
--iodepth_batch_submit=64 --iodepth_batch_complete_max=64 >> $TEST_DIR/fio_output.txt 2> /dev/null
rm $TEST_DIR\/read_throughput*
echo -e "${RED}END Read Throughput${RESET}"
echo "END Read Throughput" >>$TEST_DIR/fio_output.txt
echo ""
echo -e "${GREEN}BEGIN Read IOPS (4/4)${RESET}"
echo "BEGIN Read IOPS (4/4)" >>$TEST_DIR/fio_output.txt
fio --name=read_iops --directory=$TEST_DIR --size=$FILE_SIZE\G \
--time_based --runtime=60s --ramp_time=2s --ioengine=libaio --direct=1 \
--verify=0 --bs=4K --iodepth=256 --rw=randread --group_reporting=1 \
--iodepth_batch_submit=256 --iodepth_batch_complete_max=256 >> $TEST_DIR/fio_output.txt 2> /dev/null
rm $TEST_DIR\/read_iops*
echo -e "${RED}END Read IOPS${RESET}"
echo "END Read IOPS" >>$TEST_DIR/fio_output.txt
echo ""
echo -e "${GREEN}We're all done!"
echo -e "${GREEN}We're all done!" >>$TEST_DIR/fio_output.txt
echo -e "Test results have been output to "$TEST_DIR"/fio_output.txt${RESET}"