Building a 28-Core Raspberry Pi Cluster: A $500 Setup to Learn Docker


来自:机器之心
链接:https://ikarus.sg/how-i-built-kraken/



Coding, blogging, and building fun projects are common ways for developers to advance their skills. Many seasoned professionals have a habit of writing blogs, and their hands-on ability is beyond question.
Today, we introduce a machine learning enthusiast, WILL HO, who also enjoys blogging. He not only registered his own blog site but also built a 28-core Raspberry Pi cluster for self-hosting. During this process, he learned many skills, including Linux, Docker, Docker Swarm, Kubernetes, DNS, TLS, and network topology.
In his latest blog post, WILL HO introduces the 28-core Raspberry Pi cluster he built, named Kraken, which utilizes 7 Raspberry Pi 3B units.
As mentioned earlier, WILL HO built the Raspberry Pi cluster for self-hosting his blog site created with WordPress. WordPress is a blogging platform developed in PHP, allowing users to set up their own websites on servers that support PHP and MySQL databases, or use WordPress as a content management system.
Previously, he had also built a Raspberry Pi cluster named Octopi (one Raspberry Pi 1B+ and four Raspberry Pi 1B units), but he soon discovered significant performance bottlenecks when running WordPress on this cluster, with a new blog page taking about 10 seconds to load!
Building a 28-Core Raspberry Pi Cluster: A $500 Setup to Learn Docker
To solve this bottleneck, WILL HO decided to upgrade Octopi, leading to the star of our article today—Kraken. In the following sections, WILL HO describes the process of building Kraken. If you also have a need for building a Raspberry Pi cluster or want to learn tools like Docker, you can refer to the author’s method to set up your own cluster.
Overview of Kraken
Kraken consists of 7 Raspberry Pi 3B units powered by a USB charger. WILL HO initially planned to build a cluster with 8 nodes, but the maximum number of ports on consumer-grade network switches is 8, accommodating 7 nodes and one cable to the router.
Building a 28-Core Raspberry Pi Cluster: A $500 Setup to Learn Docker
Another option was to use a commercial-grade network switch with 16 ports, but that was clearly not feasible due to the price.
The specifications of the Kraken cluster built with Raspberry Pi 3B are shown in the table below:
Building a 28-Core Raspberry Pi Cluster: A $500 Setup to Learn Docker
The required parts list is shown in the table below:
Building a 28-Core Raspberry Pi Cluster: A $500 Setup to Learn Docker
It is worth noting that the author chose a 32GB MicroSD card as the storage for the first node, hoping it would become the master node for the Docker Swarm setup. The author anticipates needing additional storage space to build and deploy Docker images.
Building a 28-Core Raspberry Pi Cluster: A $500 Setup to Learn Docker
Kraken (top) and Octopi (bottom)
Gigabit Upgrade for Kraken
The author found that he often reached the 100Mbps bandwidth limit on the built-in Ethernet port of the Raspberry Pi 3B. During the transfer of large files, the transfer speed even hovered at a frustrating 8MB/sec.
Inspired by Jeff Geerling’s blog, the author discovered that using a USB Gigabit Ethernet adapter could increase the bandwidth to over 200Mbps. Thus, he bought a bunch of cheap USB Gigabit Ethernet adapters and a Gigabit switch to start the upgrade.
Building a 28-Core Raspberry Pi Cluster: A $500 Setup to Learn Docker
Cheap USB Gigabit Ethernet adapters.
Additional parts list:
Building a 28-Core Raspberry Pi Cluster: A $500 Setup to Learn Docker
After the upgrade, Kraken looks like this:
Building a 28-Core Raspberry Pi Cluster: A $500 Setup to Learn Docker
Gigabit Kraken, Octopi and my cable management nightmare
When all costs are accounted for, building this Kraken cluster totaled $508.84.
Benchmark Results
Running iperf before the upgrade, the maximum bandwidth was 93.1 Mbps.
~ ❯ iperf -c 192.168.3.11------------------------------------------------------------Client connecting to 192.168.3.11, TCP port 5001TCP window size:  129 KByte (default)------------------------------------------------------------[  4] local 192.168.3.71 port 57041 connected with 192.168.3.11 port 5001[ ID] Interval       Transfer     Bandwidth[  4]  0.0-10.0 sec   111 MBytes  93.1 Mbits/sec
After installing the Gigabit adapter and running iperf, the maximum bandwidth was 224 Mbps!
~ ❯ iperf -c 192.168.3.11------------------------------------------------------------Client connecting to 192.168.3.11, TCP port 5001TCP window size:  145 KByte (default)------------------------------------------------------------[  4] local 192.168.3.71 port 57298 connected with 192.168.3.11 port 5001[ ID] Interval       Transfer     Bandwidth[  4]  0.0-10.0 sec   268 MBytes   224 Mbits/sec
With this simple module, each node achieved a bandwidth of 131Mbps. However, these speeds are still theoretical, as typical use cases involve writing data received from the network to disk, whereas iperf only receives data from the network without writing it to disk.
Some Considerations
Even in web services, it is unlikely to fully utilize this new bandwidth continuously. It mainly helps to transfer large resources (such as image data) faster during the initial load, after which the user’s browser will cache the images.
Moreover, the infamous shared USB 2.0 bus among Raspberry Pi models 1 to 3 also limits actual bandwidth.
For uninitialized users, the theoretical unidirectional bandwidth of a single USB2.0 bus is 480Mbps, shared among the Ethernet port, SD card slot, and all USB ports.
The bandwidth distribution is as follows:
Building a 28-Core Raspberry Pi Cluster: A $500 Setup to Learn Docker
Although the numbers in the table may give the impression that this upgrade did not bring performance improvements, they represent the worst-case scenario. Typically, one expects to perform mostly read operations on a web server, with few write operations.
In the real world, bandwidth allocation is usually as follows:
Building a 28-Core Raspberry Pi Cluster: A $500 Setup to Learn Docker
The above is the author’s upgrade operation on the second Raspberry Pi cluster. However, if you are already familiar with the Docker system or are looking for a high-performance home setup, this tutorial is not recommended.
Why Choose This Cluster?
If you are interested in Docker and Kubernetes, the author strongly recommends setting up a cluster like this. He provides two reasons:
First, this cluster is compatible with the official supported latest version of Docker images. Additionally, the Raspberry Pi 3B runs on the armv7 CPU architecture. The latest Arm processors (arm64) are backward compatible with all code written and compiled on armv7. In contrast, arm64 processors are not backward compatible with armv6 processors (Raspberry Pi 1 and 2), which are being phased out by the community.
Second, this cluster is an ideal choice for most bandwidth-intensive applications, such as hosting your own blog, file synchronization services, media library management, note-taking applications, etc. Considering the USB 2.0 bus bottleneck in Raspberry Pi 3, if your application requires a lot of continuous writes (such as video encoding), the performance of this cluster may not meet the requirements.
In summary, building a Raspberry Pi 3 cluster is the most cost-effective way to learn Docker and clustering, and it will remain so for the foreseeable future. Therefore, if you just want to get familiar with Docker, it is highly recommended to give it a try.

Contact Liang Xu on WeChat

Add Liang Xu on WeChat to receive 3 sets of essential reading materials for programmers

→ Selected technical materials shared

→ High-level exchange community

Building a 28-Core Raspberry Pi Cluster: A $500 Setup to Learn Docker

All articles from this public account have been organized into a directory. Please reply with ‘m’ in the public account to get it!

Recommended Reading:

What are the differences between HarmonyOS and Android?

Hi: Please install this amazing plugin for both VSCode and IDEA

I ran the poetic code written by Lei Jun in 1994!

5T technology resources are being released! Including but not limited to: C/C++, Linux, Python, Java, PHP, Artificial Intelligence, Microcontrollers, Raspberry Pi, etc. Reply ‘1024’ in the public account to get it for free!

Building a 28-Core Raspberry Pi Cluster: A $500 Setup to Learn Docker

Leave a Comment