DEV Community

Cover image for Raspberry Pi: Comparing HDD Disk Read and Write Performance for external USB and SATA Drives
Sebastian
Sebastian

Posted on

Raspberry Pi: Comparing HDD Disk Read and Write Performance for external USB and SATA Drives

In my IOT Stack, a Raspberry Pi with an external connected disk serves as a SAMBA server. Before installing the system, I wanted to see the performance differences of various disk, their read speed, and their local and remote, via SAMBA, write speed.

This article briefly shows how to measure and improve the HDD performance of your server. You will learn the essential Linux commands to make disk performance measurements locally and over the network, and learn about the physical speed limits.

The technical context of this article is Raspberry Pi OS 2021-05-07. All instructions should work with other Linux distributions and newer versions as well.

This article originally appeared at my blog admantium.com.

Performance Measurements

For speed tests, the two essential tools are Hdparm and [dd](https://en.wikipedia.org/wiki/Dd_(Unix):

  • hdparm is a multifunctional tool for configuration and performance measurements, It will evaluate the disks read and write speed, as well as to access aspects like its power management capabilities and direct memory access configuration
  • dd is a command line tool for reading and writing raw device data, and can be used for tasks such as making backups of the boot sector or of the entire hard disk.

To test the drive performance with these tools, they will be called in a specific manner. With hdparm, we will test the device reads and cache reads performance - the command is hdparm -tT DEVICE_NAME. With dd, we will write 5GByte of data to the disk - the command is dd bs=10M count=500 if=/dev/zero of=PATH_TO_OUTPUT_FILE. With dd, we will both make a test for the disk’s local performance, and we will also write data to a SAMBA share to measure the network performance.

Measurement 1: 1TB USB3.0 External Disk

The fist disk is a Toshiba Canvio Basic 1TB USB3.0 external disk. It runs at 5400RPM.

Read Performance

sudo hdparm -tT /dev/sda
 Timing cached reads:   1590 MB in 2.00 seconds = 795.37 MB/sec
 Timing buffered disk reads: 256 MB in 3.03 seconds =  84.52 MB/sec
Enter fullscreen mode Exit fullscreen mode

Local Write Performance

dd bs=10M count=500 if=/dev/zero of=/home/pi/test.bin
500+0 records in
500+0 records out
5242880000 bytes (5.2 GB, 4.9 GiB) copied, 52.0089 s, 101 MB/s
Enter fullscreen mode Exit fullscreen mode

Remote Write Performance

dd bs=10M count=500 if=/dev/zero of=/Volumes/share/test.bin
500+0 records in
500+0 records out
5242880000 bytes transferred in 77.964918 secs (67246656 bytes/sec)
67MB/s
Enter fullscreen mode Exit fullscreen mode

Measurement 2: 512GB 2.5' SATA with USB3.0 Connection

The second disk is and older disk from a laptop, a 512GB Western Digital 512GB SATA 5400 WD5000BEVT. Its connected with a SATA-To-USB connector attached to an USB3.0 port.

Read Performance

sudo hdparm -tT /dev/sda
/dev/sda:
 Timing cached reads:   1544 MB in  2.00 seconds = 772.31 MB/sec
 Timing buffered disk reads: 258 MB in  3.00 seconds =  85.89 MB/sec
Enter fullscreen mode Exit fullscreen mode

Local Write Performance

dd bs=10M count=500 if=/dev/zero of=/home/pi/test.bin
500+0 records in
500+0 records out
5242880000 bytes (5.2 GB, 4.9 GiB) copied, 63.1331 s, 83.0 MB/s
Enter fullscreen mode Exit fullscreen mode

Remote Write Performance

dd bs=10M count=500 if=/dev/zero of=/run/user/1000/gvfs/smb-share:server=nexus,share=share/testbin
500+0 records in
500+0 records out
5242880000 bytes (5,2 GB, 4,9 GiB) copied, 123,337 s, 42,5 MB/s
Enter fullscreen mode Exit fullscreen mode

Measurement 3: 512GB 2.5' SATA with USB2.0 Connection

That’s the same disk as in measurement 2, but connected to an USB2.0 port on the Raspberry Pi.

Read Performance

sudo hdparm -tT /dev/sda
/dev/sda:
 Timing cached reads:   1506 MB in  2.00 seconds = 753.58 MB/sec
 Timing buffered disk reads:  98 MB in  3.01 seconds =  32.53 MB/sec
Enter fullscreen mode Exit fullscreen mode

Local Write Performance

dd bs=10M count=500 if=/dev/zero of=/home/pi/test.bin
500+0 records in
500+0 records out
5242880000 bytes (5.2 GB, 4.9 GiB) copied, 174.322 s, 30.1 MB/s
Enter fullscreen mode Exit fullscreen mode

Remote Write Performance

dd bs=10M count=500 if=/dev/zero of=/run/user/1000/gvfs/smb-share:server=nexus,share=share/testbin
^[[C500+0 records in
500+0 records out
5242880000 bytes (5,2 GB, 4,9 GiB) copied, 175,105 s, 29,9 MB/s
Enter fullscreen mode Exit fullscreen mode

Comparison

Let’s compare all the measurements.

Read Write (local) Write (Remote)
1TB USB3.0 Extern 84 MB/s 101 MB/s 67 MB/s
512GB SATA 5400RPM with USB2.0 Connection 33 MB/s 30 MB/s 30 MB/s
512GB SATA 5400RPM with USB3.0 Connection 86 MB/s 83 MB/s 43 MB/s

The clear winner is the native USB3.0 disc, although it runs at the same speed of 5400RPM, it increases the local write speed by 21% and the remote write speed by 55% compared the SATA disc.

Understanding Remote Write Performance Drop

Now, let’s see why the remote write performance drops by about 33%. The theoretically available speed limits are:

  • USB 2.0 53MB/s
  • USB 3.0 500MB/s
  • SATA3 550MB/s

In my home network, I measured raw package data transfer speed of 924 MB/s.

[ ID] Interval           Transfer     Bitrate
[  5]   0.00-10.00  sec  1.08 GBytes   924 Mbits/sec                  sender
[  5]   0.00-10.01  sec  1.07 GBytes   922 Mbits/sec                  receiver
Enter fullscreen mode Exit fullscreen mode

So, why can I only achieve 67 MB/s? Reading various threads about SAMBA network share with Raspberry Pi unveiled two facts: SAMBA adds significant network overhead, and even if a Gigabit ethernet is available, the bandwidth is shared by all connected devices. Having multiple Raspberry Pi connected and communicating with each other impacts the overall performance. To increase the performance, others are recommending to fine-tune the SAMBA settings of the software you are using, for example see this thread about improving SAMBA performance in OpenMediaVault.

Summary

When setting up a SAMBA share with a Raspberry Pi, using a well-performing disk is important. This article showed you how to use the two tools hdparm and dd for making read and write speed performance measurement. To test the SAMBA share write speed, you can simply write to a SAMBA connected disk. The results are clear: a dedicated external disk is faster than a SATA disc with an USB connector, and always prefer USB3.0 over USB2.0. Finally, be sure to optimize the SAMBA parameters to improve the performance even further.

Top comments (0)