Timely tips for speeding up your Raspberry Pi

Lead Image © realmccoy, 123RF.com

Tune Time

The Raspberry Pi is small and economical but also fairly limited for resources. A few targeted tuning steps might help you gain better performance.

Raspberry Pi is perfectly suited for hosting your own web projects, but more complex applications can make the tiny Pi break a sweat. Recently, I tried to set up my Pi with the private cloud app ownCloud [1], and the sluggish performance prompted me to investigate the options for performance tuning on the Raspberry Pi. I was able to complete the ownCloud installation, but the response times were intolerable. I knew I needed to find some performance tweaks somewhere.

With performance problems of this kind, regardless of the hardware platform, the best strategy is always: measure, change, and measure again.

Measure, Measure, Measure

When beset by performance problems, experienced Linux users will turn to the top utility, which outputs information about the current system load. Open a terminal window and type top. The top command displays the processes running on the system and the amount of system resources each process is consuming. A summary at the top displays the overall system load.

As you can see in Figure 1, the overall %CPU usage is up to 98.1. CPU load usually isn't a problem, but if you are consistently seeing high values for the %CPU, you actually need a faster CPU.

Figure 1: In the case of high CPU load, a faster processor could eliminate the problem, but …

Things look different in Figure 2, where the wa ("wait") value is very high. In Figure 2, the CPU is waiting for data from a storage medium and twiddling its thumbs in the meantime. A faster processor would do nothing but twiddle through even more cycles.

Figure 2: … if you have a high value for "wait," a more powerful CPU would just wait faster for data.

top provides important evidence, but only for the current status. Sophisticated monitoring programs, however, regularly record the status of various readings and can thus provide historical data. This record saves you from having to keep an eye on the window with the top output during your tests.

Ganglia [2] is a useful monitoring tool for working with the Raspberry Pi. Although Ganglia is suitable for performance monitoring in clusters, it can also handle single computers. On Raspbian, you only need to set up Ganglia packages; the configuration work is minimal. (See the box titled "Installing Ganglia.") If you do not need graphical analysis, install the sysstat package instead of Ganglia. Sysstat includes a component that collects the measured values in the background. The sar command displays the results in the terminal. The Sysstat package also contains iostat, with which you can measure the read and write performance of your storage.

Installing Ganglia

Ganglia [2] only needs the ganglia-monitor and gmetad packages. If you want to use the web front end (ganglia-webfrontend), you'll need a working PHP installation and a web server. The setup you get through the apt-get package manager not only installs PHP itself, but also the full Apache stack on your Rasp Pi. On a lightweight system like the Raspberry Pi, you're better off with a lightweight web server, such as lighttpd, rather than the bloated Apache. To keep things lean, first install lighttpd, then PHP, and finally the web front end for Ganglia. Listing 1 shows the necessary commands. The last command in the listing links the web front end into the file tree that lighttpd delivers. Following this series of commands, you can access Ganglia on http://<host_name>|<IP_address>/ganglia/.

Listing 1

Setting Up Ganglia on the Pi

# apt-get install lighttpd
# apt-get install php5-cgi php-apc
# lighttpd-enable-mod fastcgi-php
# service lighttpd force-reload
# apt-get install ganglia-webfrontend
# ln -s /usr/share/ganglia-webfrontend /var/www/ganglia

Additionally, you still need programs that generate loads on the system for testing. Ideally, you will choose programs that come close to your application. Alternatively, various benchmark programs can specifically generate load on individual components, such as the CPU or storage, but the results are a little artificial. These programs (such as the famous Linpack benchmark for floating point performance, or Bonnie++ for I/O performance) output the readings for a before and after comparison.

USB Gives You Wings

The root of all evil in Rasp Pi operations surprisingly turns out to be the power supply. The Rasp Pi is supplied with power through a micro-USB connector and requires a relatively constant 5 volts and at least 700mAh. However, some USB power adapters deliver 500mAh and thus simulate a PC connection. Others have two jacks, which ostensibly deliver 2,100mAh per jack, although the total output of the power supply is only 3,600mAh. These charger power supplies reduce the voltage as the current draw drops, which makes sense for (nearly) charged tablets or smartphones, but it's a problem for the Raspberry Pi.

The power supplied through the micro-USB goes to the CPU, GPU, and all USB components – in particular, to the network chip. The Rasp Pi's maximum power draw is approximately 1,100mAh. You always need to consider this in all of the following tuning steps. Additionally, in normal mode, instability or errors writing to the SD card would suggest a defective power supply.

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content