Skip to content

Instantly share code, notes, and snippets.

@mrlesmithjr
Last active September 1, 2016 18:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrlesmithjr/6c00f02018ddc672aaa3abd12f222b1b to your computer and use it in GitHub Desktop.
Save mrlesmithjr/6c00f02018ddc672aaa3abd12f222b1b to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Larry Smith Jr.
# mrlesmithjr@gmail.com
# @mrlesmithjr
# http://everythingshouldbevirtual.com
#
# Variables
DD_BS="512 1024 2048 4096 8192 16384 1048576" #define blocksizes to test in Bytes [512=512b, 1024=1k, 2048=2k, 1048576=1MB]
DD_CONV_OPTIONS="fdatasync,notrunc" #define the output options to pass to dd when creating TESTFILE
DD_DEV_TEST="/dev/zero" #define [/dev/zero, /dev/random, /dev/urandom]
DEV_MOUNTS="/" #define the mountpoints to test in which your DEVS are mounted [/ /mnt/disk2 /mnt/disk3]
DEVS="/dev/sda" #define the disk(s) device name(s) to test [/dev/sda /dev/sdb /dev/sdc]
LOOP_COUNT="1" #define the number of times to run each test...generally 4-5 times would be good
TESTFILE="TESTFILE" #define location and filename to create for testing...ensure you are testing on the correct /dev
TESTFILE_SIZE="1073741824" #define size in Bytes [1GB=1073741824]
#
#
#
# Install pre-reqs
if [ -f /etc/debian_version ]; then
apt-get -y install pv hdparm
fi
if [ -f /etc/redhat-release ]; then
codename="$(gawk -F= '/^NAME/{print $2}' /etc/os-release)"
if [[ $codename != "Fedora" ]]; then
yum -y install epel-release
yum -y install pv hdparm
fi
if [[ $codename == "Fedora" ]]; then
dnf -y install pv hdparm
fi
fi
clear
#
echo "testing sequential reads"
echo "========================"
for i in {1..$LOOP_COUNT}
do
for DEV in $DEVS
do
hdparm -Tt $DEV
done
done
echo "testing read/write speeds"
echo "========================="
echo ""
for i in {1..$LOOP_COUNT}
do
for MOUNT in $DEV_MOUNTS
do
for BLOCK_SIZE in $DD_BS
do
DD_COUNT=$(($TESTFILE_SIZE / $BLOCK_SIZE))
PV_SIZE=$(($TESTFILE_SIZE / 1024 ))k
if [ $DD_COUNT -le 0 ]; then
break
fi
echo "testing write speeds on $MOUNT using (bs=$BLOCK_SIZE count=$DD_COUNT size=$PV_SIZE)"
echo "==================================================================================="
echo ""
dd if=$DD_DEV_TEST bs=$BLOCK_SIZE count=$DD_COUNT | pv -s $PV_SIZE | dd of=$MOUNT/$TESTFILE conv=$DD_CONV_OPTIONS
echo ""
echo "clearing buffer-cache"
echo "====================="
echo ""
sync
echo 3 > /proc/sys/vm/drop_caches
echo ""
echo "testing read speeds on $MOUNT using (bs=$BLOCK_SIZE count=$DD_COUNT size=$PV_SIZE)"
echo "=================================================================================="
echo ""
dd if=$MOUNT/$TESTFILE bs=$BLOCK_SIZE count=$DD_COUNT | pv -s $PV_SIZE | dd of=/dev/null
echo ""
echo "testing buffer-cache speeds on $MOUNT using (bs=$BLOCK_SIZE count=$DD_COUNT size=$PV_SIZE)"
echo "=========================================================================================="
echo ""
dd if=$MOUNT/$TESTFILE bs=$BLOCK_SIZE count=$DD_COUNT | pv -s $PV_SIZE | dd of=/dev/null
echo ""
done
echo ""
echo "Cleaning up"
echo ""
rm $MOUNT/$TESTFILE
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment