I have a few Raspberry Pis in my network and I wanted to make them go faster when running things on them. The biggest bottleneck I see is the disk I/O performance and this is how I ran a few benchmarks to see what their performance is.
I found a nice website where someone had done a little testing and used their hdparm and dd write methods. These are the commands.
$ sudo dd if=/dev/zero of=/test bs=8k count=50k conv=fsync; sudo rm -f /test 51200+0 records in 51200+0 records out 419430400 bytes (419 MB, 400 MiB) copied, 20.1934 s, 20.8 MB/s
That is an example of just copying some data from memory to a file on the SD card. The next example from the website gives some stats for buffered reads.
$ sudo hdparm -t /dev/mmcblk0 /dev/mmcblk0: HDIO_DRIVE_CMD(identify) failed: Invalid argument Timing buffered disk reads: 126 MB in 3.02 seconds = 41.74 MB/sec
As per a blog post on the Raspberry PI blog, they useed a tool they created call agnostics. You could install it with a simple ‘apt-get install agnostics’, but it requires a GUI to be running which means it pulls in a lot of dependencies when you install it. Thankfully, all the GUI really does is run a shell script witch runs another program. Below is a script I created to automatically download that script and run it.
#!/bin/bash # Install the benchmark utility apt-get install -y fio # Download a script and benchmark file wget https://raw.githubusercontent.com/raspberrypi-ui/agnostics/master/data/sdtest.sh wget https://raw.githubusercontent.com/raspberrypi-ui/agnostics/master/data/sd_bench.fio # Fix the path to the benchmark file sed -i 's@/usr/share/agnostics/sd_bench.fio@sd_bench.fio@g' sdtest.sh # Run the downloaded script bash sdtest.sh # Remove the downloaded files rm sdtest.sh rm sd_bench.fio # Uninstall the benchmark utility apt-get autoremove -y fio
Fio is the program that is called and runs the actual benchmarks as defined in the sd_bench.fio text file. Save the above as a script and then run it.
$ sudo bash bench.sh Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: ibverbs-providers libaio1 libboost-atomic1.67.0 libboost-iostreams1.67.0 libboost-regex1.67.0 libboost-system1.67.0 libboost-thread1.67.0 libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0 libibverbs1 libnspr4 libnss3 libnuma1 librados2 librbd1 librdmacm1 Suggested packages: gnuplot gfio python-scipy The following NEW packages will be installed: fio ibverbs-providers libaio1 libboost-atomic1.67.0 libboost-iostreams1.67.0 libboost-regex1.67.0 libboost-system1.67.0 libboost-thread1.67.0 libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0 libibverbs1 libnspr4 libnss3 libnuma1 librados2 librbd1 librdmacm1 0 upgraded, 19 newly installed, 0 to remove and 0 not upgraded. Need to get 0 B/16.4 MB of archives. After this operation, 41.7 MB of additional disk space will be used. ... Run 1 prepare-file;0;0;25801;50 seq-write;0;0;29023;56 rand-4k-write;0;0;654;163 rand-4k-read;8957;2239;0;0 Sequential write speed 29023 KB/sec (target 10000) - PASS Random write speed 163 IOPS (target 500) - FAIL Random read speed 2239 IOPS (target 1500) - PASS Run 2 prepare-file;0;0;25680;50 seq-write;0;0;15957;31 rand-4k-write;0;0;598;149 rand-4k-read;8511;2127;0;0 Sequential write speed 15957 KB/sec (target 10000) - PASS Random write speed 149 IOPS (target 500) - FAIL Random read speed 2127 IOPS (target 1500) - PASS Run 3 prepare-file;0;0;28731;56 seq-write;0;0;25332;49 rand-4k-write;0;0;494;123 rand-4k-read;10196;2549;0;0 Sequential write speed 25332 KB/sec (target 10000) - PASS Random write speed 123 IOPS (target 500) - FAIL Random read speed 2549 IOPS (target 1500) - PASS sdtest.sh: line 37: return: can only `return' from a function or sourced script ...
There will be an error in the output after the Run 3 section, but that is okay. We only care about the Runs. You can average out each run or just take one as an example for the performance of your own SD card. We can see from the output that I probably need to spend a little more money when purchasing my SD cards.