|
| 1 | +#! /usr/bin/env bash |
| 2 | +## |
| 3 | +# storage_bench.sh, simple bash script to roughly benchmark a mounted storage system. |
| 4 | +# Copyright (C) 2016 ASTRON (Netherlands Foundation for Research in Astronomy) |
| 5 | +# P.O.Box 2, 7990 AA Dwingeloo, The Netherlads, [email protected] |
| 6 | +# |
| 7 | +# This program is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU General Public License as published by |
| 9 | +# the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# This program is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License |
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | +## |
| 20 | + |
| 21 | + |
| 22 | +cd /dev/shm # fastest available device |
| 23 | +dd if=/dev/urandom bs=1G count=1 of=basefile # large file to make sure it won't be compressible. To save time, we will use this as a base |
| 24 | + # urandom is way too slow to use directly for this purpose |
| 25 | + |
| 26 | +for i in `seq 30` # 1G file takes 1 minute. To save us from waiting for half an hour, we just copy this one a few times over |
| 27 | +do # We assume the OS is not extremely smart and will not notice the repetition (have never seen that happen) |
| 28 | +cat basefile >> largefile |
| 29 | +done |
| 30 | + |
| 31 | +# Going to use some stuff from Tomi Salminen: |
| 32 | +# https://github.com/tlsalmin/vlbi-streamer/blob/master/scripts/test_volumespeeds |
| 33 | + |
| 34 | +CONVFLAGS=fdatasync |
| 35 | +FLAGS=direct |
| 36 | +BLOCK_SIZE=65536 # Used the scripts from https://github.com/tdg5/blog/tree/master/_includes/scripts to find that this is more |
| 37 | + # or less an optimum for reading and writing on all devices on the specific system I used this on. |
| 38 | + # I'd love to put a copy of those in my repo but since they aren't licensed, I can't. |
| 39 | + |
| 40 | +MBSIZE=$(ls -l --block-size=M /dev/shm/largefile | awk '{print $5}' | sed -e 's/M//g') # Not a mathematician at heart and hey, if they allow "M", better use it! |
| 41 | + # And I always confuse the SI vs compute prefixes anyway |
| 42 | +function wtest { # read from shm, write to device |
| 43 | + dd if=/dev/shm/largefile of=$1/testfile bs=${BLOCK_SIZE} conv=$CONVFLAGS oflag=$FLAGS &> /dev/null |
| 44 | +} |
| 45 | +function rtest { # read from device, write to null |
| 46 | + dd if=$1/testfile of=/dev/null bs=${BLOCK_SIZE} iflag=$FLAGS &> /dev/null |
| 47 | +} |
| 48 | +function rwtest { # read from device, write to device |
| 49 | + dd if=$1/testfile bs=${BLOCK_SIZE} of=$1/testfile2 conv=$CONVFLAGS oflag=$FLAGS iflag=$FLAGS &> /dev/null |
| 50 | +} |
| 51 | + |
| 52 | +for DEVICE_FOLDER in $* |
| 53 | +do |
| 54 | +echo "Write to ${DEVICE_FOLDER}" |
| 55 | +START=$(date +%s.%N) # Current time at rediculous precision |
| 56 | + wtest $DEVICE_FOLDER |
| 57 | +END=$(date +%s.%N) |
| 58 | +WSPEED=$(echo "$MBSIZE/($END - $START)" | bc -l) |
| 59 | + |
| 60 | +echo "Read from ${DEVICE_FOLDER}" |
| 61 | +START=$(date +%s.%N) |
| 62 | + rtest $DEVICE_FOLDER |
| 63 | +END=$(date +%s.%N) |
| 64 | +RSPEED=$(echo "$MBSIZE/($END - $START)" | bc -l) |
| 65 | + |
| 66 | +echo "Read from & write to ${DEVICE_FOLDER}" |
| 67 | +START=$(date +%s.%N) |
| 68 | + rwtest $DEVICE_FOLDER |
| 69 | +END=$(date +%s.%N) |
| 70 | +RWSPEED=$(echo "$MBSIZE/($END - $START)" | bc -l) |
| 71 | + |
| 72 | +echo "${DEVICE_FOLDER}:" |
| 73 | +echo "READ: ${RSPEED}MB/s" |
| 74 | +echo "WRITE: ${WSPEED}MB/s" |
| 75 | +echo "R+W: ${RWSPEED}MB/s" |
| 76 | +rm $DEVICE_FOLDER/testfile $DEVICE_FOLDER/testfile2 |
| 77 | +done |
| 78 | +rm /dev/shm/largefile /dev/shm/basefile |
0 commit comments