DIY IO Benchmarking

October 11, 2009

Here’s a totally unscientific and potentially extremely flawed tool for measuring IO performance. It grew out of the frustration of not being able to at least roughly estimate and compare the performance of different disks when dealing with different file sizes. Most benchmarking tools out there seem to focus on large files, but for mail and iCal servers this information is basically useless.

So I hacked together this thing in like 10 minutes. A basic usage example would be:

$ ./smalltest.sh 1000 20 /tmp
#### WRITE TEST ####

real    0m2.452s
user    0m0.530s
sys 0m1.649s
#### READ TEST ####

real    0m1.799s
user    0m0.461s
sys 0m1.302s

That created 1000 ten kilobyte (twenty 512 byte blocks) files into a folder under /tmp on my MacBook Pro. The scrips itself would make a great “Bash 101” example for first graders:

  #!/usr/bin/env bash
  # smalltest.sh

  USAGE="$(basename $0) HowManyFiles BlockSize Destination"

  if [[ $# -lt 3 ]]; then
    echo $USAGE 2>&1
    exit 1
  fi

  tmpdir="/$3/$(date +%s)"
  mkdir $tmpdir

  echo "#### WRITE TEST ####"

  time (
    for (( i = 0; i < $1; i++ )); do
      dd if=/dev/zero of="$tmpdir/$i" count=$2 bs=512 > /dev/null 2>&1
    done
  )


  echo "#### READ TEST ####"

  time (
    for f in $tmpdir/*; do
      cat $f > /dev/null
    done
  )

  rm -r $tmpdir