Minecraft Server Optimization



In our blog, we already talked about how to create your own Minecraft server, however, 5 years have passed since then and a lot has changed. We are sharing with you the current ways to create and optimize the server side of such a popular game.



Over its 9-year history (counting from the release date), Minecraft has earned an amazing number of fans and haters, both among casual players and geeks. The simple concept of a cube world has evolved from a simple entertainment into a universal environment for communication and creation of various objects from the real world.



In addition to construction, the game has the ability to create logic circuits that allow you to implement full-fledged algorithms inside Minecraft. YouTube is full of very impressive videos where people put a lot of effort and time to create a copy of an electronic device or build a detailed copy of existing and fictional architectural structures. Everything is limited only by the fantasy of the gamer and the possibilities of the gaming universe.





But let's not talk further about what exactly the players are creating, but let's look at the server side of the application and highlight the problems (sometimes very complex) that can arise during work under load. Let's make a reservation right away that we will only talk about Java Edition.



Server types



The simplest option is the server built into the game client. We created a world, pressed one button, and now the server became available on the local network. This option cannot withstand any serious load, and therefore we will not even consider it.



Vanilla



Mojang Studios distributes the server part of the game as a Java application for free on the official website . This allows you to create your own dedicated server and personal world, making it available for connection from anywhere in the world. For those who are doing this for the first time, there is an excellent tutorial available on the respective game Wiki.



This approach has one serious drawback, namely, the lack of opportunities "out of the box" to connect plugins that extend the functionality of the server and allow not only to automate many processes, but also to optimize performance. In addition, the official server has a fairly large consumption of RAM for each connected player.



Bukkit



Created by enthusiasts based on the Vanilla version, the Bukkit server application significantly expanded the game's capabilities by supporting plugins and mods (modifications). It allowed not only to add new blocks to the gameplay, but also to perform various manipulations that are inaccessible to vanilla software. Interestingly, this application required significantly less memory.



It is not difficult to install Bukkit, the corresponding instructions are on the GamePedia resource . But this does not make sense, since since 2014 the Bukkit team has disbanded, the developers of the project have become employees of Mojang Studios, and the repository is abandoned. So Bukkit is actually dead and it makes sense to pay attention to the next two projects.



SpigotMC



To make life easier for plugin developers, there was a need for an API to interact with the game world. This is exactly what the creators of Spigot solved by taking the Bukkit core as a basis and reworking it to achieve better reliability and performance. However, the project's Git repository has been locked due to the Digital Millennium Copyright Act ( DMCA ) and the sources cannot be downloaded from there.



At the moment, SpigotMC is being actively developed and used. It supports all plugins built for Bukkit, but is not backward compatible with it. To get around the DMCA Takedown ban, an elegant way was coined called BuildTools. This tool eliminates the need to distribute a compiled application and allows users to compile Spigot, CraftBukkit, and Bukkit from source. All this makes the DMCA ban useless.



PaperMC



Everything seemed cool and Spigot was a great option. But some enthusiasts didn’t find this enough, and they wrote down their own fork of Spigot “on steroids”. On the project page, the key advantage states that “It's stupid fast”. A developed community allows you to quickly resolve emerging issues, and an extended API allows you to make interesting plugins. You can start PaperMC with one simple command from the documentation .



Everything is fine with PaperMC's compatibility, so the written plugins for SpigotMC will easily work on PaperMC, but without official support. Backward compatibility with SpigotMC is also present. Now that we've listed the various options for creating a server, let's move on to those performance issues that can arise.



Problems and Solutions



The main thing to understand is that everything related to the processing of the game world will be processed only on one computing core of the physical server. So if suddenly you have an excellent server with a dozen computing cores, then only one will be loaded. All the rest will be virtually idle. This is the architecture of the application, and there is nothing you can do about it. So when choosing a server, you should pay attention not to the number of cores, but to the clock frequency. The higher it is, the better the performance will be.



As for the question of the amount of RAM, one should proceed from the following indicators:



  • planned number of players;
  • the planned number of worlds on the server;
  • the size of each world.


Remember that a Java application always needs a headroom of RAM. If you are counting on memory consumption of 8 gigabytes, then in fact you need to have 12. The numbers are relative, but the essence does not change.



To start the server side, we recommend using the flags specified in the Tuning the JVM - G1GC Garbage Collector Flags for Minecraft article . This "black magic" allows the server to intelligently configure the garbage collector and optimizes the use of RAM. It is not worth allocating more memory than the server actually consumes during the peak influx of players.



Generating a block map

