Category Archives: Linux

What performs better on a RasPi: Apache, Lighttpd or Nginx?

As I’m hosting my blog on a Raspberry Pi, I did some research on the web about it’s performance as a server. I started this site with Apache and migrated after a while to Lighttpd which already reduced server response time (3.6 seconds, according to Google’s PageSpeed Insights it reached 72/100 points) and improved performance. With an DSL upload speed of only 676 kbit/s one shouldn’t expect miracles anyway. Google’s PageSpeed results, which suggested to make a couple of changes to my site, and a comparison of Lighttpd vs. Nginx convinced me to migrate to Nginx.

Continue reading What performs better on a RasPi: Apache, Lighttpd or Nginx?

Connecting a DS18S20 temperature sensor to RasPi

I’ve been a little reluctant to connect a DS18S20 temperature sensor to my RasPi, since there were rumors that the w1_gpio.ko kernel module exclusively requires a connection to GPIO #4, because of being hard coded. At least that’s what Lady Ada’s tutorial says about it and what one can read in several user forums. Unfortunately GPIO #4 was already occupied on my Pi. Therefore I searched through several Blogs for advice how to change the hard-coded GPIO in the kernel module. It turned out that I wasn’t the only one – so here’s the good news: In Raspbian Wheezy with Kernel 3.10.25+ it is possible to pass the desired GPIO in /boot/cmdline.txt to the kernel using the option:

bcm2708.w1_gpio_pin=<GPIO#>

To be able to read temperatures from the sensor, modprobe the wire, w1_gpio and w1_therm kernel modules. The temperature can be read from /sys/bus/w1/devices/<device_serial_number>/w1_slave.

I’m using the the sensor for outdoor temperature measurement. I soldered about 1 m wire to the sensor (TO92 housing), insulated the solder joints with heat shrink tube and embedded the sensor into an old metal ballpoint cap using epoxy glue.

WiFi trouble with smsc95xx

In the /var/log/messages file of my Raspberry Pi, which is connected through WiFi to my home WLAN, I repeatedly noticed this error message:

smsc95xx 1-1.1:1.0 eth0: unexpected urb length 0

Furthermore, I got “no route to host” messages when attempting to ssh to my  RasPi. At the same time I couldn’t connect to lighttpd. Some research with Google suggested, that there might be a problem with the USB driver. Symptoms are characterized by fluctuating transfer rates and response times as well as bad WiFi connection quality leading to delayed keyboard response or garbled input when using ssh. Fortunately, there is a  workaround:

Continue reading WiFi trouble with smsc95xx

RasPi lighttpd and server tweaks

This blog is hosted on a Raspberry Pi using the lighttpd (lighty) webserver. Since I haven’t been satisfied with the response time until a page is loaded, I applied some tweaks to increase its performance.

If you need details about your RasPi server, you can test it’s performance with Google’s online PageSpeed Insight tool. Then, follow the recommendations of the analysis results.

Most important for a good WordPress performance appears to be  CSS and Javascript concatenation/compression as well as installation of a cache plugin, such as Autoptimize and WP-Cache.com.

/boot/cmdline.txt, /etc/fstab

Although I use an “ultra” Sony Class 10 (94 MB/s) SD card, performance of the ext4 journaling file system has been an issue. To increase file system throughput, I added:

rootflags=commit=120,data=writeback

to /etc/cmdline.txt, and:

/dev/mmcblk0p2  /  ext4  defaults,noatime,nodiratime,barrier=0

to /etc/fstab. These options disable storing of access times to the file system. Using data=writeback mode extends the time from when a file is written to when it is pushed out to disk to 120 seconds. Be aware that you’ll lose all cached data on a file system crash!

/etc/sysctl.conf

To tell the system to use less IO/RAM, I placed these options into my /etc/sysctl.conf

vm.dirty_background_ratio = 20
vm.dirty_expire_centisecs = 0
vm.dirty_ratio = 80
vm.dirty_writeback_centisecs = 1200
vm.overcommit_ratio = 2
vm.laptop_mode = 5
vm.swappiness = 10

/etc/lighttpd/lighttpd.conf

Disabling keep-alive might help lighttpd if it suffers from a large number of open file descriptors. Select an event handler which takes care of notifying the server that one of the connections is ready to send or receive.

Since we want to send out a file from the webserver, it doesn’t make any sense to copy the file into the webserver just to write it back into a socket in the next step. Therefore, we enable linux-sendfile to minimize the work in the application and push the file directly into the network card.

With the help of gamin (sudo apt-get install gamin) you can use kernel events to assure that your stat cache is up to date.

server.max-keep-alive-requests = 0
server.event-handler = "linux-sysepoll"
server.network-backend = "linux-sendfile"
server.max-fds = 1024
server.stat-cache-engine = "fam"
server.max-worker = 0

After applying these tweaks, lighty responds much faster and I observed less “The site could be temporarily unavailable or too busy. Try again in a few moments.” messages.

Adding podcasts to MPD using castget

In order to play mp3 files on my RasPi, I’ve installed the Music Player Daemon (MPD). Music playback can be controlled with Mozilla Firefox using the Minion plugin. By placing *.m3u files into MPDs’ playlists folder, as configured in /etc/mpd.conf, it is possible to listen to internet radio streams.

Unfortunately, subscription to podcasts is not directly supported by MPD. However there’s a way to automatically download podcasts to MPD’s mp3 directory using a program called castget. It’s not in the Wheezy repo. Thus, it must be compiled from source:

$ ./configure --prefix=/usr
$ make
$ make install

To build castget, make sure to have the glib2, libxml2, libcurl and id3lib development packages installed on your Pi. Castget is using a default ./castgetrc in /home/pi for configuration, but one can point it to a different location by using the –rcfile=/etc/castgetrc flag. The castget tarball provides a sample configuration file.

# Global settings.
[*]
id3contenttype=Podcast
spool=/media/usb/podcasts

# Per-channel settings.
[dsc]
url=http://www.deutschlandfunk.de/podcast-computer-und-kommunikation-komplette-sendung.416.de.podcast.xml
playlist=/var/lib/mpd/playlists/Computer_u_Kommunikation.m3u

[dsc]
url=http://www.deutschlandradiokultur.de/podcast-reportage.948.de.podcast.xml
playlist=/var/lib/mpd/playlists/Deutschland_Reportage.m3u

All you need to do is to define a spool directory for downloading the podcasts, to enter the URLs of the podcast’s RSS feeds and to tell castget where to store the playlist.m3u files (must be the the same directory as defined in /etc/mpd.conf).

To automatically check and download new podcasts each 24 hours at 02:00 am, I placed a new line into my /etc/crontab

 0  2    * * *   root    /usr/bin/castget -r --rcfile=/etc/castgetrc

If the download was successful, new podcasts should appear in Minion’s playlists tab.