Raspberry Pi – Techniques for optimizing your system
Pol, a reader of the site, contacted me to tell me about performance issues it encounters with his Raspberry Pi. The problem almost solved, He told me it might be an idea to talk about the tools and methods to optimize its Raspberry Pi.
Make a full article on the subject seems to me unrealistic. So I'll give the tools and methods that I use on my side. If you have others do not hesitate to share, I will update the article.
In tools installation, the limit of the ARM processor can quickly be waiting. A solution proposed by the Foundation is the overclock. As say you, I'm not a fan of this kind of method. I think always that if it consumes too much it is necessary to review how the app works rather than booster CPU. Nevertheless it is a possibility and in addition it is included in warranty (up to 1 GHz if I am not mistaken) !
The best way to overclock your Raspberry Pi It is with the raspi-config tool. Install by default on some distributions, If it is not present you simply use
apt-get install raspi-config
Choose the option 7 for the overclock then the frequency desired :
Another method is also already identify what will consume the resource. I use the classic : top. Installed as standard in our distributions, It will display the processes running and sort them according to certain criteria.
Here for example that the command returns on my server :
By default, the command will sort the programs by their CPU usage. You can change the sorting with the following shortcuts : ' f’ to select fields to display, then you move with the arrows. The SPACEBAR to display a field then ' s’ to use the field as default sort.
You can then quickly identify who does what, is your system really is on his knees, etc.
To know your memory occupation, You can use the command top as I mentioned a bit higher. Alternatively, you can use the free command that will give you your memory usage :
A way to recover a bit of memory is to reduce the RAM available to the GPU. Caution it will depend on the use of your machine. My server uses no GUI. The GPU is then not “useful” and I therefore decreased maximum RAM that is allocated.
To change this setting, You can update the value of gpu_mem in the file /boot/config.txt either through the tool raspi-config the menu Advanced Options then A3 :
Change the memory for the GPU to 1 MB it is possible ! So try and set the value according to your needs.
Another tool that can be useful is vmstat. Setting the number of seconds between each execution then the number of execution :
The disk access
Disk access can windows be a source of your performance. Yet, There also exists the simple means of controls.
But above all, one of the problems most often encountered is that the drivers. People add an external drive formatted in NTFS and ends up with very slow access. A simple way is to format the disk in ext4. Your CPU will tell you thanks !
Side tools, There are two main : iostat which gives statistics on inputs outputs disks. To install it :
apt - get install sysstat
With this tool you can see (among other) the volumes of Scriptures on a drive or partition :
And yet vmstat mode disk with the option ' p <partition>’ :
The result allows you to see the progression of readings and writings during the time of execution of the command
The log files
To see the traces of the system, There is a magical place : /var/log. You will find all traces of programs running on your system (for those generating in course).
You have on my test machine traces of the ftp server, MySQL, PHP. Anything that can help is to run-time errors, or alert messages. The command dmesg used to list the contents of one of these logs, which corresponds to the messages of the system itself since the boot and while running even when the device insertion/detection.
In these traces you can read technical information. Take the time to understand them by searching on Google or in the comments. You will learn many things about what goes on the back of the shop.
Monitoring of the machine
Monitor your machine at the time can also be a way to identify a source of problem, slowdown, memory loss, etc. For that you have different tools that can provide precise information. I'll let you read the articles on Monitorix or Zabbix.
Make here a list of the software best suited to Raspberry Pi would be totally subjective and utopian. Just a few tips before installing a tool :
- Is it really suitable for your use ? For example Citadel which is mail but that is heavy in installation server. Can be Postfix, much lighter, would be sufficient.
- Are there other alternatives that meet your need ? A well-known Web server (Yes Apache) can operate on Raspberry Pi. Yet there are other lighter alternatives like Lighttpd, Nginx and certainly others.
- Is it compatible with other tools that will be installed ? Some soft will install their own Web server for example while you already have one for another tool. Ditto for the DB with MySQL, SQLite, etc. The best known is not the best (pas de troll sur Windows ou Apple svp 🙂 )
- Is there a community supporting the tool ? Here it is for two reasons : the first is the help that you might find in the event of problems installing or configuring. The second is the security. In some cases install an exotic tool can save resources but will open doors to your system.
Voilà. If not give the answers, I hope that you now have ways to optimize your system. Do not hesitate to share your experiences and your tricks !