Many things have changed since I wrote my last Raspberry Pi Minecraft Server guide. OpenJDK is now the better supported Java for Raspberry Pi and Oracle is discontinuing support for Java 8 in January 2019. Java 9 is out and Java 10 is soon to follow. The Raspberry Pi 3B+ has also arrived! After testing the server on the new 3B+ using Java 9 I was blown away by the performance and decided to write an updated guide and a script that will have you up and running in minutes.
To give you a taste of how smooth the timings are in Java 9 OpenJDK headless using the Paper Spigot Minecraft Server here is a nearly 2 hour session I played with my girlfriend. This was played in survival mode on a brand new server so no blocks had been pregenerated and no settings were modified from the defaults. Nothing is overclocked except the SD card. There was even a village right by the spawn so many entities were in use. Here’s the timings output report:
RPI Minecraft Server Requirements:
- Raspberry Pi 3B+ (recommended) but any Raspberry Pi will work
- SanDisk Extreme 128GB Solid State Flash Drive (optional and meant to be used in place of SSD. This is the best choice for performance but can be pricey. For further explanation about the benefits see this article about MicroSD vs. Solid State on the Raspberry Pi)
- SanDisk Extreme 32GB MicroSD card (recommended as a cheaper alternative to solid state – $23 at time of writing) or other high performance storage options
- 2.5A Raspberry Pi 3B+ Designed Power Supply
- Raspbian Lite
Minecraft Server Setup Script
SSH into your Raspberry Pi and type/paste the following commands:
wget -O SetupMinecraft.sh https://raw.githubusercontent.com/TheRemote/RaspberryPiMinecraft/master/SetupMinecraft.sh chmod +x SetupMinecraft.sh ./SetupMinecraft.sh
… and we’re done! The Minecraft server is now in the folder “minecraft”. To start the server type:
cd minecraft ./start.sh
The server will start in the background using the screen application. To view the console type:
screen -r minecraft
From this console you can issue any command to the Minecraft server. The most important one you should know is the command to safely stop the server. This will save all players and states which is simply “stop” without the quotes. To get out of the console without closing the server press Ctrl+A and then Ctrl+D. This will minimize the screen session and put you back in your main console session. The screen session will continue to run even if you disconnect from your SSH session to your Pi!
Pi Specific Performance Optimizations: Storage and GPU Memory
The most important optimization you can make is high performance storage. Read my Raspberry Pi Storage Benchmarks article to see why some storage mediums are over 1000% faster for I/O which is the most critical factor for a Raspberry Pi Minecraft server. You can also use USB adapters for mSATA SSDs (cheap on eBay) or a USB to SATA cable if you have a 2.5″ older SSD.
If you are going to use MicroSD anyway you must use a high performance MicroSD card and overclock your SD card reader to obtain the best performance. It is normally 50hz to ensure compatibility with the cheap low quality cards but goes all the way up to 100hz. Storage speed is a major bottleneck on the Pi and this nearly doubles your read/write speeds. The second most important optimization is setting your GPU to only use 16mb of RAM. Since RAM is at a premium on the Pi it needs need as much as possible (64mb is used by default). This is all done in the Raspberry Pi’s /boot/config.txt file. Type:
sudo nano /boot/config.txt
Then place these lines at the bottom of your config.txt file:
Now restart your Pi using
That’s it! If your Pi won’t boot up after doing the SD card overclock don’t panic. Just put the SD card in any computer and remove the line dtparam=sd_overclock=100 from boot.txt. You can do it from Windows using notepad or any other text editor on any OS as the boot partition is always visible.
If you are using a older Raspberry Pi or a Raspberry Pi Zero then you may want to overclock it as well for smooth performance in game. My favorite guide for overclocking older Raspberry Pis is located at the one and only RetroPie project wiki page located here. The CPU and memory overclocking is going to be the most beneficial.
Minecraft Optimizations – The Timings Tool
If you are using an older Pi or have more than a few players using the server you may need to do some optimizations. The most important thing to understand about optimizing your Minecraft server is to understand what is slowing it down. There is an extremely useful tool built into the Paper Minecraft server called timings. In the intro to this post I posted a picture of the graphs from this report.
To start the timings measurements open up your Minecraft console with the screen -r minecraft command like I covered earlier. Once in the Minecraft console type:
The longer you take timings the better insight you will get into what is slowing down your server. It is best to play as you normally would when taking these timings so you are taking accurate measurements. To generate the report type the following:
This will give a link to paste in a web browser to view an incredibly detailed report.
Correctly Interpreting Timings
There are several different views available. It is important not to look only at the “Lag” category but also view the “All” category. If you only look at “Lag” you’re only seeing part of the picture. This is useful for identifying major “spikey” slowdowns but not the overall performance of the server. Check the “All” tab and toggle between total, average and count to understand how your server is performing.
In this example we can see some of the more expensive operations on my server are entities and chunks. Entities are monsters/animals/items/villagers/etc. Chunks are the map itself. If you are doing heavy exploring on a new server you may see very large numbers for chunks. This is due to the Pi generating them and storing them on the SD card (slow). If you are spending lots of time in villages or fighting monsters the entities may be high.
If you are not getting good performance and you have ran the timings tool here are some of the usual suspects to look for and possible optimizations to apply:
- Check config files – Configuration files are server.properties, paper.yml, spigot.yml, and bukkit.yml. If unsure about what a setting does google it or consult the documentation. If you screw up your configuration unintentionally then you can revert it to default by removing the file and relaunching the server.
- Lower your entity counts/ranges – Type nano bukkit.yml and in the file you will find spawn-limits: monsters: 70 animals: 15 and several others. You may lower these numbers to limit the number of entities by type. Type nano spigot.yml and you will find entity-activation-range and entity-tracking-range. These control how close you have to be before the server starts making monsters see/track you.
- Disable the Nether and The End – In server.properties. In the sample report you will see the Nether uses CPU cycles (we never went there). When/if your group is ready to go to the Nether you can turn it back on in the properties to re-enable it. You may disable “The End” in bukkit.yml by setting allow-end: false.
- Lower the view distance – This should be a last resort but on older Pi hardware or if you want more than a handful of players this is an option. It will increase performance dramatically because it reduces chunk loading/generation. Since chunk loading/unloading/generation is very I/O intensive the Pi is not very good at it. Change it in server.properties and spigot.yml.