Creating a cluster of Raspberry Pis undoubtably looks cool. If you are looking for an excuse to create a cluster but aren't quite sure what you could actually do with it, here is a quick run down of some of the reasons you might want to create a cluster of Pis.

Performance

This is probably what most people think of first. However whether or not you will get any performance benefit from a cluster depends on your use case. If you are using your Raspberry Pi as a desktop computer and you feel it is a bit sluggish browsing the web, clustering won't help you.

On the other hand if you need to batch process 100s of images then a cluster of Pis will allow you to process multiple at the same time. So whilst each image won't process any quicker, the overall time taken will be reduced in proportion to the number of Pis in your cluster.

Similarly, if you are hosting a web site, you could use a load balancer to distribute requests across multiple web servers running across a number of Pis. Again, the time taken for a single request to be processed won't be improved but you will be able to process multiple requests simultaneously. So if you have a number of clients trying to access your site at the same time, this will reduce the time spent by each client waiting for other client's requests to finish processing.

So whilst you can use a cluster to improve performance, it only applies in certain circumstances, specifically when you have a number of discrete jobs that can be run in parallel.

Resilience

This the reason that prompted me to explore running a cluster of Pis. When I first started using a Pi for home automation, I had an SD card fail which seems to be a fairly common occurance. All of my automation was out of action until I re-installed all the software and got everything back up and running. This led me to explore high availability options for home automation. I ended up going with a solution based on the High Availability Home Assistant project.

This means that now if a Pi fails, the services it was running are re-distributed accross the remaining Pis. I can swap out the SD card and put the node back in the cluster. There is no outage for my home automation.

Ease of management

One way of using a cluster is to make use of something like Docker Swarm or Kubernetes to deploy services across the cluster.

Imagine you have 3 Pis to use for your Home Automation setup. A typical home automation setup might be running things like:

  • Home Assistant
  • Node-RED
  • an MQTT broker such as mosquitto
  • Influx DB
  • Grafana

And the kind of person running this setup probably has a few other related applications to run as well such as:

  • Pihole
  • Nginx or Apache

How do you decide which applications to run on which Pi? Does it matter? Do you even care? Probably not.

By running these services as containers and deploying them using Docker Swarm or Kubernetes, you don't need to decide. Even better they run independently so you can easily start and stop different services independently. You also only need a minimal set of dependencies installed (eg just docker in the case of Docker Swarm). Everything else is managed via the containers so no need to worry about things like upgrading app A breaking app B.

Summary

So to summarise, you can use a Pi cluster to increase performance for specific use cases but from the point of view of the Home Automation enthusiast, the resilience and ease of management aspects are the really exciting part.

If you want to get started, I recommend checking out out the HAHA project, particularly if you are already using Home Assistant.