Tag Archives: lighttpd

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?

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.