In our blog, we
In its 9-year history (if you count from the release date), Minecraft has earned an amazing amount of fans and haters from both casual players and geeks. The simple concept of a world made of cubes has evolved from a simple entertainment to a versatile medium for communication and creation of various objects from the real world.
In addition to construction, the game has the ability to create
But let's not talk further about what exactly the players create, but let's look at the server side of the application and highlight the problems (sometimes very complex) that may arise in the process of working under load. At once we will make a reservation that it will be a question only of Java Edition.
Server types
The simplest option is a server built into the game client. We created the world, pressed one button, and now the server became available over the local network. Such an option cannot withstand any serious load, and therefore we will not even consider it.
Vanilla
Mojang Studios is distributing the server side of the game as a Java application for free
This approach has one serious drawback, namely, the lack of the ability to connect plug-ins out of the box that expand the functionality of the server and allow not only automating many processes, but also optimizing performance. In addition, the official server has a fairly large consumption of RAM for each connected player.
bukkit
Enthusiast-built Vanilla-based server application
Installing Bukkit is not difficult, the corresponding instructions are on the resource
SpigotMC
To make life easier for plugin developers, there was a need for an API to interact with the game world. This is the problem that the creators solved
At the moment, SpigotMC is 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 method called BuildTools was invented. This tool eliminates the need to distribute the compiled application and allows users to compile Spigot, CraftBukkit and Bukkit from source. All of this makes the DMCA ban useless.
PaperMC
It would seem that everything is cool, and Spigot became a great option. But this was not enough for some enthusiasts, and they washed down their own Spigot fork “on steroids”. On
Everything is fine with PaperMC compatibility, so plugins written for SpigotMC will easily work on PaperMC, but without official support. Backward compatibility with SpigotMC is also present. Now that we have listed the various options for creating a server, let's move on to the 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 on only one computing core of the physical server. So if suddenly you have a wonderful server with a dozen computing cores, then only one will be loaded. All the rest will actually be 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 speed. The higher it is, the better the performance will be.
As for the question of the amount of RAM, it should be based on the following indicators:
- the planned number of players;
- the planned number of worlds on the server;
- the size of each world.
It should be remembered that a Java application always needs a margin of RAM. If you are counting on a memory consumption of 8 gigabytes, then you actually need to have 12. The numbers are conditional, but the essence of this does not change.
To start the server part, we recommend using the flags specified in the article
Block map generation
“Do you really believe that the moon only exists when you look at it?” (Albert Einstein)
Completely new server. As soon as the player successfully connects for the first time, the player character appears at the common rally point (spawn). This is the only place where the game world is pre-generated by the server. At the same moment, the client side looks at the settings, and the key parameter is the draw distance. It is measured in chunks (map area 16×16 and 256 blocks high).
The global map of the world is stored on the server, and if it does not yet have generated blocks 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 anarchic servers
World generation around one player is not a problem. World generation around a hundred players will cause minor server lag for a short time, after which the load will decrease. The generation of the world at a distance of drawing a client around a thousand players is already capable of “dropping” the server and throwing all clients out of it by timeout.
In the server software, there is such a value as GST (Ticks per Server - ticks per second). Normally, 1 cycle is equal to 50 ms. (1 second of the real world is equal to 20 ticks of the game world). If the processing of one cycle increases 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 pre-generate blocks. Thus, we remove the need for dynamic generation during the game, and it will be enough for the server to read an existing map. Both issues are solved by a single 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-generation of 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 the execution:
/wb confirm
In total, it took about 5000 hours to generate a world with a radius of 40 blocks (~2 billion blocks) on an Intel® Xeon® Gold 6240 processor. , and the TPS of the server will be seriously reduced. Also, remember that even a radius of 5000 blocks will require approximately 2 GB of disk space.
Despite the fact that the latest version of the plugin was developed for Minecraft version 1.14, it has been empirically found that it works fine on subsequent versions. A complete list of commands with explanations is available
Problem blocks
There are many types of blocks in Minecraft. However, we would like to draw the attention of readers to such a block as TNT. As the name suggests, this block is an explosive (editor's note - this is a game item of the virtual world and this item has nothing with real explosives). Its feature is such that at the moment of activation, the force of gravity begins to act on it. This forces the server to calculate all the coordinates if the block starts to fall at that moment.
If there are several TNT blocks, then the detonation of one block causes a detonation and the inclusion of gravity in neighboring blocks, scattering them in all directions. All this beautiful mechanics on the server side looks like a lot of operations to calculate the trajectory of each of the blocks, as well as interactions with neighboring blocks. The task is extremely resource-intensive, which can be easily checked by everyone. Generate and explode a cube of TNT blocks, at least 30x30x30 in size. And if you thought that you have a good powerful gaming computer, then you were greatly mistaken 😉
/fill ~ ~ ~ ~30 ~30 ~30 minecraft:tnt
A similar "experiment" on a server with an Intel® Xeon® Gold 6240 resulted in a serious TPS "drawdown" and 80% CPU load during the entire block detonation time. Therefore, if any of the players can do this, then the performance problem will affect all players on the server.
An even tougher version Ender Crystals. If TNT does explode sequentially, then the Ender Crystals detonate all at the same time, which in theory could stop the server application altogether.
This scenario can be avoided only by completely prohibiting the use of these blocks in the game world. For example, using the plugin
Conclusion
Proper management of a game server is not an easy task. Difficulties and performance degradation will be waiting 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 can sometimes be very creative in trying to make the server do something for which it was not intended. Only a reasonable balance between risks and limits set will allow the server to work continuously and not reduce its performance to critical values.
During 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 without wasting time on the road.
To do this, we invite everyone to our server minecraft.selectel.ru (client version 1.15.2), where the Tsvetochnaya-1 and Tsvetochnaya-2 data centers are recreated. Do not forget to agree with the download of additional resources, they are necessary for the correct display of some locations.
You are waiting for quests, promotional codes, Easter eggs and pleasant communication.
Source: habr.com