Skip to content

Instantly share code, notes, and snippets.

@gxfxyz
Created October 1, 2018 18:16
Show Gist options
  • Save gxfxyz/0d81429fc48a82ef6c2402b178a82566 to your computer and use it in GitHub Desktop.
Save gxfxyz/0d81429fc48a82ef6c2402b178a82566 to your computer and use it in GitHub Desktop.
A simple script to test Synology NAS disk speed with hdparm, dd and fio
#!/usr/bin/env bash
# =======================================================================================
#
# A simple script to test Synology NAS disk speed with hdparm, dd and fio.
#
# How to use:
#
# 1. Save synology_disk_benchmark.sh and xfio.conf to your Synology NAS
# 2. Make it executable: chmod +x synology_disk_benchmark.sh
# 3. Run: sudo ./synology_disk_benchmark.sh <test_name>
# 4. A report file <test_name>.md will be created
#
# =======================================================================================
filename=`echo "$@" | tr " " _`
filename="${filename,,}".md
volume=`dirname "$PWD"`
device=`df $volume | tail -1 | awk '{ print $1 }'`
echo $@
echo $@ > $filename
#########################################################################################
exec () {
echo; echo ---; echo
echo "$1"
echo
echo --- >> $filename
echo '```bash' >> $filename
echo "$1" >> $filename
echo '```' >> $filename
echo '```' >> $filename
eval "$1" 2>&1 | tee -a $filename
echo '```' >> $filename
}
#########################################################################################
#########################################################################################
read -r -d '' cmd << EOM
sudo hdparm -Tt $device
EOM
exec "$cmd"
#########################################################################################
read -r -d '' cmd << EOM
# create a 1 GiB test file with random data (it can take minutes)
head -c 1G </dev/urandom >test
# clear cache
sync; echo 3 | sudo tee /proc/sys/vm/drop_caches > /dev/null
# read from test file, read 1 MiB each time, read 1024 times, total read 1 GiB
dd if=test of=/dev/null bs=1M count=1024
EOM
exec "$cmd"
#########################################################################################
read -r -d '' cmd << EOM
# write 0 to test file, write 1 GiB each time, write 2 times, total write 2 GiB
dd if=/dev/zero of=test bs=1G count=2 oflag=dsync
EOM
exec "$cmd"
#########################################################################################
read -r -d '' cmd << EOM
# write 0 to test file, write 128 MiB each time, write 8 times, total write 1 GiB
dd if=/dev/zero of=test bs=128M count=8 oflag=dsync
EOM
exec "$cmd"
#########################################################################################
read -r -d '' cmd << EOM
# write 0 to test file, write 1 MiB each time, write 1024 times, total write 1 GiB
dd if=/dev/zero of=test bs=1M count=1024 oflag=dsync
EOM
exec "$cmd"
#########################################################################################
read -r -d '' cmd << EOM
# write 0 to test file, write 128 KiB each time, write 1024 times, total write 128 MiB
dd if=/dev/zero of=test bs=128k count=1024 oflag=dsync
EOM
exec "$cmd"
#########################################################################################
read -r -d '' cmd << EOM
# write 0 to test file, write 4 KiB each time, write 1024 times, total write 4 MiB
dd if=/dev/zero of=test bs=4k count=1024 oflag=dsync
EOM
exec "$cmd"
#########################################################################################
read -r -d '' cmd << EOM
# write 0 to test file, write 512 bytes each time, write 1024 times, total write 512 KiB
dd if=/dev/zero of=test bs=512 count=1024 oflag=dsync
EOM
exec "$cmd"
#########################################################################################
read -r -d '' cmd << EOM
fio xfio.conf
EOM
exec "$cmd"
#########################################################################################
rm test
echo
[global]
filename=test
ioengine=psync
direct=1
numjobs=1
iodepth=1
group_reporting
stonewall
[seq-read-1m]
name=seq-read-1m
size=5G
bs=1m
rw=read
stonewall
[seq-write-1m]
name=seq-write-1m
size=5G
bs=1m
rw=write
stonewall
[seq-read-4k]
name=seq-read-4k
size=1G
bs=4k
rw=read
stonewall
[seq-write-4k]
name=seq-write-4k
size=1G
bs=4k
rw=write
stonewall
[rand-read-1m]
name=rand-read-1m
size=1G
bs=1M
rw=randread
stonewall
[rand-write-1m]
name=rand-write-1m
size=1G
bs=1M
rw=randwrite
stonewall
[rand-read-4k]
name=rand-read-4k
size=100M
bs=4k
rw=randread
stonewall
[rand-write-4k]
name=rand-write-4k
size=100M
bs=4k
rw=randwrite
stonewall
@JannemanDev
Copy link

JannemanDev commented Jan 11, 2020

On my Synology DS214+ with DSM 6.2.2-24922-4 the script didn't work. I installed as instructed and put them in the folder /root/syno hd speedtest. This line
#device=df $volume | tail -1 | awk '{ print $1 }'``

didn't work. Device (harddisc) was detected as /dev/root which of course is not correct so it gave an error:

sudo hdparm -Tt /dev/root
/dev/root: No such file or directory

As a workaround I set the device to /dev/md1
Now the script continued correctly... although creating the testfile took several minutes. Furthermore the test as a whole took very long, because my IronWolf 10TB has it's writecache disabled because of a stability issue in combination with DSM. This should be fixed in the SC61 firmware.

Update:
when you put the script inside your home folder for example /volume1/homes/username/hd speedtest it works and device/hd is detected as /dev/md1

@girtsn
Copy link

girtsn commented Dec 21, 2021

My issue was with line

  • head -c 1G </dev/urandom >test

it does not take minutes to create, more like an hour on my Synology, guess the random generator is not using the proper method
instead I used this:

  • openssl rand -out test "$( echo 1G | numfmt --from=iec )"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment