The Raspberry Pi 4 was released and it has finally enough memory to run Chromium effectively. With the addition of an USB 3.0 controller, this little board can now run programs off an external SSD really fast. However, for anything other than a desktop replacement, this upgrade may prove quite expensive relative to the Pi’s price.
Since most of the Pi’s I know live in a secluded place having no monitors or keyboards attached and will execute a single codebase for their entire lifespan, it’s more important that this code loads up fast and runs smoothly.
In this writeup I will be benchmarking the loading time for Chromium on the latest Raspbian release and try to beat the 3.3 second loading time in the Tom’s Hardware article presented above.
Benchmark setup
Since Chromium is probably the most used application on the Pi, I’ll use that as a gold standard for this test. Real life Python and Node.JS applications may benefit even more from this kind of acceleration since they store lots of files.
Measuring the startup time for Chromium is performed using puppeteer APIs from Node.JS. Two loading characteristics were recorded, one for browser startup and the other for opening up a local page. Since the majority of Linux based systems cache frequently used applications, the OS cache was cleared after every test iteration.
Components
- Raspberry Pi 4 with 4GB RAM running Raspbian Buster
- A SanDisk Extreme 32GB microSDHC UHS-I U3 card
- Cheap heatsinks to prevent thermal throttling
- Puppeteer and Node.JS v10.x for running the benchmarking script
Benchmark results
Using a RAM disk effectively halves the loading time of Chromium, reducing the loading time to about 1.8 seconds.
Setting up the RAM Partition
Start by creating the RAM drive folder and editing the fstab file.
sudo mkdir /var/bench sudo chmod 775 /var/bench sudo nano /etc/fstab
Add the next line with the necessarry space requirements for your application. In this case, 512MB would be enough.
tmpfs /var/bench tmpfs nodev,nosuid,size=512M 0 0
Mount the partitions using the following command.
sudo mount -a
The RAM drive is now mounted and ready to be used. You can check its status using the df -h command. Copy the Chromium browser to the RAM partition.
sudo mkdir /var/bench/chromium-browser sudo cp -r /usr/lib/chromium-browser/* /var/bench/chromium-browser
Running the benchmark
Clone this GitHub repository.
git clone https://github.com/cristidbr/pi4_bench.git
Install dependencies
sudo apt-get install nodejs npm -y npm install --global puppeteer
Call the benchmark script using
node benchmark.js --runs 100
Conclusions
The RAM partition proved really effective for speeding up applications, being only 9% slower than direct OS caching. When running large apps (Node.JS or Python) which load multiple small files over and over again in memory, it’s really useful to have a RAM partition on hand. Also, this technique can be used to reduce the wear and tear of the SD card which is always a plus.
That’s why the memory upgrade on the new Raspberry Pi 4 is such a big deal.