Jan 28, 2014

Auto reactivate wifi on raspberry pi

One of my raspberry pi was having trouble auto reconnectiong to home wifi when wifi router starts. I made a simple script to re-activate wifi.                                                                        
#!/bin/sh
stat=`/sbin/ifconfig wlan0 | /bin/grep -q "inet addr:"`

if [ $? -ne 0 ]
then
        echo "Wifi restarting..."
        /sbin/ifup --force wlan0
fi
It will have to be registered on crontab of root:
* * * * * wifi.sh

It will check the wifi every minute and reactive when the wifi is down.

You can also test it by manually deactivating it: sudo ifdown wlan0.
If it comes up by itself after one minute later, the setting is working.

Jan 4, 2014

The performance of Raspberry PI as NAS

I have been running some testing yesterday and made some conclusions.

One of PIs I am running is for file server. An external HDD with NTFS is attached via USB. Ethernet cable is directly connected to the home router. SD card is class 10.

I measured I/O performance with dd command; cf this.
  • Write speed: sync; time dd if=/dev/zero of=./test.tmp bs=500K count=1024; time sync
  •  Read speed: dd if=./test.tmp of=/dev/null bs=500K count=1024

Read speed of SD card is 30MB/s.
Write speed of SD card is 5MB/s.
Read speed of external HDD with NTFS-3G is 30MB/s, which is surprising.
Write speed of external HDD with NTFS-3G is 5MB/s.

It is interesting that both of them looks similar. I thought that I made some mistake on differentiating HDD from SD card. I am thinking that swap partition thing is limiting the HDD write speed and read speed seems to be limited by the maximum bandwidth that PI can handle.

When I copied a movie file from the file server to Windows 7 PC, the speed is about 50Mbps, which is about 6MB/s. It seems like 6MB/s as NAS is actually excellent compare to other people.

People say the bottleneck as NAS is on CPU due to NTFS-3G being inefficient. While it may be true that NTFS-3G is slow, it doesn't explain why I was getting only 6MB/s while HDD read speed is 30MB/s.

The point is that 30MB/s for HDD reading speed was after NTFS-3G and USB 2.0 bandwidth. Whatever performance of NTFS-3G or USB 2.0 was, I was getting 30MB/s after them.

I think the bottleneck is on the Ethernet port. It is working at 100Mbps not 10Mbps. Theoretically 100Mbps can give me 100Mbps at best, which is about 12MB/s. It means I can never get 30MB/s via wired network. Realistically 100Mbps will give me about half of the speed, which is 6MB/s, which is what I am getting.

For now, 6MB/s is fast enough for movie streaming or any other tasks and it works fine for me. But I think the throughput can be improved if I use USB wireless adapter; probably up to 15MB/s, because the maximum bandwidth, 30MB/s, will be shared by wifi card and HDD.

Raspberry PI overclocking failed. lol

Yesterday I tried overclocking Raspberry PI and the SD card was busted. lol. I properly rebooted the system and the file system was broken. It seems like overclocking and SD card doesn't go along well.

Also I installed "mini DLNA" and NFS, Network File System, for movie streaming. They works very well. I don't know exactly why but I am super exited about having my own NFS server; probably because I dreamed of having one at home since college. lol. It seems like people report that NFS works faster than Samba in terms of network performance.