Upgrading my Raspberry Pi minecraft server

I thought this would only take a few minutes...
gaming linux pi

update 200203 I have since moved this server to an old Dell Optiplex 3020m (Intel i5-4590T 2.0GHz with 8GB Ram) under Ubuntu 18.04 LTS which runs 1.13.2 spigot without issue. The Raspberry Pi was sufficient for 1.12.2 (with occassional lag) but after upgrading to 1.13.2 it was essentially unplayable.

ORIGINAL POST FOLLOWS:

I had some extra cash left on a gift card so I decided to get a Raspberry Pi 3B+ (RP3B+) and try to upgrade my tiny minecraft server. That's right - I'm running a minecraft server on a pi. When I first set up my minecraft server for the kids in 2013, I had it running on a spare server in an actual server room. This was ideal of course but eventually I had to remove it from that location. Running it on a consumer grade PC was still acceptable given there was never more than maybe 4 players at a time on it but I didn't like leaving a PC running all the time just for minecraft, and it always ended up being off when we wanted to use it. There's more detail in this blog post, but in 2016 I managed to get minecraft installed and running on a Raspberry Pi2. It was about as good as you might imagine - barely able to keep up even with every possible setting tweaked to help it. When I upgraded to a Raspberry Pi3 (RP3) things improved greatly, but lag was still a problem and the log file would get spammed with errors about not being able to keep up. I hoped this new RP3B+ would be just fast enough to do the job.

The idea was that I'd just be able to swap the microSD card from the RP3 over to the RP3B+ and boot it up. This didn't work. I was still running jessie on the 3 and that could not run on the 3B+ so I decided to upgrade first, then swap the card. The upgrade went well and I checked to make sure the server was still running (it was) then swapped the card. Same problem - the RP3B+ would boot to the rainbow screen and get no further. I was pretty disheartened since setting up the minecraft server again seemed a bit daunting. I decided I'd get the RP3B+ running with a newer version of Raspbian and then decide if I wanted to move the server over to it.

I downloaded Rasbian Stretch Lite (which is Raspbian without all the desktop stuff) and wrote it to a spare 16GB microSD card with Etcher. This booted right up in the RP3B+. There was some annoyance trying to get openssh-server to run - I ended up having to create an empty file called "ssh" in /boot to make it magically work so I could stop cursing about it.

Then I stuck my RP3 card into my laptop and tarred up the 4GB of minecraft server files and rsynced them over to the RP3B+. I knew I had to install Java of some kind because at least in the Lite version java is not included. I won't go through the horrible mess I ended up in trying to get some kind of java installed because it was probably my own fault but suffice to say it took a lot longer to straighten it out than it did to break it. With java installed (I'm using openjdk 9-Raspbian) I was able to build a new version of the server.jar file.

update 190330 there were just so many glitches happening when dynmap was enabled that I decided to install Oracle java today. I found oracle-java8-jdk in the repos for stretch so I installed that. Then I switched to it using: sudo update-java-alternatives -s jdk-8-oracle-arm32-vfp-hflt (I found this arcane program name by looking in /usr/lib/jvm).

Anidees

I was tired of the cheap plastic case I've used for years and looked around for a good long time to find something better. There are a huge number of cases available, but I settled on an aluminum case by Anidees model AI-PI-SG-Plus which comes with a nice thick lucite top. The case fits the RB3B+ perfectly, and the provided allen head screws hold the board snugly in place inside, and don't get in the way of the GPIO pin header like some others I saw - just in case I want to run a cable out of it some day to do another project with it. As you can see in the picture I only have an ethernet and power cables connected because once Raspbian and openssh-server was installed, I can manage it via ssh from any machine so the pi just runs "headless".

I did a couple tests, first to check the temperature:

pi@mc:~ $ sudo vcgencmd measure_temp
temp=49.4'C

note: after running around in the world, and using dynmap subsequent tests showed as high as 53.7 degrees C.

To test the speed of the SD card (which sadly, on the Pi is limited to 20 MB/s databus) - after CPU speed, I suspect disk I/O to be my big problem with the minecraft server performance at this point.

pi@mc:~ $ sudo hdparm -tT /dev/mmcblk0

/dev/mmcblk0:
 Timing cached reads:   1388 MB in  2.00 seconds = 693.88 MB/sec
 Timing buffered disk reads:  68 MB in  3.03 seconds =  22.46 MB/sec
pi@mc:~ $ sudo hdparm -tT /dev/mmcblk0

/dev/mmcblk0:
 Timing cached reads:   1406 MB in  2.00 seconds = 702.44 MB/sec
 Timing buffered disk reads:  68 MB in  3.03 seconds =  22.47 MB/sec

update 190330 In an attempt to get the server running smoother, I disabled bluetooth and its services which I'm not using hoping to free up a tiny bit more memory by following this guide. Then I made a tweak to the script I use to start the server. Previously I had only specified an -xMx setting but after reading this guide I decided to try setting -xMs as well. I also reduced -xMx to the figure provided there. After reading about Garbage collection in Java here I decided against using -xMs and changed the GC I was using. My script now looks like this:

screen -dmS minecraft java -Xmx1008M -XX:+UseG1GC -jar /home/pi/bin/server/server.jar nogui

For years I ran Minecraft using Craftbukkit until Mojang was sold to Microsoft causing a cascade of issues related to the rights of third party open source developers for Minecraft plugins. It could reasonably be argued that these third party developers were the sole reason Minecraft ever became popular enough that Mojang could be sold to anyone in the first place, but in the aftermath many of them just disappeared. Thankfully, the folks at SpigotMC kept the flame alive and continued to provide a way to build a minecraft server which would allow for customizable plugins. Using Spigotmc's awesome BuildTools I was able to keep the server up to date for years and have the few plugins I wanted actually work. I've read that Minecraft 1.13 will not work well (if at all) on the pi yet and I was worried about messing up my world so for now I've decided to stay running 1.12.2.

Once the server file was built and linked up, my initial test showed that I had some issues with plugins related to the version of java I was using (which was different from the one I had used on the RP3), so I ended up downloading newer versions of those plugins and testing each one at a time (watching the logs at boot). I also had to call my start up script from rc.local again (I hever set up a decent service for it as I had originally intended) and then the tweaking began!

Fine tuning of the server involved a whole lot of running around in-world mining stuff, killing skeletons, etc. between configuration file edits. I eventually switched over to using the spigot build instead of craftbukkit (BuildTools builds compatible versions of each) but since spigot is really just a higher performance version of craftbukkit anyway there really wasn't any downside. Performance is only marginally better than it was on the RP3. Its perfectly playable, but chunks sometimes take a few seconds to load when you're racing around in a boat, fast walking, or riding in a powered minecart.

Errors show up in the log for these events: "moved too quickly!" or "moved wrongly" messages mainly. I'm not sure, but I think one of the major impacts on performance is that I refuse to stop using dynmap. Dynmap is a brilliant plugin which builds a Google Map of your world and updates in real-time where players are on the map. I'm guessing that it is this awesome mapping feature which is causing the bulk of my problems since when it is disabled I haven't noticed any lag. For now I'm going to keep it enabled because its just too awesome.

The Raspberry Pi can certainly run a tiny spigotmc-based Minecraft server with a couple plugins and provide a persistent shared world for a few players at a time with only minimal power requirements, but if you're looking for serious gaming performance this ain't it. Expect your raspberry pi based server to lag occassionally and especially if you use demanding plugins.

Previous Post Next Post