1

I want to use my RPi4 as a small home NAS. To do that, I'm trying to benchmark the maximum file transfer performance.

Workflow:

  1. Rpi4 connected to home router with a 1 Gbit cable

  2. computer connected to home router with a 1 Gbit cable

  3. in order to avoid variations due to the microSD card speed itself or the USB external hard drive speed, I create a 500MB file in a RAMdisk:

    sudo mkdir /mnt/ramdisk
    sudo mount -t tmpfs -o size=512m tmpfs /mnt/ramdisk
    sudo dd if=/dev/urandom of=/mnt/ramdisk/500MB bs=1M count=500 iflag=fullblock   # random 500MB file
    
  4. then I copy via SFTP this file from RPi's /mnt/ramdisk/500MB to my laptop's SSD

I get the following results:

  • When nothing is additionally plugged on USB ports, I get 32 MB/sec transfer

  • When I plug an external USB 2.5" external hard drive without its own power supply (supply from USB), without using it, still using transfer from RAMdisk, I get 15 MB/sec only!

    So I had my answer ready ... the USB external hard drive takes too much power and this is the reason for the performance drop! But it seems that no: indeed the next test is a mystery:

  • When I plug an external USB3 external hard drive which has its own power supply (with an adapter for the HDD only) to the RPi4 (USB2 or USB3 port tested, idem), without using it but just plugged in, still using the RAMdisk, I get 15 MB/sec too!

Question: which maximum transfer speed over SFTP from RPi to computer do you get? if possible with a similar workflow from above: RPi + computer with ethernet cables, no Wifi, transfer a file from RPi (in RAMdisk) to computer (on SSD)

Basj
  • 782
  • 3
  • 17
  • 46
  • does https://raspberrypi.stackexchange.com/questions/99896/does-the-pi-4-resolve-the-ethernetusb-bottleneck-issue-of-past-versions answer your question? – Ljm Dullaart Nov 23 '20 at 16:33
  • Doesn't seem like an answer since it does not explain the discrepancy in ethernet speed when a USB drive is connected. All it does is imply the reason is not the same as it is for previous models. @Basj Check if you get anything in the logs like this when you have the drive attached (also check its performance, if you are unsure of that): https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=245931 Flailing with the hardware (repeated connect/re-connect) may be slowing other aspects of the system down. – goldilocks Nov 23 '20 at 16:47

2 Answers2

4

I have an Rpi4 8GB with a WD Elements 2TB USB3 external HDD (USB3 powered from the Pi) and a Seagate Backup Plus USB 3TB (with its own power supply), both shared by the Pi using Samba and I can get 100 Mbyte/sec each way from either on my LAN, maxing out the Gigabit Ethernet. SFTP is slow because of encryption/decryption. Also, if the drives are formatted NTFS then any Linux server is going to bog down because of the CPU load. My Samba shares are formatted ext4.

(1) 11.6 GB file from Pi to Windows PC

enter image description here

(2) The same file from Windows PC to Pi

enter image description here

(3) You will not get such high speeds with lots of small files (Rpi to Windows PC)

enter image description here

(4) For comparison, using WinSCP for an SFTP transfer from Pi to Windows PC.

enter image description here

Another factor is power. Although earlier Pis may work fine with various "charger" type wall warts which the owner may have lying around, the Raspberry Pi Foundation makes clear that later Raspberry Pis, especially the 3 and 4 models, are very fussy about power supplies, and for the 4 the official PSU is strongly recommended. Devices intended for battery charging duty may allow the voltage to sag below 5V when current draw goes over a certain level. You want 5.1V / 3.0A DC output, and it must be capable of doing both these at the same time!!! This goes double if you are powering external devices via the PI. The total USB draw allowed is 1.2A, which is, realistically, ONE external USB drive. Really people purchasing the Pi 4 should order an official PSU at the same time.