"Do you really think the moon only exists when you look at it?" (Albert Einstein)
Brand new server. As soon as the player successfully connects for the first time, the game character appears at a common gathering point (spawn). This is the only place where the game world is pre-generated by the server. At the same moment, the client part looks into the settings, and the key parameter is the drawing distance. It is measured in chunks (the map area is 16x16 and 256 blocks high). How many chunks are indicated there, this is exactly how much will be requested from the server.



A global map of the world is stored on the server, and if there are no generated blocks in it at the point of appearance of the game character, then the server dynamically generates them and stores them. Not only does this require large computing resources, it also constantly increases the size of the world map. On one of the oldest anarchist servers 2b2t(2builders2tools) the map size has already exceeded 8 Tb, and the world border is at the mark of 30 million blocks. Thousands of stories are associated with this server and deserves its own article in a series of articles.



Generating a world around one player is not a problem. Generating a world around hundreds of players will cause minor server brakes for a short time, after which the load will decrease. Generation of the world at the distance of drawing a client around a thousand players is already capable of "dropping" the server and throwing out all clients from it by timeout.

The server software has a value such as TPS (Ticks per Server - ticks per second). Typically, 1 clock cycle is equal to 50 ms. (1 second of the real world is equal to 20 bars of the game world). If the processing of one clock grows to 60 seconds, the server application will be closed, throwing out all the players.
The way out is to limit the world to certain coordinates and perform preliminary block generation. Thus, we remove the need for dynamic generation during the game, and the server will only have to read the existing map. Both issues are handled by a single WorldBorder plugin .



The easiest way is to set the border of the world in the form of a circle relative to the spawn point (although you can make it of any shape) with one command:



/wb set <  > spawn


If the player character tries to cross the border, he will be thrown back a few blocks. If this is done several times in a limited time, then the intruder will be forcibly teleported to the spawn point. Pre-generating the world is even easier with the command:



/wb fill


Since this action can potentially affect players on the server, do not forget to confirm execution:



/wb confirm


In total, it took about 2 hours on an Intel® Xeon® Gold 6240 processor to generate a world with a radius of 5000 blocks (~ 40 billion blocks). Therefore, if you want to start pre-generation of a larger map, keep in mind that this process will take a decent amount of time , and the TPS of the server will be seriously reduced. Also, remember that even a 5,000 block radius will require approximately 2GB of disk space.



Despite the fact that the extreme version of the plugin was developed for Minecraft version 1.14, it has been experimentally found that it works great on subsequent versions. A complete list of commands with explanations is available on the plugin forum .



Problem blocks



There are a great many types of blocks in Minecraft. However, we would like to draw readers' attention to such a block as TNT . As the name suggests, this block is an explosive (editor's note is a playable item in the virtual world and this item has nothing with real explosives) . Its peculiarity is that at the moment of activation, the force of gravity begins to act on it. This forces the server to calculate all coordinates, if at this moment the block starts to fall.



If there are several TNT blocks, then the detonation of one block causes detonation and the inclusion of gravity in the neighboring blocks, scattering them in all directions. All this beautiful mechanics on the server side looks like a lot of operations for calculating the trajectory of each of the blocks, as well as interactions with neighboring blocks. The task is extremely resource-intensive, which everyone can easily check. Generate and explode a cube of TNT blocks at least 30x30x30 in size. And if you thought that you had a good powerful gaming computer, then you were greatly mistaken;)



/fill ~ ~ ~ ~30 ~30 ~30 minecraft:tnt




A similar "experiment" on a server with Intel® Xeon® Gold 6240 led to a serious "drawdown" in TPS and 80% load on the CPU during the entire time of block detonation. Consequently, if any of the players can do this, then the performance problem will affect all the players on the server.



An even tougher option is the Crystals of the End . If TNT nevertheless explodes sequentially, then the Crystals of the End detonate all at the same time, which in theory can completely stop the operation of the server application.



This scenario can be avoided only by completely prohibiting the use of these blocks in the game world. For example, using the WorldGuard plugin . Please note that this plugin itself does not work without another WorldEdit plugin... So install WorldEdit first and then WorldGuard.



Conclusion



Competent game server management is not an easy task. Difficulties and reduced performance will await at every turn, especially if you do not take into account the very mechanics of the gameplay. It is impossible to foresee everything, because players are sometimes very creative in trying to force the server to do something for which it was not intended. Only a reasonable balance between risks and established limits will allow the server to work in a continuous mode and not reduce its performance to critical values.



In quarantine, some of our employees missed their favorite offices and decided to recreate them inside Minecraft. You also have a chance to visit us without risking your health and wasting time on the road.

minecraft.selectel.ru ( 1.15.2), - -1 -2. , .



, , «» .



All Articles