Raspberry Pi 2 NAS Experiment HOWTO
It is not an exaggeration to say that the Raspberry Pi took the world by storm. The combined sales of the Raspberry Pi Models A, A+, B and B+ have exceeded 4.5 million units.
The new Raspberry Pi 2 Model B has sold half a million units in less than two months, bringing the total sales to 5 million units, and will likely equal all previous Raspberry Pi sales in less time than anyone could reasonably expect.
I would not be surprised if combined Pi sales reached 10 million units by 2017.
(click on image for larger version – click here for Raspberry Pi 2 Review)
With the new Raspberry Pi 2, many more applications become feasible due to twice the RAM and roughly six times the compute performance compared to the original Raspberry Pi’s.
One common theme on the Raspberry Pi Forum has been people wanting to use their Raspberry Pi’s as a NAS (small file server)
This begs the question:
“Is the Raspberry Pi 2 suitable for use as a NAS?”
The answer is:
“It depends on your needs”
This article will explain the trade-offs and limitations that effect using a Raspberry Pi 2 (or original Raspberry Pi) as a NAS.
Hopefully it will help those new to servers and performance limits understand why the Raspberry Pi 2 cannot be used as a high performance file server – regardless of their enthusiasm.
I hope that as you read this article you will be able to decide if the Raspberry Pi 2 will suit your needs as a NAS.
Analysis (Looking for Bottlenecks)
The performance of any system is limited by its bottlenecks. The Raspberry Pi 2 (and original Raspberry Pi) have the following bottlenecks in common:
1) USB 2.0
The Raspberry Pi 2 Model B is almost identical to the Raspberry Pi Model B+ as other than the aforementioned double ram and greatly increased performance, and some low level changes needed to support the extra memory (register base addresses have changed) no changes were made to the Pi architecture.
This means:
- same LAN9514 10/100 Ethernet controller with USB hub sharing the single BCM USB2.0 host port
- BCM2836 has the same USB2.0 host port as on the BCM2835
USB2.0 is limited to 480Mbps (which has to include USB overhead) so it is physically impossible to transfer more bits per second into or out of the processor in a second.
In reality, due to USB overhead, interrupt overhead etc., the combined usable bandwidth of a USB2.0 bus is limited to less than 400Mbps, that is, less than 50MB/sec total bandwidth for Ethernet and all USB devices.
No matter how much we might wish that this limit does not exist, it does … and it cannot be changed.
2) 10/100 Ethernet
The LAN9514 containes a 10/100 USB Ethernet interface.
Experience shows that under ideal circumstances close to 99Mbps of useful data can be transferred on a 100Mbps Ethernet segment – indeed the iperf tests I ran for my Raspberry Pi 2 review showed up to 94.2Mbps per second.
In real life, this translates to a theoretical limit of just over 11.5MB/sec data transfer – assuming that it took zero time to find and read the data from the disk storage. As this cannot be the case, real life data transfer rates on a 100Mbps Ethernet segment are limited to less than that, regardless of how fast the processor, disk and memory are.
In order to bypass this bottleneck, I tried using a USB 3.0 Gigabit Ethernet adapter with my Raspberry Pi 2.
In my Raspberry Pi 2 Model B Review I was able to achieve 178Mbps with iperf in client mode, which suggests that 21MB/sec transfers are theoretically possible over a gigabit Ethernet using one of these adapters and a Raspberry Pi 2.
At least we can get higher than 100Mbps of throughput as long as we add a gigabit USB3 Ethernet adapter – but this is not without cost, as now there will be less USB2.0 bandwidth available for data transfer to/from USB hard drives.
3) USB 2.0 Disk Transfer Rate
(click on image for larger version)
This is a major fly in the ointment.
The biggest limitation on USB disk transfer rate is the USB 2.0 interface used by the Raspberry Pi.
The second biggest limitation is having to share that bandwidth with the Ethernet controller.
Less important considerations are the seek time and rotational latency of the drive – as even a 5400rpm laptop drive can transfer far more data per second than a USB 2.0 link can carry.
In a perfect world, without overhead, a USB 2.0 link could transfer close to 60MB/sec. That world does not exist – and cannot exist.
In our real world, we are limited to less than 50MB/sec, even if we had a direct USB2.0 host to the SOC, which we don’t.
My recent Raspberry Pi 2 USB hard drive and adapter tests show that at most 38MB/sec can be written over the USB bus.
Assuming we can transfer data over the 10/100 Ethernet at full blast (11.5MB/sec) we would theoretically have up to 38.5MB/sec bandwidth to the hard drive. In reality, due to software overhead, it will be less than that.
But it does not matter.
The absolute best theoretical transfer rate over 100Mbps Ethernet between a Raspberry Pi NAS and a client computer is less than 11.5MB/sec – that is assuming zero overhead for reading/writing the files, finding the files, file server software, file system drivers etc – which is impossible.
The best we can do is approach that theoretical 11.5MB/sec Ethernet 100 transfer rate, and potentially 21MB/sec on a gigabit network using an external USB Gigabit Ethernet adapter… of course this would be limited by the speed of the storage, and the USB bandwidth left over (from what the gigabit adapter used), as well as file server software and file system limitations.
Article Index
- Introduction, Analysis (Looking for Bottlenecks), USB 2.0, 10/100 Ethernet, Disk Transfer Rate
- But what about RAID?, File Server Software, File System Overhead, Configuring your Raspberry Pi 2 SAMBA server, Tuning the server, Test Equipment
- Benchmarks, Reading/Writing/Copying large files, Reading/Writing/Copying directory of jpeg’s, Conclusion