Michael Harvey
  • 1,390
  • 7
  • 11
  • Thanks for this very useful information. I'll test without SFTP, but Samba. I'll do first a Samba share of /mnt/ramdisk, to see how it behaves. Then I'll plug another USB external disk formatted with ext4, shared with Samba, and I'll see if I can get similar results than you. – Basj Nov 23 '20 at 23:02
  • @Basj - I've added some screen shots. – Michael Harvey Nov 24 '20 at 07:22
  • Wonderful @MichaelHarvey, I'll try to do similar tests. Out of curiosity, what MB/s speed do you get if downloading via SFTP (example: WinSCP) Rpi -> computer? – Basj Nov 24 '20 at 08:48
  • Linked question: I plan to do the same than you: use a WD Elements 2TB USB3 external HDD (USB3 powered from the Pi). Do you think it's ok for a Rpi4 running 24hr/24 365day/365, do you use it that way too? – Basj Nov 24 '20 at 08:50
  • @Basj SFTP screen shot added; I keep both my USB HDDS running 24/7. Don't place it where it cannot keep cool. – Michael Harvey Nov 24 '20 at 11:06
  • Thanks @MichaelHarvey! I'm just running the same test with Samba, and I get much higher speed! Around 70 MB/s! I'll also redo a test when the better power supply I ordered will arrive. For now it seems that I'm throttled. – Basj Nov 24 '20 at 11:25
  • If you had to choose only one 4TB HDD to connect to the Rpi4, @MichaelHarvey, would you order a 2.5" (power supply from Pi USB), or a 3.5" (with its own power supply, but then it takes more space + one more adapter...). I'm hesitating. (I'll use only 1 HDD, I other other backups elsewhere). – Basj Nov 24 '20 at 11:27
  • I only connected the Seagate BUP with its own PSU because I was bored one day and was curious to see how it worked with the Pi when formatted ext4. It had been attached to a USB3 port on my Windows PC for several years. Since the Rpi4 has a max current rating of 1.2A for all USB ports combined, I would check the current rating of any USB powered drive I might add to the Pi. If you plan to add other USB devices to the Pi that might add to the current draw, I would choose a drive with its own PSU. – Michael Harvey Nov 24 '20 at 11:44
  • Last question @MichaelHarvey: does your 2.5" HDD (USB-powered, without PSU) stop spinning when it's not used (example: during the night), or is the disk spinning 24/24 365/365 when it's connected to the Pi? When I did the test with sudo smartctl --all /dev/sda -d sat it seems it stops, but I'm not 100% sure if it's always the case with a RPi + any HDD, so a confirmation would be great :) – Basj Nov 24 '20 at 12:35
  • I have so many cron jobs running that access the USB drive (about 4 each hour) that it never spins down, but I think it might spin down after 20 minutes if they weren't doing that. – Michael Harvey Nov 24 '20 at 13:36
  • A million thanks, you helped me solve my problem @MichaelHarvey! Full solution here. – Basj Nov 26 '20 at 09:32
0

My problem was a combination of two factors:

  • using SFTP instead of Samba share. Using Samba massively increases the speed, as detailed in @MichaelHarvey's answer

  • the PSU that I used did not deliver enough current: the RPi was "throttled":

    /opt/vc/bin/vcgencmd get_throttled   # throttled=0x50005: under voltage, currently throttled!
    

Now that I bought the official RPi power supply, it is no more throttled (throttled=0x0), and I can enjoy 110 MB/s speed when transferring from RPi ramdisk to computer over a Samba share (both RPi and computer with 1Gbps ethernet cables).

enter image description here

I did a similar test in the other way, sending from computer to RPi (ramdisk), and I get similar speed:

enter image description here

Now the tricky thing will be to find the best filesystem both readable on Windows (if one day I need to connect the external HDD to Windows), and having good write performance on RPi (exFAT? NTFS? etc.), but it's out of topic for this precise question

Basj
  • 782
  • 3
  • 17
  • 46
  • 1
    Although earlier Pis may work fine with various "charger" type wall warts, the owner may have lying around, the Raspberry Pi Foundation makes clear that later Raspberry Pis, especially the 3 and 4 models, are very fussy about power supplies, and for the 4 the official PSU is strongly recommended. Devices intended for battery charging duty may allow the voltage to sag below 5V when current draw goes over a certain level. You want 5.1V / 3.0A DC output, and it must be capable of doing both these at the same time!!! Really people purchasing the Pi 4 should order an official PSU at the same time. – Michael Harvey Nov 26 '20 at 09:39
  • I only realized today how important this 3.0A PSU thing is! – Basj Nov 26 '20 at 09:42
  • It's in all the Raspberry Pi Foundation material on their web site. Their own forum is a very useful resource, more focussed and expert than anywhere else with Pi information and questions. Good to do pre-purchase research there. – Michael Harvey Nov 26 '20 at 10:30
  • Starting with Windows 10 Insider Preview build 20211, Windows Subsystem for Linux 2 (WSL2) now includes a wsl --mount command that lets you mount ext4 and other Linux kernel supported filesystems, directly in installed WSL distributions. This means it may well be in mainstream Windows in the not-too-distant future. Another thing you could do now is attach the ext4 USB drive to a Linux VM in VirtualBox and share it via Samba. – Michael Harvey Nov 26 '20 at 21:36