Raspberry Pi with Ethernet cable connected to it.

RPi NAS: Part 3 Network Connections

19 January 2024

In the previous post we decided on booting from an SD card. Now we’ll have a look at the speed of different types of network connections.

This post is part of a series about building a Network-Attached Storage (NAS) with redundancy using a Raspberry Pi (RPi). See here for a list of all posts in this series.


When we want to copy data to our NAS we first have to send it via a network from our computer to the Raspberry Pi. The speed of the network will be an upper limit for the overall transfer speed we can expect.

I’m not considering a direct connection via USB for a few reasons. One is that I know from experience that I’m lazy when it comes to saving data. If I have to get up to grab hard drives from somewhere then I’ll usually postpone it1. I also don’t want to have potentially noisy hard drives sitting on my desk. Moreover, multiple users in my household should be able to access the drives so a USB-cable-bound storage solution would be inconvenient.

So let’s have a look at our options for network connections!

Ethernet

There are different Ethernet standards. As I’m writing this 1G Ethernet is widely available. It’s also the fastest standard that’s (natively) supported by the RPi 4b and 5. So let’s connect both the RPi and a computer the a router via Ethernet and test the speed of our connection. For this test we’ll use iperf3, which allows us to estimate the maximum achievable bandwidth of a network. On the RPi we run

iperf3 -s

and on the computer sending the data we run

iperf3 -c rpi.ip.add.ress

You may have to install iperf3 first with sudo apt install iperf3. The table below shows the results:

Type of ConnectionConnection Speed
in bits
Connection Speed
in bytes
Ethernet 1Gb/s941Mb/s~117.5MB/s
Both the RPi and my computer are connected via Ethernet. The results are the average over five separate runs of iperf3.

So when it says Gigabit Ethernet then that really means that the physical connection supports transfers of up to 1Gb per second. However, not all of that bandwidth can be used for data transfer. To be able to communicate you need some sort of protocol that establishes and manages the communication (typically that’s TCP). This admin work uses some of the bandwidth. According to this article there’s an overhead of approximately 5%, which is roughly what we’re seeing here ((1000-941)/1000 = 0.059).

Are you getting slower transfer speeds? The connection is only as fast as the slowest link. So your computer, the cable from your computer to the router, your router and the cable from your router to the RPi (and all other components that you might have in-between) must all support Gigabit Ethernet. For example, it should say at least Cat5e or Cat6 on your Ethernet cable, anything lower and you won’t get the full speed (larger numbers are fine but not necessary).

WiFi

WiFi is messy. There are many different standards and the speeds we will get depend on many factors.

WiFi 5 Physical Speed

The latest and fastest WiFi standard that the RPi 4b (and the RPi 5) supports is WiFi 5 (standard 802.11ac). What speeds can we expect to get from WiFi 5 under ideal circumstances?

The answer is a little involved because it depends on

  • the number of antennae on your router,
  • the number of antennae on your computer (e.g. the RPi),
  • the bandwidth used and
  • the modulation type.

It’s probably clear what number of antennae means2. But what’s that bandwidth? And what’s modulation type?

A 5GHz WiFi connection communicates via radio waves whose frequencies are somewhere in the range of 5170 to 5895 Hertz3. That’s a wide spectrum and a single connection doesn’t use all of it. Instead the spectrum is split up into bands of 20MHz. For example, the first band goes from 5170 to 5190.

Bands can be combined. A connection can combine two adjacent bands for 40MHz, four for 80MHz or eight for 160MHz. Your connection over 40MHz will be roughly twice as fast as over 20MHz and your connection over 160MHz will be roughly eight times as fast as over 20MHz.

There’s a similar trend for the number of antennae. If both the router and your computer have two antennae then the connection will be twice as fast compared to using only one antenna.

Finally, modulation is an umbrella term for methods that combine multiple signals into one signal, thereby increasing the amount of information that can be transferred over a connection. The kind of modulation used depends on the quality of the WiFi signal. If you have a very good signal from the router (e.g. if you’re close to it and there is little interference from other networks), then a very fast modulation method can be used (and vice versa)4.

If your router supports different characteristics than your computer then the smaller of the two will be used (e.g. if your router has 4 antennae and you computer has 2 then only 2 can be used).

So what physical speeds can we expect to get over a 5GHz network? According to the standard, a computer with one antenna, a bandwidth of 80MHz and the fastest type of modulation should result in a physical link rate of 433Mb/s (~54MB/s). If our computer has two antennae then we should get 867Mb/s (~108MB/s).

Number of Antennae
Router
Number of Antennae
Computer
BandwidthPHY link rate
Mb/s
1180MHz433
4180MHz433
4280MHz867
A few examples of the network speeds we can expect, given the number of antennae and a fixed bandwidth of 80MHz.

Channels

We said before that the 5GHz spectrum consists of many different bands (or channels). We can choose the band we want to use in our router’s settings. Does it matter which one we choose?

An important point about bands is that they are shared with other routers (or access points). If a computer notices that some other device is already communicating over a channel (whether on your WiFi or your neighbour’s) then it will wait a little before it tries to communicate again. So if you and your neighbour share the same channels then your WiFi connection may get a lot slower.

