Skip to content

Instantly share code, notes, and snippets.

@remyd1
Last active April 7, 2016 08:11
Show Gist options
  • Save remyd1/7134789e97014e09ff33cba76f1863e1 to your computer and use it in GitHub Desktop.
Save remyd1/7134789e97014e09ff33cba76f1863e1 to your computer and use it in GitHub Desktop.
disks benchmarks with hdparm, dd, iozone
#!/bin/bash
set -e
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root"
exit
fi
echo "The device you want to test needs to be mounted. The script will write a 100MBytes and 1Gb file. It may take a long time depending mainly on your hardware..."
echo "Enter the device to test (eg: /dev/sda):"
read device
mountpoint=`mount |grep -m 1 $device | cut -d" " -f3`
echo "Moving to $mountpoint"
echo "checking iozone3 package"
PKG_MANAGER=$( command -v yum || command -v apt-get ) || echo "Neither yum nor apt-get found"
if [ "$PKG_MANAGER" == "/usr/bin/yum" ]; then
# need epel repository
iozone="--enablerepo=epel iozone"
elif [ "$PKG_MANAGER" == "/usr/bin/apt-get" ]; then
# need non-free repository
# echo "deb http://ftp.fr.debian.org/debian `lsb_release -c |awk '{print $2}'` main non-free" > /etc/apt/sources.list.d/nonfree.list
# apt-get update
iozone="iozone3"
fi
$PKG_MANAGER install $iozone
basenamedev=`basename $device`
RESULT_DIR="~/disk-results-benchs"
mkdir -p $RESULT_DIR
Hdparm_func ()
{
echo "########################################################"
echo "Retrieve informations on specific disk"
hdparm -I $device > $RESULT_DIR"/"$basenamedev"_hdparm_info.out"
echo "########################################################"
echo "########################################################"
echo "Test disk $device with hdparm"
sync ; echo 3 > /proc/sys/vm/drop_caches ; /usr/bin/time hdparm -tT $device > $RESULT_DIR/$basenamedev"_hdparm.out" 2>&1
echo "Writing results to "$RESULT_DIR"/"$basenamedev"_hdparm.out"
}
HundredMBsize_eightKchunks ()
{
echo "The write tests will write a 100MBytes file with 8KBytes chunks"
echo "########################################################"
echo "Test read/write on $device with iozone with 2<->10 threads"
iozone -R -b "$RESULT_DIR"/results_`hostname`_"$basenamedev"_8k100M.ods -r 8k -s 100m -l 2 -u 10 $mountpoint
echo "Writing results to "$RESULT_DIR"/results_`hostname`_"$basenamedev"_8k100M.ods"
echo "########################################################"
echo "Write test on $device with dd (100Mb in 8Kb chunks)"
# test with dd. Drop the cache before.
sync ; echo 3 > /proc/sys/vm/drop_caches ; /usr/bin/time dd if=/dev/zero of=$mountpoint/dd.tmp bs=8K count=12207 conv=fsync > "$RESULT_DIR"/$basenamedev"_dd8k100M.out" 2>&1
echo "Writing results to "$RESULT_DIR"/"$basenamedev"_dd8k100M.out"
rm -f dd.tmp
}
OneGBsize_oneBlock ()
{
echo "The write tests will write a 1GBytes file with only one big block."
echo "########################################################"
echo "Test read/write on $device with iozone on 1 thread."
iozone -R -b "$RESULT_DIR"/results_`hostname`_"$basenamedev".ods -s 1g $mountpoint
echo "Writing results to "$RESULT_DIR"/results_`hostname`_"$basenamedev"_1g.ods"
echo "########################################################"
echo "Write test on $device with dd (1Gb, count=1)."
# test with dd. Drop the cache before.
sync ; echo 3 > /proc/sys/vm/drop_caches ; /usr/bin/time dd if=/dev/zero of=$mountpoint/dd.tmp bs=1GB count=1 conv=fsync > "$RESULT_DIR"/$basenamedev"_dd1g.out" 2>&1
echo "Writing results to "$RESULT_DIR"/"$basenamedev"_dd1g.out"
rm -f dd.tmp
}
Hdparm_func
OneGBsize_oneBlock
HundredMBsize_eightKchunks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment