Now let’s try to squeeze the most performance of it.
First, I have set up SAMBA as this is the most important file sharing protocol supported by this NAS; everything else revolves around it. I created some shares, mounted them on my Linux box. Unix extensions on SAMBA are enabled, that’s good – I can see the owners and file modes correctly. But when I tried to create a symlink – bah! – got access denied?
Long story short, after digging the SAMBA sources I found out that those strange D-Link guys hacked them badly and ugly. In particular, they changed the ‘follow symlinks’ option from its default of ‘yes’ to ‘no’. So, everything you have to do is to add ‘follow symlinks=yes’ to /etc/samba/smb.conf and restart SAMBA. You’ll have to do that manually after every reboot, of course – or write a script to do it automatically 🙂
Another thing I wanted to try is to compare the performance of NFS and SAMBA and decide which of two is better to use. Long time ago SAMBA was no alternative to NFS because it was missing file ownership and mode info; but things changed since that and nowadays it’s a quite functional alternative.
So, I’ve made my SAMBA shares also available via NFS, mounted them on my PC and did a simple test by dd’ing a large file (>1Gb) to /dev/null (dd if=largefile.avi of=/dev/null bs=64k). Fortunately, dd will do all the math for us, so we get the numbers… what??? 17Mb/s? What the hell?
After some research I found that the guys at D-Link, amongst other things, forgot to correctly set up NFSD. If you do a ‘cat /proc/net/rpc/nfsd‘ you can see that the ‘th’ (threads) line says the NFS daemon uses a single thread to serve client requests. So, basically, CPU usage goes to 100% on a single core and the second core stays idle. That’s the limiting factor for NFS. We have to increase number of NFSD threads at least to number of CPU cores, or more. To increase number of NFSD serving threads just run ‘rpc.nfsd 4‘ to set th to 4, for example. After that my ‘dd’ test shows a increase in throughput from 17 to 27Mb/s! That’s way better.
Then I tried the ‘dd test’ with SAMBA shares and – guess what – it gave me 58Mb/s! That’s astonishing, given the fact that ‘dd’ on NAS can’t read more than 48Mb/s directly from /dev/sda! Moreover, during the test the CPU load is under 20% (just one core).
Some research has revealed that the SOC used on DNS-315 contains a circuit named “Network Offloading Engine”. My guess is that this circuit (with appropriate support from kernel) can pump data directly between SATA and Ethernet controller, without CPU intervention. So, on this NAS the best results on file sharing operations can be achieved when this hardware data pump support is activated.
It looks, like this support is built into the Linux’ sendfile() system call. This syscall just copies data from one file handle to another; if it happens that one handle points to hard disk and other to Ethernet, the kernel support activates the CPU-less data pumping function.
Now, as you understand, the most important option in smb.conf is “use sendfile = yes”. If you set ‘use sendfile=no’ in smb.conf, it starts crawling just like NFS. So, don’t do it! 🙂
So, in the end, I decided to use SAMBA and avoid using NFS. Unfortunately, the NFS implementation does not use sendfile() (perhaps because NFSD is already implemented in kernel, so it won’t gain anything on “regular” hardware). So, the net result is that NFSD can’t take advantage of the huge performance benefit provided by the “Network Offloading Engine” on PLX NAS 7820 SOC.
Now, to put it all together, let’s create a script that will automatically optimize NFSD performance (just in case) and enable symlinks in SAMBA at NAS startup. Create a shell script in /ffp/start/ and put the following inside:
#!/bin/sh if grep -q '^th 1' /proc/net/rpc/nfsd ; then    # set up 4 threads to handle NFSD requests    # instead of default 1 which is ineffective on a 2-core config    rpc.nfsd 4 fi # fix SAMBA symbolic links if ! grep -q 'follow symlinks' /etc/samba/smb.conf ; then    sed /etc/samba/smb.conf \        -e '/^\[ global \]/{' \            -e 'a \' -e 'unix extensions = yes' \            -e 'a \' -e 'follow symlinks = yes' \        -e '}' > /etc/samba/smb.conf.new    if [ -r /etc/samba/smb.conf.new ] ; then        mv -f /etc/samba/smb.conf.new /etc/samba/smb.conf        while pidof smbd >/dev/null ; do            killall smbd            sleep 1        done        smbd -D    fi fi
After that, chmod a+x the file so that it will automatically run at startup, and you’re done!