How can you find out if you’re sharing channels? There are a few tools available. I really like wavemon which should be available for most Linux distributions. When you open it with sudo wavemon and press F3 you get a list of all WiFi networks and the channels they use (and a lot of other information). If many networks use the same channel as yours then you may want to look for a less crowded channel and update your router’s settings.

Communication Overheads

The speeds we saw before are physical speeds. As for Ethernet there are communication overheads, but they are a lot higher for WiFi. According to the website I linked to earlier these tend to consume somewhere between 20% to 40% of the physical speed (there are a lot more details on the website, it’s well worth reading).

Let’s do a little test. I’ve connected the RPi to my router via Ethernet so this side of the communication will be fast. The 5GHz WiFi uses a bandwidth of 80MHz and is on a channel that’s not shared with any neighbour. My laptop, which has two antennae, is connected to the 5GHz WiFi and it sits right next to the router so the fastest available modulation method (256 QAM) should be used. According to the standard the connection should give a physical speed of 867Mb/s (~108MB/s). Doing the same iperf3 test as before I get connection speed of 76MB/s, which is roughly 70% of the expected physical speed. So there’s an overhead of approximately 30%. That observation is consistent with the article mentioned above.

Type of ConnectionConnection Speed
in bits
Connection Speed
in bytes
5GHz WiFi608Mb/s~76MB/s
The RPi is connected via Ethernet, my computer to the 5GHz WiFi. The results are the average over five separate runs of iperf3.

WiFi Speed on the RPi 4b

So, as before, we’ve picked a bandwidth of 80MHz and we’ve selected a channel that’s not used by any other WiFi. We put the Raspberry Pi right next to the router and connect it to the 5GHz network. Our computer is connected via Ethernet.

What speed do we expect to get? Well, unlike my computer the RPi only has one antenna. However, it does support 80MHz and it supports 256 QAM so we’re looking at a physical transfer rate of 433Mb/s and a data transfer rate of somewhere between 260Mb/s and 346Mb/s (40% overhead and 20% overhead).

Let’s do the same iperf3 test as before:

Type of ConnectionConnection Speed
in bits
Connection Speed
in bytes
5GHz WiFi95Mb/s~12MB/s
The RPi is connected to the 5GHz WiFi, my computer via Ethernet. The results are the average over five separate runs of iperf3.

That seems slow, even though we’ve tried to create perfect conditions for a high transfer rate.

If you look online then you’ll find that other people got similar speeds. Most results I’ve seen are even a bit slower. I’ve only found one which is significantly faster at 114Mb/s (see here). If you manage to get that kind of speed please let me know under which conditions you tested and which hardware you used!

So why are we getting such a slow speed? There could still be some interference from other networks or devices, or my router could be a bit slow, or the RPi’s power supply might not be the best. But these explanations seem unlikely to explain such a large speed difference (also, almost all other results online are not faster).

The most likely reason I can think of is that the hardware used in the RPi is not able to provide faster speeds. For example, WiFi and Bluetooth are on the same chip and thus share the same bus so they may interfere with each other (although during the test I had no device connected via Bluetooth). The bus connecting the wireless chip may not support the full bandwidth. Also, the WiFi antenna is probably very small and may not be capable of providing high enough speeds. Can you think of any other reason? Let me know.

Of course we could use a USB WiFi card to improve our signal and transfer speed. However, we will use the RPi’s USB 3 ports for attaching hard drives so they are not available for a WiFi card.

2.4GHz WiFi

WiFi 5 uses a 5GHz connection. But other standards also use 2.4GHz (and the latest standard, WiFi 6e, even uses 6GHz). The Raspberry Pi supports 2.4GHz but those connections are typically a lot slower than the 5GHz connection, so we won’t cover them here.

Decision Time

It’s really not much of a decision. The only way to get a decent transfer speed to and from our NAS is if the Raspberry Pi is connected via Ethernet. In that case we can expect transfers of up to 117.5MB/s. This is also an upper bound for the transfer speed of the entire system.

For best performance we should also connect our computer via Ethernet. With a good router and WiFi card we may still get decent speeds over a 5GHz network (I got ~76MB/s).

If you’ve got a WiFi 6e router and a computer with a WiFi 6e-capable WiFi card, you may even be able to get really high speeds over WiFi (unfortunately I don’t have either to test that :).


Footnotes:

  1. And then I run out of disk space during an update. If that happens, don’t reboot! Make space on your computer and rerun the system update. If you do reboot then there’s a good chance that your system won’t boot at all. When I ran out of disk space during an update I wasn’t paying attention and I did reboot, at least I tried to. Luckily, there’s an easy fix if your system doesn’t boot. Boot with a live boot medium, make space on your disk, chroot into the system and use snapper-rollback (see this previous post) to return to your pre-failed-update state. Then do the full system update. ↩︎
  2. If you’re from North America you may be wondering why I’m writing about insects. Of course I mean antennas but having lived in the UK for a large part of my life I’ve picked up their spelling. ↩︎
  3. The subranges 5330 to 5490 and 5730 to 5735 are not used. ↩︎
  4. For more information about modulation see this Wikipedia entry. ↩︎
  5. Note, if there are only very few users then WiFi 6 won’t give any speedup over WiFi 5. ↩︎

This post is tagged as:



Comments

Leave a Reply

Your email address will not be published. Required fields are marked *