Machine Learning Engineer
Valheim is all the rage these days, surpassing even Dota 2 with 500K peak players on February 21st, 2020 and crossing its 6 million sales mark just a few days back. As much as I'd like to proclaim myself as a non-conformist, I'm ashamed to say that I too, succumbed to Valheim's mysterious allure.
I picked up this game just over 3 weeks ago and the first thing I did, given my obsession with self-hosting, was to find the most cost-efficient way to host a dedicated server for it.
Disclaimer: I'm neither affiliated with nor sponsored by Radxa/Allnet, the manufacturer/distributor of the Rock Pi X. I bought the Rock Pi X with my own money and I'm writing purely to share my experience of running a dedicated server on it.
In case you've been living under a rock, Valheim is currently the hottest survival sandbox game on the market developed by the Swedish developer, Iron Gate Studios, comprising of a team of just 5 people. Valheim's peak players statistics on Steam at one point was second only to Counter Strike: Global Offensive (CS:GO), which is very impressive given that it's only in Early Access and has only been released for slightly over a month then.
Valheim bears a striking similarity with Minecraft and other similar sandbox games and because of that, shares the same reasons behind why a dedicated server is a crucial addition to the gaming experience.
To start the game, the player must first generate a world before creating a character which then joins this newly-generated world. A world, when loaded by the player's computer (host) and configured to be open to other players, is then functionally equivalent to a server. Multiplayer is achieved by inviting other players to join the game. Players may join directly by IP address or via Steam's friends list.
This model makes perfect sense for a sandbox game as the very definition of a sandbox implies isolation from outside influences, with each player generating their own world and/or joining other worlds. Without isolation Valheim is not much different from your typical MMORPG.
The only catch here is that when the host quits the game, all other players in the server are immediately disconnected and will not be able to rejoin the same world unless the host is online and in game. This makes for a less than fun experience, especially given that it is getting increasingly difficult to find a common time slot among friends to play together with the unpredictability of work schedules during these uncertain times brought about by none other than our best friend, COVID-19.
Asynchronous collective progress
With a dedicated server, players can decouple their gaming schedules from each other, and play whenever they want and still contribute to the collective progress of a shared world. For example, I can just enter the game and dedicate an hour just to chop down an entire forest of trees for the sole purpose of relieving stress and yet in doing so, I can use the wood obtained to replenish the stockpile at base which was used earlier for building walls.
This element of asynchronous collective progress, in my opinion, is what makes Valheim really fun and probably one of the main reasons behind Valheim's meteoric success thus far. It takes the stress of coordinating schedules among friends away from the game and gives each player the opportunity to still play as a team, even if no one could agree on a time to play together.
Another benefit is that the dedicated server decouples the performance of the server from the performance of your computer. For instance, if you happen to have a less than average computer, hosting a Valheim game may result in other players bottlenecking at your computer's network connection or CPU resources.
With a dedicated server, your computer is now freed of the burden of computing world changes for other players just needs to focus on your game experience. On top of all that, the enjoyment of all other players won't be diminished when you are experiencing performance issues.
Though that is still not a valid excuse for not getting a better-specced computer, but at the very least whenever there seems to be some lag with the dedicated server, you can now share the pain with the other players and pin the blame on the server. 😂
Regardless of whether you are a solo-player or prefer multiplayer with friends, disaster-recovery is an important aspect of every service that's at least semi-critical. Imagine putting in ~2 hours a day per player, in a server of 6 people, building a base, a dock, a castle, accumulating resources, all over several weeks, only to lose all that progress when the host's computer dies. That's easily 180 man-hours lost!
With a dedicated server, depending on the implementation that you choose to deploy, one can schedule backups of the game world, and at any time, restore the state of the world to a specific backup. Personally, I schedule backups every 15 minutes, so that the maximum loss of is limited to 15 minutes, and I keep the backups for up to 24 hours, just in case something goes horribly wrong.
With all that talking out of the way, let's get down to the setup itself!
None other than the Rock Pi X!
Specs for the Rock Pi X
| Aspect | Rock Pi X | |----------|----------------------------------------------| | CPU | Intel Atom x5-Z8300 Cherry Trail (Quad core) | | Cores | 4x 1.44GHz with Turbo Boost to 1.84GHz | | Memory | 4GB LPDDR3-3200 | | Ethernet | Gigabit | | Storage | eMMC (32GB/64GB) | | USB | - 1x USB 3.0 (OTG/Host) | | | - 3x USB 2.0 | | Power | USB-PD |
The Rock Pi X comes with a soldered-on eMMC module, which is a departure from its typical modular eMMC on its arm64 sister product, the Rock Pi 4, but it is a tradeoff that has to be made as the BIOS does not like the storage being swapped out.
Overall, here's what the cost of the entire setup looks like:
| Item | Cost (SGD) | Cost (USD)* | |------------------------|------------|-------------| | Rock Pi X (32GB eMMC) | S$100.86 | US$75.00 | | Heatsink | S$10.75 | US$7.99 | | 45W USB-PD Power Brick | S$10.75 | US$7.99 | | USB-C to USB-C Cable | S$6.71 | US$4.99 | | Shipping | S$17.55 | US$13.04 | | Total | *S$146.60* | *US$109.01* | * SGD/USD exchange rate is 0.746268 as of the time of writing
And this is what the final setup looks like, with the old cluster rack case.
I chose the Rock Pi X as it is the cheapest amd64/x86 Single-board computer (SBC) on the market with storage and memory included. I did take a look at the ODROID H2+ but beside the fact that it's perpetually out of stock, it costs quite a bit more with all components included. In fact, the total cost of an Odroid H2+ setup is enough to buy myself 2 Rock Pi X setups!
If you're still unconvinced, here's the cost breakdown for an Odroid H2+:
| Item | Cost (SGD) | Cost (USD)* | |-----------------------|------------|-------------| | Odroid H2+ | S$158.58 | US$118.00 | | 15V 4A Power Supply | S$12.63 | US$9.40 | | Samsung 8GB SO-DIMM | S$48.38 | US$36.00 | | Samsung 8GB SO-DIMM | S$48.38 | US$36.00 | | ^Shipping | S$40.32 | US$30 | | Samsung 960 Evo 250GB | S$63.00 | US$46.88 | | Total | *S$371.30* | *US$276.28* | * SGD/USD exchange rate is 0.746268 as of the time of writing ^ This shipping costs WAY too much in my opinion
Another reason why I chose the Rock Pi X is its size. The Rock Pi X, unlike many x86 SBCs, adopts the Raspberry Pi form factor, which saves a ton of space. As an added bonus, the form factor means that it fits in my old GeauxRobot Raspberry Pi cluster case, recycled from my old retired cluster, the Octopi.
I know, I know, by now you must be wondering why didn't I just go for cloud VMs?
I did consider the option of running Valheim on a cloud virtual machine but it turned out to be pretty pricey as well.
Based on the experiences of Redditors in r/valheim, it appears that the dedicated server requires at least 2 vCPU and 3GB RAM. I searched across the 3 major cloud service providers for the best prices available and the table below shows what I've found.
| Item | AWS | Azure | GCP | |----------------------|-----------------------|------------------------|------------------------| | Instance Type | t4g.medium | A2 v2 | e2-custom-2-4096 | | vCPUs | 2 | 2 | 2 | | Memory | 4 GiB | 4 GiB | 4 GiB | | Instance Class | Spot | Low Priority | Preemptible | | **Compute Subtotal** | **US$9.29 (S$12.49)** | **US$13.87 (S$18.65)** | **US$16.41 (S$22.07)** | | Storage Type | EBS SSD (gp2) | Standard SSD | Zonal standard PD | | Storage Capacity | 32GiB | 32GiB | 32GiB | | Storage Subtotal | *US$3.84 (S$5.16)* | *US$2.40 (S$3.23)* | *US$1.41 (S$1.90)* | | Monthly Total | *US$13.13 (S$17.66)* | *US$16.27 (S$21.88)* | *US$17.82 (S$23.96)* | * SGD/USD exchange rate is 0.746268 as of the time of writing
Note that the prices above exclude any disk snapshot costs, where snapshots are used to recover your data should there be catastrophic data corruption or loss. This exposes you to additional risk of losing all the progress in the world you and your friends collectively built.
In an attempt to further reduce the cost of the VMs, I've even lowered the virtual machine's instance class to Spot/Low Priority/Preemptible, depending on the cloud provider, but they all mean the same thing:
You are sold leftover compute capacity of physical servers that nobody really wants to buy, at a deep discount (~70%).
However, at any point in time, if the leftover capacity is no longer available, your VM will be terminated to give way to users who pay the full-price for the compute capacity.
This means, in exchange for a discount, you pay in terms of uncertainty of the availability of your servers. For a dedicated game server it's generally fine, though it is rather concerning as Valheim saves at 20-minute intervals, so if your VM terminates while you and your friends are playing, you may stand to lose up to 20 minutes of progress, which may sound trivial but will turn out to be rather frustrating if it happens frequently.
From the table above, we can see that AWS offers the cheapest VMs for the required specs. But if we were to opt out of Spot instance class and go for On-Demand, which is the standard class of VMs with no risk of termination, the price jumps to US$34.79 (S$46.79) per month! To put things into perspective, that means in about 3 months of incurred cloud costs, you can already purchase a Rock Pi X.
Assuming that the instance class is not an issue for you, then the breakeven point is pushed to around 8 months of cloud bills. To me, I foresee myself playing this game beyond 8 months, plus, I'm a huge fan of self-hosting on-premise so I opted for the Rock Pi X in the end.
I'm running Debian Buster installed via a bootable USB, with default configuration with the exception of zram logging and zram swap to extend the life of the eMMC module by reducing/redirecting writes from logging and swapping.
As for Docker, I followed the instructions to set up Docker's apt repository, and installing via
Docker image and configuration
As for image choice, I chose
for its simplicity in configuration but there are other alternatives worth considering such as
which is more feature-packed. I'd suggest checking out both of them and choosing what suits you best.
Last but not least, here's the
along with my environment variable configuration:
docker run -d \ --name valheim-server \ -p 2456-2458:2456-2458/udp \ -e NAME="My Valheim Server" \ -e WORLD="My World" \ -e PASSWORD="mysupersecurepassword" \ -e PUID=1000 \ -e PGID=1000 \ -e TZ=Asia/Singapore \ -e AUTO_UPDATE=1 \ -e AUTO_UPDATE_SCHEDULE="5 8 * * *" \ -e AUTO_BACKUP=1 \ -e AUTO_BACKUP_DAYS_TO_LIVE=1 \ -e AUTO_BACKUP_PAUSE_WITH_NO_PLAYERS=1 \ -e WEBHOOK_URL="https://discordapp.com/api/webhooks/1234567/somejumbleofalphanumeric-dash_underscore" \ -v ./valheim/saves:/home/steam/.config/unity3d/IronGate/Valheim \ -v ./valheim/backups:/home/steam/backups \ -v ./valheim/server:/home/steam/valheim \ mbround18/valheim-docker
Details of each environment variable setting can be found in the
Some notable configuration values I've set:
: I set this to 1000 as that is the default UID and GID of the first user you create during installation of Debian. This is to ensure that you don't run into permission issues with volume mounts.
: I've enabled auto updates and set the server to update at 8:05AM which is a time when all players are guaranteed to be not offline (when everyone's either working or sleeping). The time specified by the cron expression here depends on the correct setting of the timezone in
: I set the server to perform an auto-backup at a default frequency of every 15 minutes and to pause auto-backups when there are no players. This reduces disk writes from backups by up to 75% as in any given day the server will only see active players in ~6 out of 24 hours and in the time when there are no players, the world remains frozen in the exact same state so there is no need for further backups.
: I set this to my Discord channel's Webhook URL which allows for server status notifications in the channel, giving my friends some visibility into whether the server is running.
I configured port-forwarding on my router for source ports
to the Rock Pi X's internal IP address, for the same destination ports. Each router has a different interface so you'll have to search for help with this one if you have never tried it.
There are 2 ways to connect to the server, via Steam server browser or in-game server browser, but there's an even faster way that's not very well documented, which is specifying the server via the launch options.
1. Go to Valheim in Steam, click on Settings (indicated by the Gear icon)
2. Under Launch Options, enter the following, replacing the IP address with your dedicated server's:
3. On launching the game, you'll only need to enter the password in the in-game prompt and you're good to go
I've been running the server for more than 3 weeks now and the server has achieved 99% uptime in the past 30 days as tracked by BattleMetrics (The downtime was mainly from scratching my own itch, tinkering with the server, and accidentally bringing it down).
I must say I'm pretty impressed by what the 3.35in by 2.13in machine can do. I have not experienced unexplainable performance issues so far. The only issues I've experienced are known issues with the game itself, but thankfully, have since been fixed in the 0.148.6 patch on 23 March, 2020.
Known issues (Fixed)
I've taken measurements of the game's resource utilization with htop and computed the averages below.
CPU (Idle): 0.6CPU (Load): 1.5RAM: ~2.2GB
With the 4 cores and 4GB of RAM, the game still leaves quite a bit of headroom.
I've since joined the Rock Pi X into my arm64 cluster, Leviathan (post on it to come) and migrated the dedicated server into my K3s Kubernetes cluster so that it leverages the existing distributed block storage.
I find that using Kubernetes is great if you already self-host multiple apps, but not so much if you're just intending to run a Valheim server, hence I did not recommend it in the instructions earlier.
Yes, but only if you're a tinkerer. There are a number of small hiccups along the way that tend to be very typical of self-hosted setups, so much that it has become a reflex for me to address them but may prove to be discouraging if you are not interested in solving small problems and just want a working solution up with the least amount of effort and time.
If you intend to dive head first into the rabbit hole of self-hosting, then absolutely yes. I'd highly recommend this as your first project as it's relatively straightforward and the roadblocks you may face will help you in debugging other apps. The motivation behind this project and the sense of satisfaction you'll get when it all works out will help drive you forward in this endeavor.
Hosting a Valheim dedicated server will be a good litmus test for whether self-hosting in general is really something you'd like to do in the longer term.
Till next time, have fun and good hunting!
Create your free account to unlock your custom reading experience.