Tool One: ioPS, a python-written script
Usage Example: sudo./iops--num_threads 1--time 2/dev/md1
Source: http://benjamin-schweizer.de/measuring-disk-io-performance.html
Code: HTTP://BENJAMIN-SCHWEIZER.DE/FILES/IOPS/IOPS-2011-02-11
#!/usr/bin/env python## Copyright (c) 2008-2011 Benjamin Schweizer and others.## Permission to use, copy, modify, and/or D Istribute This software for any# purpose with or without fee are hereby granted, provided that the above# copyright notice And this permission notice appear with all copies.## the software are provided "as is" and the AUTHOR disclaims all Warrantie s# with REGARD to the software including all implied warranties of# merchantability and FITNESS. In NO EVENT shall the AUTHOR is liable for# any special, DIRECT, INDIRECT, or consequential damages OR any damages# Whatso Ever resulting from LOSS by, DATA OR profits, WHETHER in an# action of contract, negligence OR other tortious action, Arising out of# or in CONNECTION with the use or performance of this software.### abstract# ~~~~~~~~# Benchmark disk ios## authors# ~~~~~~~# Benjamin Schweizer, http://benjamin-schweizer.de/contact# Uwe menges# John Keith Hohm <john at Hohm Dot net>## changes# ~~~~~~~# 2011-02-10, John: Added Win32 support# 2010-09-13, benjamin:increased num_threads default to + (MAX-NCQ) # 2010-09-01, BENJAMIN:IOCTL cl Eanup, improved FreeBSD support# 2010-08-12, benjamin/uwe:added multi-threading support# 2010-07-22, benjamin:fixed 32bi T IOCTLs on bsd# 2010-07-21, BENJAMIN:FREEBSD/OSX support, switched to ISC license# 2009-09-16, uwe:changed formatting, Fixed last block bug# 2008-10-16, benjamin:initial release## todo# ~~~~#-check/add Netbsd/openbsd mediasize Ioctls#USAG E = "" Copyright (c) 2008-2011 Benjamin Schweizer and Others.usage:iops [-n|--num_threads threads] [-t|--time time] &l T;device> Threads: = number of concurrent IO threads, default 1 time: = time in seconds, default ten device : = Some block device, LIKE/DEV/SDA or \\\\.\\PHYSICALDRIVE0EXAMPLE:IOPS/DEV/SDA iops-n 8-t 2/dev/disk0 "" Impo RT sysimport Arrayimport structimport randomimport timeimport threadingdef mediasize (dev): "" "Report of the media size for A device, platform specific code "" "# Caching Global _mediasizes if not ' _mediasizes ' in Globals (): _mediasizes = {} if dev in _media Sizes:return _mediasizes[dev] mediasize = 0 # bytes If sys.platform = ' Darwin ': # Mac OS X IOCTL fro M sys/disk.h import Fcntl dkiocgetblocksize = 0x40046418 # _ior (' d ', ' uint32_t ') Dkiocgetblockcoun T = 0x40086419 # _ior (' d ', +, uint64_t) fh = open (dev, ' r ') buf = Array.array (' B ', Range (0,4)) # UInt32 R = Fcntl.ioctl (Fh.fileno (), Dkiocgetblocksize, buf, 1) blocksize = Struct.unpack (' I ', buf) [0] buf = AR Ray.array (' B ', Range (0,8)) # UInt64 R = Fcntl.ioctl (Fh.fileno (), Dkiocgetblockcount, buf, 1) Blockcount = s Truct.unpack (' Q ', buf) [0] fh.close () mediasize = Blocksize*blockcount elif sys.platform.startswith (' FreeB SD '): # FreeBSD IOCTL from sys/disk.h import fcntl diocgmediasize = 0x40086481 # _ior (' d ', 129, UINT6 4_t) fh = open (DEV, ' r ') buf = Array.array (' B ', Range (0,8)) # Off_t/int64 R = Fcntl.ioctl (Fh.fileno (), Diocgmediasize, buf , 1) mediasize = struct.unpack (' q ', buf) [0] Fh.close () elif Sys.platform = = ' Win32 ': # Win32 IOCTL From Winioctl.h, requires Pywin32 try:import win32file except Importerror:raise Sys Temexit ("Package pywin32 isn't found, see http://sf.net/projects/pywin32/") Ioctl_disk_get_drive_geometry = 0x0007000 0 dh = win32file. CreateFile (Dev, 0, win32file. File_share_read, None, Win32file. open_existing, 0, None) info = win32file. DeviceIoControl (DH, ioctl_disk_get_drive_geometry, ",") win32file. CloseHandle (DH) (Cyl_lo, Cyl_hi, Media_type, TPS, SPT, bps) = struct.unpack (' 6L ', info) mediasize = ((Cyl_hi <<) + cyl_lo) * TPS * SPT * bps else: # Linux or Compat # Linux 2.6 lseek from fcntl.h seek_set =0 seek_cur=1 seek_end=2 fh = open (DEV, ' R ') Fh.seek (0,seek_end) mediasize = Fh.tell () fh.close () if not mediasize:raise Except Ion ("Cannot determine media size") _mediasizes[dev] = mediasize return mediasizedef Greek (value, precision=0, prefix =none): "" "Return a String representing the IEC or SI suffix of a value" "" # Copyright (c) 1999 Martin Pohl, copied From # http://mail.python.org/pipermail/python-list/1999-December/018519.html if prefix: # use SI (10-based) Units _abbrevs = [(10**15, ' P '), (10**12, ' T '), (10** 9, ' G '), (10** 6 , ' M '), (10** 3, ' K '), (1, ')] Else: # use IEC (2-based) units _ABBR EVS = [(1<<50l, ' Pi '), (1<<40l, ' Ti '), (1<<30l, ' Gi '), (1&L t;<20l, ' Mi '), (1<<10l, ' Ki '), (1, ')] for factor, suffix in _abbrevs: If Value >= FACTor:break if precision = = 0:return "%3.d%s"% (int (value/factor), suffix) else:fmt= "%%% D.%DF%%s "% (4+precision, precision) return FMT% (float (value)/factor, suffix) def iops (Dev, blocksize=512, t=10): "" "Measure input/output operations per second Perform random 512b aligned reads of blocksize bytes on FH for T Seco NDS and print a stats line returns:ios/s "" "FH = open (dev, ' r ') Count = 0 start = Time.time () while Time.time () < Start+t:count + = 1 pos = random.randint (0, mediasize (Dev)-blocksize) # need at least on E Block left Pos &= ~0x1ff # Freebsd8:pos needs 512B sector alignment Fh.seek (pos) Blockdata = Fh.read (blocksize) end = Time.time () t = End-start fh.close () return count/tif __name__ = = ' __main__ ': # Parse CLI t = ten num_threads = + dev = None If Len (SYS.ARGV) < 2:raise systemexit (USAGE) while Sys.argv:arg =Sys.argv.pop (0) if Arg in ['-N ', '--num-threads ']: num_threads = Int (sys.argv.pop (0)) Elif Arg in ['-t ', '--time ']: t = Int (sys.argv.pop (0)) Else:dev = arg # run Benchmark blocksize = Try:print "%s,%SB,%d threads:"% (Dev, Greek (mediasize (Dev), 2, ' Si '), num_threads) _iops = num_t Hreads+1 # Initial Loop while _iops > Num_threads and BlockSize < Mediasize (dev): # threading Boil Erplate threads = [] results = [] def results_wrap (results, func, *__args, * * __KW): "" "Collect return values from func" "" Result = Func (*__args, **__kw) r Esults.append (Result) for I in range (0, num_threads): _t = Threading. Thread (Target=results_wrap, args= (results, ioPS, Dev, blocksize, T,)) _t.start () Threads.app End (_t) for _t in Threads: _t.join () _iops = SUM (results) bandwidth = Int (blocksize*_iops) print "%SB blocks:%6. 1f io/s,%sb/s (%sbit/s) "% (Greek (blocksize), _iops, Greek (bandwidth, 1), Greek (8*bandwidth, 1, ' si ')) BlockSize *= 2 except IOError, (Err_no, err_str): Raise Systemexit (ERR_STR) except Keyboardinterrupt: Print "Caught Ctrl-c, bye." # EOF.
Tool Two: Fio http://www.freecode.com/projects/fio/
Usage is slightly more complex and powerful
Disk Performance measurement