Raspberry Pi Network and Performance Tweaks

hardware, linux, raspberry pi, workflow
Raspberry Pi Network and Performance Tweaks

In the last post, we bought the hardware, installed a minimal Raspbian OS, and set it up as a Synergy client. This time we'll improve the system's usability in terms of network settings and performance.

Show IP address on desktop

Using the lxsession reference page, we can see what we need to do.
First, create a file called showIP.sh in /home/pi

rm /home/pi/Desktop/*.IP
touch "/home/pi/Desktop/$(hostname -I).IP"

Allow anyone to execute this script: chmod +x /home/pi/showIP.sh

Then edit the auto-start file to display the IP on your X desktop:
sudo vim /etc/xdg/lxsession/LXDE-pi/autostart and add @/home/pi/showIP.sh to the end of the file.

Showing the IP on the desktop will allow you to access the machine without a hostname. This is important later, as we will optimize system load by disabling avahi-daemon.

Update IP upon network reconnection

You will need to add a post-up line in your /etc/network/interfaces to update the IP.post-up /home/pi/showIP.sh

Email with the Pi's updated IP

Install a SMTP mail utility: sudo apt-get install ssmtp.
Next, ensure you have a GMail password that does not contain spaces.

You can send the PI's IP to an email once ssmtp.conf is configured properly:

echo To: hi@cohesive.dev
echo From: ip.changed@cohesive.dev
echo Subject: RPi0 IP change
echo "IP changed to $(hostname -I) at $(date)"
} | ssmtp hi@cohesive.dev

I've added this command to the showIP.sh script on my own RPi0.

Using public-key security instead of passwords

We recommend a brief skim of this simple guide on how to set up your client / host to use SSH keys instead of entering a password for every SSH connection. Doing this minimizes the risk of exposing your Pi's password and also the amount of typing required to gain SSH access.

Using Ansible to automate Synergy reinitialization

After completing, we can use Ansible to automate re-initializing the Synergy client on the Pi. Consolidating all these steps:

  1. Find the IP of the main computer (Synergy Host)
  2. SSH into the Pi (Synergy Client)
  3. Run sudo ~/initSynergy.sh <SYNERGY-HOST-IP>
  4. Exit SSH

Into a single Ansible playbook: initSynergy.yml which can be run with

ANSIBLE_PIPELINING=True ansible-playbook initSynergy.yml -i hosts --extra-vars "hostIP=$(getSynergyHostIP.sh)"

Performance tweaks

It is important to kill memory hogs and high CPU background services as well as anything you are not / will not be using when running Raspbian. Any savings in those areas will have significant impact on your daily user experience.

  • Disable Bluetooth background services if not using any Bluetooth devices
    systemctl disable bluetooth
    systemctl stop bluetooth
  • Disable avahi-daemon if you can accept managing IPs of your network resources. Avahi provides human-friendly hostnames (e.g. raspberrypi.local) via Bonjour / Zeroconf.
    systemctl disable avahi-daemon
    systemctl stop avahi-daemon
Removing this has the largest impact on CPU load on the lower spec Raspberry Pi models. You can expect an idle CPU usage reduction from 30% down to ~1%.
  • Disable TriggerHappy: if the Pi isn't being used with any custom hardware buttons (e.g. power button) you won't need this service.
    systemctl disable triggerhappy
    systemctl stop triggerhappy

In the final post of the series, we'll look at lightweight replacements for common desktop apps that you can run on your new Raspbian installation.

Ensure peak performance

Cohesive.dev provide comprehensive software, operating environment, and network configuration audits. We can help you keep your computing resources working smoothly, and reliably.