Monday, 26 January 2015

Samba or nfs

There's two ways to share directories over a network, Samba and NFS. There's probably lots of other ways, but those are the common ones. The question is, which to use?

If your network includes Windows boxes, then you'll need at least some Samba, because Samba is the native Windows file sharer. So, for example, to access Dropbox, I use a Windows machine to handle the Dropbox, and share that across the network using Samba. And NFS is the native Unix file sharer.

I'm mostly Linux, with a couple of Windows boxes for the places that Windows really is needed (for GSAK, for example, and yes, I know you can run GSAK under Wine, but have you actually tried that? Not everything works).

Setting up the Pix firewall, brought this question back to my attention. Because it's a bit fiddly running NFS across a firewall, there's two ports to allow (111 and 2049), usng both TCP  and UDP. And then there's several other ports that need to be allowed, and you can't predict which ports get used. You can fix most of them, but even after doing that, the Pix reported attempts to use another port, and the port number was variable. Bah! With Samba, there's only two ports (139 and 445), and only TCP. So much easier to allow.

Finding a fix for the bug that was stopping me from using Samba on Fedora core 9, means that I can now use Samba wherever I want; before, I was forced to use NFS in the places Samba didn't work.

But then there's the question of speed. I googled, of course, and opinions are a bit mixed, but mostly come down in favour of NFS being a bit faster. So I did a speed test. I copied a 670 mb file from a shared directory to the local machine, and timed it. NFS ran at 10 megabytes/sec (which is pretty much the speed of my internal network, 100 mbit). Samba ran at 8 mb/sec, so NFS is 25% faster. This isn't a big deal. If there's something else going on at the same time on my network, that would impact the file transfer speed a lot more.

So I'm going to use Samba for most things, and NFS when that last ounce of speed is actually useful.


  1. When I set up a Raspberry Pi as a samba NAS, I found that reads went at around 8 megabytes/sec but writes to it across network were around 10 megabytes/sec (As reported by Windows 7).

    Curious, as it goes against the tradition of reads being faster than writes. No idea why, but its consistent.


  2. Weird! When you read from it, does the data go to /dev/null, or are you writing it somewhere?

    1. The test was run on a Windows 7 PC, copying a 5Gigabyte file from the PC hard disk to the Pi's USB hard disk, then copying it back again.

      I re-ran the tests today, and also compared the speed between two PCs. My network is gigabit, the 2 PCs have gigabit cards although the Raspberry Pi is only 100Mbit.

      Test PC to PI PI to PC PC to PC2 PC2 to PC
      1 6.07 3.67 21.02 19.11
      2 6.08 3.66 21.56 19.12
      3 10.14 6.54 31.31 23.77
      4 10.21 6.51 31.41 21.37

      Tests 3 & 4 were run with 9K jumbo frames enabled on the two PCs. Curiously, this improves throughput to the Raspberry PI, even though I didn't think it supported jumbo frames and I didn't make any configuration changes to it.

      So, from the PC's point of view, writes to a network device are faster than reads.

      Need to try it frmo the Raspberry Pi end next I suppose.