Difference between revisions of "Winter 2009 SYA810 Block Device Benchmark Scripts"

From CDOT Wiki
Jump to: navigation, search
 
(12 intermediate revisions by 8 users not shown)
Line 1: Line 1:
Please post your block device benchmark script here. I'm looking for a wide range of benchmark methodologies, so your script should test in a different way than the other scripts. I will collect these scripts on '''Monday, Jan 26''' and create a master script which runs all of these tests and reports the overall results.
+
Please post your block device benchmark script here. I'm looking for a wide range of benchmark methodologies, so your script should test in a different way than the other scripts.
  
= John Doe (example) =
+
= P. Constantino =
  
  Script or link to script goes here
+
  #!/bin/bash
 +
# This script generate random numbers and seeks to that POSITION on the block device given, reading 1 kb of data at the time.
 +
# The purpose is test the speed of randomly reading 1024(default) blocks of 1KB from the disk.
 +
# A valid input for BLOCK DEVICE could be: /dev/sdb (disk) - /dev/sda9 (partition) - /dev/md8 (RAID) - /dev/mapper/foo/bar (LV).
 +
echo -n "Enter a number of block to read. Enter for default(1024): "
 +
read BLOCKS
 +
if [ "$BLOCKS" = "" ]
 +
then
 +
    BLOCKS=1024
 +
fi
 +
echo -n "Enter a valid block device (dev/): "
 +
read BLOCKDEVICE
 +
SIZE=$(df /dev/$BLOCKDEVICE | awk '{print $3}' | grep -v 'Used')
 +
time -p for ((x=1; x<=$BLOCKS; x++))
 +
do
 +
POSITION=$(( RANDOM % $SIZE + 1))
 +
dd if=/dev/$BLOCKDEVICE of=/dev/null bs=1k count=1 seek=$POSITION
 +
sync
 +
echo 3 >/proc/sys/vm/drop_caches
 +
done
 +
echo "  ^ time to process randomly $BLOCKS blocks of 1KB on /dev/$BLOCKDEVICE."
  
= Gregory Masseau =  
+
= Katherine Masseau =  
 +
[http://matrix.senecac.on.ca/~gjmasseau/DiskTest.py Disk Test Script]
  
"""
+
= Nestor CHAN =
DiskTest.py:
+
[http://matrix.senecac.on.ca/~tnchan/PerformanceTest/ Perfomance Test]
This script tests a disks write/read performance for both block devices and individual files, presenting it's output as an HTML file contaning a table.
 
  
Example invocation:
+
= Mohak Vyas =
sudo python DiskTest.py D="/dev/sda1" F="./x" -readd -writef -readf -d18 O=/mnt/md0/webshare/stuff/out.html
+
[http://zenit.senecac.on.ca/wiki/index.php/Performancescript Performance Test]
  
To (destructively) write test a block device add the '-writed' option.
+
=Varinder Singh=
"""
+
[http://matrix.senecac.on.ca/~vsjhand/storage/python-scripts/ Python Performance Scripts]
  
from sys import stdout
+
Script in Python.Any suggestions would be welcome
verbosity = 2
 
debug    = True
 
if __name__=="__main__":
 
repeat    = 5
 
  
from os    import remove, system
 
from sys    import argv
 
from time  import sleep
 
from timeit import Timer
 
  
def setup(argv):
+
=Kezhong Liang=
"""Takes an argument list argv and returns paraters needed for tests."""
+
#!/bin/bash
depth  = list(set([a[2:] for a in argv if a[0:2] == "-d"]))
+
echo "Start to test ..."
disk    = list(set([a[2:] for a in argv if a[0:2] == "D="]))
+
TIME_WRITE_START=$(date +%s)
scratch = list(set([a[2:] for a in argv if a[0:2] == "F="]))
+
dd if=/dev/zero of=test bs=1024 count=1000000
outf    = list(set([a[2:] for a in argv if a[0:2] == "O="]))
+
sync
tests  = list(set([a[1:] for a in argv if a[1:] in ["readf","readd","writef","writed"]]))
+
TIME_WRITE_END=$(date +%s)
errors = list(set([a for a in argv if a not in (["-d"+x for x in depth]+["D="+x for x in disk]+["F="+x for x in scratch]+["-"+x for x in tests]+["O="+x for x in outf]+[argv[0]])]))
+
echo 3 > /proc/sys/vm/drop_caches
if errors or (not(len(disk)==1)) or (not(len(scratch)==1)) or (not(len(depth))==1) or (not(len(outf)) == 1):
+
sync
print "USAGE -- "+argv[0]+" D=<disk> F=<scratch file> O=<output> -d<depth> [-readd] [-readf] [-writed] [-writef]"
+
  TIME_READ_START=$(date +%s)
exit(1)
+
dd if=test of=/dev/null bs=1024 count=1000000
if ("writed" in tests):
+
TIME_READ_END=$(date +%s)
system('clear')
+
rm test
print ("WARNING!!! "*7)+"\n\nYou have selected the 'write to disk' test.\nThis test will DESTROY any file system on the device selected (if it is a partition), possibly multiple filesystems if it is an entire disk. \n\nPLEASE DOUBLE CHECK TO ENSURE NO IMPORTANT DATA IS ON THIS DISK PRIOR TO PROCEEDING!\n\nTo proceed with the test, please enter the name of the device whose contents you are about to destroy.\n\n(The test will be aborted if input does not match the disk specified previously.\n\nDevice:",
+
echo "--------------------------------------------------------"
if (not (raw_input() == disk[0])):
+
TIME_WRITE_USED=$(($TIME_WRITE_END - $TIME_WRITE_START))
print "\nAborting.\n\n"
+
echo -n "The write disk performance: "
exit(1)
+
echo -n $((1024 / $TIME_WRITE_USED))
else:
+
echo " MB/sec"
tests.remove("writed")
+
TIME_READ_USED=$(($TIME_READ_END - $TIME_READ_START))
tests.append("writed")
+
echo -n "The read disk performance: "
if ("writef" in tests):
+
echo -n $((1024 / $TIME_READ_USED))
tests.remove("writef")
+
echo " MB/sec"
tests = ["writef"]+tests
 
return [disk,scratch,outf,tests,depth]
 
  
def time(p):
+
== Milton Paiva Neto ==
"""Runs a test p, returning the time in seconds it took."""
 
print " - time(%r)\n"%(p,) if debug else "",
 
f,d,s,sf  = p
 
importstr = "from "+"".join(argv[0].split(".")[0:-1])+" import "+", ".join(tests)
 
teststr  = stringifyparams(p)
 
timer    = Timer(teststr,importstr)
 
print " - timer = Timer('%s','%s')\n"%(teststr,importstr) if debug else "",
 
stdout.write("\nTest: "+teststr if (verbosity==1) else "")
 
time      = timer.timeit(repeat)
 
print " - time = %s\n"%time if debug else "",
 
stdout.write("Time: "+("%.3lf"%time)+" seconds.\n" if (verbosity==1) else "")
 
sleep(0.025)
 
return (f,d,s,sf,time)
 
  
def stringifyparams(p):
+
#!/bin/bash
"""Stringifies a set of test parameters p."""
+
#
print " - stringifyparams(%r)\n"%(p,) if debug else "",
+
# Script first written by Nestor Chan - Bossanesta and modified by Milton Paiva Neto <milton.paiva@gmail.com>
func,disk,size,scratchfile = p
+
# Create 10 files with one with 10 GBs fully of zeros
return "".join([func,"('",disk,"',",("%s"%size),",'",scratchf,"')"])
+
 +
time -p (for ((x=1; x<=10; x++))
 +
do
 +
        dd if=/dev/zero of=fakefile$x bs=1G count=10;
 +
done
 +
sync
 +
)
  
def dropextraneous(rs):
+
= LINKS =
"""Takes a tuple rs and drops uneeded fields."""
+
[http://linux-raid.osdl.org/index.php/Performance Linux Raid Performance]
print " - dropextraneous(%r)\n"%(rs,) if debug else "",
 
f,d,s,sf,t = rs
 
return [f,s,t]
 
 
 
def group(inp):
 
"""Takes a list of lists inp, returning a list of lists grouped by the first element, i.e.:
 
[['a',1,2],['a',2,3],['b',4,5],['b',6,7],['c',3,3]] => [['a', [[1, 2], [2, 3]]], ['b', [[4, 5], [6, 7]]], ['c', [[3, 3]]]]
 
"""
 
print " - group(%r)\n"%inp if debug else "",
 
return __group(sorted(inp),[],[],"")
 
def __group(inp,buf,out,seek):
 
print " - group(%r,%r,%r,'%r')\n"%(inp,out,buf,seek) if debug else "",
 
if (not (inp==[])):
 
inph  = inp[0]
 
inpt  = inp[1:]
 
inphh = inph[0]
 
inpht = inph[1:]
 
seek  = inphh if (seek=="") else seek
 
return out+[[seek,buf]] if (inp==[]) else __group(inpt,buf+[inpht],out,seek) if (seek==inphh) else __group(inpt,[inpht],out+[[seek,buf]],inphh)
 
 
 
def preformat(d):
 
"""Adjusts the values returned by the test loop (d) into something suitable for table."""
 
left  = "<table border=1><tr><td>Bytes</td><td>Test</td></tr></table>"
 
right  = "<table border=1><tr><td>Test</td><td>Bytes</td></tr></table>"
 
colns  = (lambda d: [""]+[("<b>%s</b>"%x[0]) for x in d[0][1:][0]]+[""])(d)
 
rowns  = (lambda d: [("<b>%s</b>"%x[0]) for x in d])(d)
 
fdata  = (lambda d: [["%.3lf s"%x[1] for x in x[1]] for x in d])(d)
 
lol    = map(list,zip(*[colns]+[[rowns[x]]+fdata[x]+[rowns[x]] for x in range(0,len(rowns))]+[colns]))
 
height = (lambda x:len(x)-1)(lol)
 
width  = (lambda x:len(x[0])-1)(lol)
 
lol[0]    [0]    = left
 
lol[height][0]    = left
 
lol[0]    [width] = right
 
lol[height][width] = right
 
return lol
 
 
 
def table(title,lol):
 
"""Takes a list of lists lol and a title title, returning as a string an HTML page titled title containing the contents of lol in a table."""
 
print "table(%r)\n"%lol if debug else "",
 
return "".join(["".join(x) for x in [["<html>\n<center><table><tr><td><center><h3>%s</h3></center></td></tr><tr><td><table border=1>"%title]]+[["\n    <tr>"]+["\n      <td>%s</td>"%w for w in l]+["\n    </tr>"] for l in lol]+[["\n  </table></td></tr></table></center>\n</html>"]]])
 
 
 
settings  =    setup(argv)
 
disks    =    settings[0]
 
scratchfs =    settings[1]
 
outputf  =    settings[2][0]
 
tests    = settings[3]
 
depth   = int(settings[4][0])
 
 
 
testparams = [(test,disk,size,scratchf)
 
for test    in tests
 
for size    in [siz*1024 for siz in [1<<(x-1) for x in range(1,depth)]]
 
for scratchf in scratchfs
 
for disk    in disks
 
for depth    in [depth]]
 
 
 
OUTFILE = open(outputf,"w")
 
OUTFILE.write(table("Disk Benchmark Results",preformat(group(map((lambda p:dropextraneous(time(p))),testparams)))))
 
OUTFILE.flush()
 
OUTFILE.close()
 
 
 
print "\nDone. Output is in: "+outputf+"."
 
else:
 
from os    import SEEK_END
 
from random import randint
 
 
 
def donefile(FILE,tag):
 
"""Close a file."""
 
FILE.flush()
 
print " - donefile(FILE) <-[ %s ]\n"%tag if debug else "",
 
print ' - FILE.close()\n' if debug else "",
 
FILE.close()
 
stdout.write("done.\n" if (verbosity==2) else ""),
 
return True
 
 
 
def writef(disk,size,scratchf):
 
"""Do a file write test."""
 
print " - writef('%s',%d,'%s')\n"%(disk,size,scratchf) if debug else "",
 
randomseek(disk)
 
stdout.write("(D) Writing "+("%s"%size)+" bytes to "+scratchf+"...\n" if (verbosity==2) else ""),
 
FILE = open(scratchf,"w")
 
print ' - FILE.write("xxx"...)\n' if debug else "",
 
FILE.write((lambda x: "".join(["x" for x in range(1,x)]))(size))
 
donefile(FILE,"writef")
 
return True
 
 
 
def writed(disk,size,scratchf):
 
"""Do a disk write test."""
 
print " - writed('%s',%d,'%s')\n"%(disk,size,scratchf) if debug else "",
 
return writef(disk,size,disk)
 
 
 
def readf(disk,size,scratchf):
 
"""Do a file read test."""
 
print " - readf('%s',%d,'%s')\n"%(disk,size,scratchf) if debug else "",
 
randomseek(disk)
 
print ' - FILE = open(%s),"r"\n'%disk if debug else "",
 
FILE = open(scratchf,"r")
 
FILE.seek(0,0)
 
stdout.write("(D) Reading "+("%s"%size)+" bytes from "+scratchf+"...\n" if (verbosity==2) else "")
 
print ' - FILE.read()\n' if debug else "",
 
FILE.read(size) if (size < 4194304) else [FILE.read(4194304) for x in range(0,size/4194304)]
 
donefile(FILE,"readf")
 
return True
 
 
 
def readd(disk,size,scratchf):
 
"""Do a file read test."""
 
print " - readd('%s',%d,'%s')\n"%(disk,size,scratchf) if debug else "",
 
return readf(disk,size,disk)
 
 
 
def randomseek(disk):
 
"""Seek the disk head to a random position."""
 
print " - randomseek('%s')\n"%disk if debug else "",
 
jumploc = randint(0,disksize(disk))
 
stdout.write("Randomizing head position by seeking byte "+("%s"%jumploc)+" of "+disk+"...\n" if (verbosity==2) else "")
 
print ' - FILE = open(%s),"r"\n'%disk if debug else "",
 
FILE    = open(disk,"r")
 
FILE.seek(jumploc)
 
donefile(FILE,"randomseek")
 
return True
 
 
 
def disksize(disk):
 
"""Get the size of a disk."""
 
print " - disksize('%s')\n"%disk    if debug else "",
 
print ' - FILE = open(%s),"r"\n'%disk if debug else "",
 
FILE = open(disk,"r")
 
FILE.seek(0,SEEK_END)
 
l    = FILE.tell()
 
print " - FILE.close()\n" if debug else "",
 
FILE.close()
 
return l
 
 
 
def writef(disk,size,scratchf):
 
"""Do a file write test."""
 
print " - writef('%s',%d,'%s')\n"%(disk,size,scratchf) if debug else "",
 
randomseek(disk)
 
stdout.write("(D) Writing "+("%s"%size)+" bytes to "+scratchf+"...\n" if (verbosity==2) else ""),
 
FILE = open(scratchf,"w")
 
print ' - FILE.write(<%d>)\n'%size if debug else "",
 
[FILE.write('\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa') for x in range(0,size/64)]
 
donefile(FILE,"writef")
 
return True
 

Latest revision as of 23:39, 16 July 2012

Please post your block device benchmark script here. I'm looking for a wide range of benchmark methodologies, so your script should test in a different way than the other scripts.

P. Constantino

#!/bin/bash
# This script generate random numbers and seeks to that POSITION on the block device given, reading 1 kb of data at the time. 
# The purpose is test the speed of randomly reading 1024(default) blocks of 1KB from the disk.
# A valid input for BLOCK DEVICE could be: /dev/sdb (disk) - /dev/sda9 (partition) - /dev/md8 (RAID) - /dev/mapper/foo/bar (LV).
echo -n "Enter a number of block to read. Enter for default(1024): "
read BLOCKS 
if [ "$BLOCKS" = "" ]
then
   BLOCKS=1024
fi
echo -n "Enter a valid block device (dev/): "
read BLOCKDEVICE
SIZE=$(df /dev/$BLOCKDEVICE | awk '{print $3}' | grep -v 'Used')
time -p for ((x=1; x<=$BLOCKS; x++))
	do 
		POSITION=$(( RANDOM % $SIZE + 1))
		dd if=/dev/$BLOCKDEVICE of=/dev/null bs=1k count=1 seek=$POSITION
		sync
		echo 3 >/proc/sys/vm/drop_caches
	done	
echo "  ^ time to process randomly $BLOCKS blocks of 1KB on /dev/$BLOCKDEVICE."

Katherine Masseau

Disk Test Script

Nestor CHAN

Perfomance Test

Mohak Vyas

Performance Test

Varinder Singh

Python Performance Scripts

Script in Python.Any suggestions would be welcome


Kezhong Liang

#!/bin/bash
echo "Start to test ..."
TIME_WRITE_START=$(date +%s)
dd if=/dev/zero of=test bs=1024 count=1000000
sync
TIME_WRITE_END=$(date +%s)
echo 3 > /proc/sys/vm/drop_caches
sync
TIME_READ_START=$(date +%s)
dd if=test of=/dev/null bs=1024 count=1000000
TIME_READ_END=$(date +%s)
rm test
echo "--------------------------------------------------------"
TIME_WRITE_USED=$(($TIME_WRITE_END - $TIME_WRITE_START))
echo -n "The write disk performance: "
echo -n $((1024 / $TIME_WRITE_USED))
echo " MB/sec"
TIME_READ_USED=$(($TIME_READ_END - $TIME_READ_START))
echo -n "The read disk performance: "
echo -n $((1024 / $TIME_READ_USED))
echo " MB/sec"

Milton Paiva Neto

#!/bin/bash
#
# Script first written by Nestor Chan - Bossanesta and modified by Milton Paiva Neto <milton.paiva@gmail.com>
# Create 10 files with one with 10 GBs fully of zeros

time -p (for ((x=1; x<=10; x++))
do
       dd if=/dev/zero of=fakefile$x bs=1G count=10; 
done
sync
)

LINKS

Linux Raid Performance