Skip to content

Instantly share code, notes, and snippets.

@tcooper
Created March 7, 2014 18:15
Show Gist options
  • Save tcooper/9416799 to your computer and use it in GitHub Desktop.
Save tcooper/9416799 to your computer and use it in GitHub Desktop.
Script for testing block device(s) using dd
#!/bin/bash
# Script for testing block device(s) using dd
#
# Actual files sizes written may be slightly smaller than the target due to bc's
# default truncation of floating point results.
#
# Read tests use /dev/null as the output device.
#
# MACOSX: (SSD)
# dd if=/dev/zero of=/tmp/test.dat count=100 bs=256k 2>&1 | \
# grep bytes | sed 's,[a-zA-Z()/],,g' | \
# awk '{print $1/$2/1024/1024" MB/s "100/$2" IOPS"}'
# 507.11 MB/s 2028.44 IOPS
#
# dd of=/dev/null if=/tmp/test.dat count=100 bs=256k 2>&1 | \
# grep bytes | sed 's,[a-zA-Z()/],,g' | \
# awk '{print $1/$2/1024/1024" MB/s "100/$2" IOPS"}'
# 4994.01 MB/s 19976 IOPS
# LINUX:
# dd if=/dev/zero of=/tmp/test.dat count=100 bs=256k oflag=direct 2>&1 | \
# grep bytes | sed 's,[a-zA-Z()/\,],,g' | \
# awk '{print $1/$3/1024/1024" MB/s, " 100/$3" IOPS"}'
# 9.06885 MB/s, 36.2754 IOPS
#
# dd if=/tmp/test.dat of=/dev/null count=100 bs=256k iflag=direct 2>&1 | \
# grep bytes | sed 's,[a-zA-Z()/\,],,g' | \
# awk '{print $1/$3/1024/1024" MB/s, " 100/$3" IOPS"}'
# 48.6412 MB/s, 194.565 IOPS
# in_file can/should be a pre-created file for example...
# dd if=/dev/urandom of=/tmp/urandom_file bs=1048560 count=1024
#
# out_file can be a file or a raw device if it's a file then be sure to clean up when
# you are done. Writing to a raw device will destroy any/all data on the device
in_file=$1
out_file=$2
# File sizes to test in KB
fs_array=(64 128 256 512 1024 1792 2048 4096 8192 16384 32768 65535 131070 262140 524280 1048560)
# I/O bytes read/written in a single I/O request in KB
bs_array=(4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65535 131070 262140 524280 1048560)
for fs_idx in {0..15}
#for fs_idx in {0..3}
do
for bs_idx in {0..18}
do
fs=${fs_array[$fs_idx]}
bs=${bs_array[$bs_idx]}
if [ ${bs_array[$bs_idx]} -le ${fs_array[$fs_idx]} ]
then
count=`echo "$fs / $bs" | bc`
w_result=`dd if=${in_file} of=${out_file} count=${count} bs=${bs}k 2>&1 | grep bytes | sed 's,[a-zA-Z()/\,],,g'`
r_result=`dd if=${out_file} of=/dev/null count=${count} bs=${bs}k 2>&1 | grep bytes | sed 's,[a-zA-Z()/\,],,g'`
printf "%10s %10s %s %s\n" "$fs" "$bs" "$w_result" "$r_result"
fi
done
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment