Advertisement
peetaur

test script - mdadm ext4 vs btrfs, fio ssd-test 4k and 256k

Oct 31st, 2012
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.71 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Author: Peter Maloney
  4. # License: GPLv2
  5. #
  6. # A benchmark script for testing many different layouts with 4 disks.
  7. # It is a work in progress.
  8. # Much of it is hardcoded... eg. 4 disks
  9. # It doesn't test different io schedulers.
  10. #
  11. # To use:
  12. #     cd to the directory where you want the logs:
  13. #         mkdir ~/raidtest1/
  14. #         cd ~/raidtest1/
  15. #     then run the script in test mode:
  16. #         ~/path/to/raidtest.bash test
  17. #     then run the script in either results or csv mode:
  18. #         ~/path/to/raidtest.bash results
  19. #         ~/path/to/raidtest.bash csv
  20.  
  21. testd1=/dev/sda2
  22. testd2=/dev/sdb2
  23. testd3=/dev/sdc2
  24. testd4=/dev/sdd2
  25. testmd=/dev/md127
  26.  
  27. btrfspath="/home/peter/projects/btrfs-progs"
  28.  
  29. fio=/home/peter/archive/software/fio/fio-2.0.10/fio
  30.  
  31. testConfigFile4k="/home/peter/archive/software/fio/fio-2.0.10/examples/ssd-test-short"
  32. testConfigFile256k="/home/peter/archive/software/fio/fio-2.0.10/examples/ssd-test-short256k"
  33.  
  34. if [ "$#" -lt 1 -o "$#" -gt 2 ]; then
  35.     echo "USAGE: $0 <mode> [configFile]"
  36.     echo "    modes are: test, results, csv"
  37.     echo "    configFile is either: 4k, or 256k (default), or a path to an fio test config file"
  38.     exit 1
  39. fi
  40.  
  41. mode="$1"
  42. testConfigFile="$2"
  43.  
  44. if [ "$mode" = "test" ]; then
  45.     if [ "$testConfigFile" = "4k" ]; then
  46.         testConfigFile="$testConfigFile4k"
  47.     elif [ "$testConfigFile" = "256k" ]; then
  48.         testConfigFile="$testConfigFile256k"
  49.     elif [ -f "$testConfigFile" ]; then
  50.         echo "Using custom config file: $testConfigFile"
  51.     else
  52.         testConfigFile="$testConfigFile256k"
  53.         echo "Using default config file: $testConfigFile"
  54.     fi
  55. fi
  56.  
  57. cleanTest() {
  58.     if mountpoint /mnt/TestDevice >/dev/null; then
  59.         umount /mnt/TestDevice
  60.     fi
  61.     if [ -e "$testmd" ]; then
  62.         mdadm --stop "${testmd}"
  63.         wipefs -a "$testmd"
  64.     fi
  65.     mdadm --zero-superblock "$testd1" 2>/dev/null
  66.     mdadm --zero-superblock "$testd2" 2>/dev/null
  67.     mdadm --zero-superblock "$testd3" 2>/dev/null
  68.     mdadm --zero-superblock "$testd4" 2>/dev/null
  69.     wipefs -a "$testd1" 2>/dev/null
  70.     wipefs -a "$testd2" 2>/dev/null
  71.     wipefs -a "$testd3" 2>/dev/null
  72.     wipefs -a "$testd4" 2>/dev/null
  73.     rmdir /mnt/TestDevice 2>/dev/null
  74. }
  75.  
  76. runTest() {
  77.     fs="$1"
  78.     level="$2"
  79.     disks="$3"
  80.    
  81.     pwd=$(pwd)
  82.     if ! mountpoint /mnt/TestDevice; then
  83.         echo "ERROR: /mnt/TestDevice is not a mountpoint"
  84.         return 1
  85.     fi
  86.    
  87.     cd /mnt/TestDevice
  88.         "$fio" \
  89.         "$testConfigFile" \
  90.         | tee "$pwd/$fs $level $disks".log
  91.  
  92.     # for debugging / verification purposes, just to prove the test was really testing what it should have been
  93.     echo >> "$pwd/$fs $level $disks".log
  94.     mdadm -D "$testmd" >> "$pwd/$fs $level $disks".log
  95.     echo >> "$pwd/$fs $level $disks".log
  96.     btrfs fi show TestDevice >> "$pwd/$fs $level $disks".log
  97.     echo >> "$pwd/$fs $level $disks".log
  98.     mount >> "$pwd/$fs $level $disks".log
  99.    
  100.     rm ssd.test.file
  101.     cd "$pwd"
  102. }
  103.  
  104. setupTest() {
  105.     fs="$1"
  106.     level="$2"
  107.     disks="$3"
  108.    
  109.     devs=
  110.     if [ "$disks" = "1" ]; then
  111.         devs="$testd1"
  112.     elif [ "$disks" = "2" ]; then
  113.         devs="$testd1 $testd2"
  114.     elif [ "$disks" = "3" ]; then
  115.         devs="$testd1 $testd2 $testd3"
  116.     elif [ "$disks" = "4" ]; then
  117.         devs="$testd1 $testd2 $testd3 $testd4"
  118.     fi
  119.    
  120.     if [ "$fs" = "btrfs" ]; then
  121.         if [ "$level" = "raid10-far" ]; then
  122.             echo "skipping test: $fs $level $disks"
  123.             return 1
  124.         fi
  125.         "$btrfspath"/mkfs.btrfs -L TestDevice -m "$level" -d "$level" $devs || return 2
  126.         mkdir /mnt/TestDevice
  127.         mount -o noatime "$testd1" /mnt/TestDevice
  128.     elif [ "$fs" = "mdadm ext4" -a "$level" = "single" ]; then
  129.         mkfs.ext4 -L TestDevice -m 0 "$testd1"
  130.         mkdir /mnt/TestDevice
  131.         mount -o noatime "$testd1" /mnt/TestDevice
  132.     elif [ "$fs" = "mdadm ext4" ]; then
  133.         mlevel=
  134.         mlayout=
  135.         if [ "$level" = "raid10-far" ]; then
  136.             mlevel="--level 10"
  137.             mlayout="--layout f2"
  138.         else
  139.             mlevel="--level ${level:4}"
  140.         fi
  141.        
  142.         # using --metadata=0.90 to stop the interactive "yes no" junk related to booting
  143.         mdadm --create "$testmd" --metadata=0.90 -n "$disks" -x 0 -N "TestDevice" -W $mlevel $mlayout $devs || return 2
  144.         mkfs.ext4 -L TestDevice -m 0 "$testmd"
  145.         mkdir /mnt/TestDevice
  146.         mount -o noatime "$testmd" /mnt/TestDevice
  147.  
  148. # next block obsolete by mdadm -W option        
  149. #        echo -n "Waiting for mdadm sync to complete"
  150. #        while mdadm -D "$testmd" | grep "State.*active.*resyncing" >/dev/null; do
  151. #            echo -n "."
  152. #            sleep 1
  153. #        done
  154.         echo
  155.     else
  156.         echo "ERROR: bad fs: $fs"
  157.         return 1
  158.     fi
  159. }
  160.  
  161. runAllTests() {
  162.     for fs in btrfs "mdadm ext4"; do
  163.         for level in raid0 raid1 raid10 raid10-far single; do
  164.             for disks in {1..4}; do
  165.                 # skip tests that don't make sense
  166.                 if [ "$level" = "raid0" -a "$disks" = 1 ]; then
  167.                     continue
  168.                 elif [ "$level" = "raid1" -a "$disks" != 2 -a '(' "$disks" != 1 -o "$fs" != "btrfs" ')' ]; then
  169.                     # don't test btrfs raid1 with 1 disk
  170.                     # don't test mdadm raid1 with anything except 2 disks
  171.                     continue
  172.                 elif [ "$level" = "raid10-far" -a "$fs" = "btrfs" ]; then
  173.                     continue
  174.                 elif [ "$level" = "raid10" -a "$disks" != 4 ]; then
  175.                     continue
  176.                 elif [ "$level" = "single" -a "$disks" != 1 -a "$fs" != "btrfs" ]; then
  177.                     continue
  178.                 fi
  179.                
  180.                 echo "======================================"
  181.                 echo "next test: $fs $level $disks"
  182.                 echo "======================================"
  183.                 cleanTest
  184.                 setupTest "$fs" "$level" "$disks" \
  185.                     && runTest "$fs" "$level" "$disks"
  186.                 echo
  187.                 echo
  188.             done
  189.         done
  190.     done
  191. }
  192.    
  193. testResults() {
  194.     for t in seq-read rand-read seq-write rand-write; do
  195.         echo "======================================"
  196.         echo "$t"
  197.         echo "======================================"
  198.         grep -E "${t}: \(groupid" -A 1 *.log
  199.     done
  200. }
  201.  
  202. testResultsCsv() {
  203.     #for f in "mdadm ext4 single 4.log"; do
  204.     for f in *.log; do
  205.         #echo "DEBUG: f is $f"
  206.        
  207.         setup=$(echo "$f" | sed -r "s/.log$//")
  208.        
  209.         IFS=$'\n'
  210.         for t in seq-read rand-read seq-write rand-write; do
  211.             for line in $(grep -E "${t}: \(groupid" -A 1 "$f"); do
  212.                 #echo "DEBUG: line is $line"
  213.                
  214.                 first=$(echo "$line" | cut -f1 -d:)
  215.                 if [ "$first" = "seq-read" ]; then
  216.                     test="seq-read"
  217.                 elif [ "$first" = "rand-read" ]; then
  218.                     test="rand-read"
  219.                 elif [ "$first" = "seq-write" ]; then
  220.                     test="seq-write"
  221.                 elif [ "$first" = "rand-write" ]; then
  222.                     test="rand-write"
  223.                 else
  224.                     bw=$(echo "$line" | grep -Eo "bw=[0-9\.GMKB\/s ]+" | cut -f2 -d'=' )
  225.                    
  226.                     bwValue=$(echo "$bw" | grep -Eo "[0-9\.]+")
  227.                     bwUnit=$(echo "$bw" | grep -Eo "[GMKB\/s]+")
  228.                    
  229.                     # convert to KB/s
  230.                     if [ "$bwUnit" = "GB/s" ]; then
  231.                         bw=$(echo "$bwValue * 1000000" | bc)
  232.                     elif [ "$bwUnit" = "MB/s" ]; then
  233.                         bw=$(echo "$bwValue * 1000" | bc)
  234.                     elif [ "$bwUnit" = "B/s" ]; then
  235.                         bw=$(echo "$bwValue / 1000" | bc)
  236.                     elif [ "$bwUnit" = "KB/s" ]; then
  237.                         bw=$bwValue
  238.                     else
  239.                         echo "ERROR: unparsable bw = $bw"
  240.                         bw=$bwValue
  241.                     fi
  242.                    
  243.                     iops=$(echo "$line" | grep -Eo "iops=[0-9]+" | cut -f2 -d'=' )
  244.                 fi
  245.             done
  246.            
  247.             echo "$setup, $test, $bw, $iops"
  248.         done
  249.     done
  250. }
  251.  
  252. if [ "$mode" = "test" ]; then
  253.     runAllTests
  254. elif [ "$mode" = "results" ]; then
  255.     testResults
  256. elif [ "$mode" = "csv" ]; then
  257.     testResultsCsv > results.csv
  258.     grep "seq-read" results.csv > "results.seq-read.csv"
  259.     grep "seq-write" results.csv > "results.seq-write.csv"
  260.     grep "rand-read" results.csv > "results.rand-read.csv"
  261.     grep "rand-write" results.csv > "results.rand-write.csv"
  262. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement