-
-
Notifications
You must be signed in to change notification settings - Fork 91
Concepts for dummies
This page will help you understand basic concepts behind hosting a minecraft server.
Your startup Xms and Xmx flags should always have the same value. Consider the following analogy:
Imagine you're going to school and you get yourself a single page for taking notes. The week comes to an end and you see your page is full, but there are bound to be more notes to be made next week, so you go and buy a 16 page notebook. A few weeks go by and you notice your notebook is full, but there's still a lot of time until the end of school, so you go buy a 32 page notebook. You repeat this until you get to the end of the school year. You currently have a 9 thousand page notebook.
Wouldn't it be cheaper and more time/resource efficient to buy a bigger notebook in the first place?
If your Xms is lower than Xmx, your CPU has to take resources to increase the amount of allocated memory each time it hits current allocation limit. By setting equal values for both, you allocate all the memory at the start, saving your cpu's time on runtime.
You shouldn't allocate too much RAM Allocating too much memory can hurt your server the same way as allocating too little will.
Taking the previous analogy from this section, consider this:
The school year is over and the next one is about to begin shortly. You need to go through your notes. Turns out a lot of the pages are just silly sketches or stuff that you won't use in the next year. If only you filtered your notes more often during the previous school year while there were less pages!
Smaller amounts of memory are faster to clean up by garbage collection. The more data garbage collection has to filter through, the more time the collection will take, possibly stalling your server.
Imagine you have a storage box, that is filled to the brim. There is absolutely no free space inside. That storage box is your allocated memory. If you wanted to clean it up, you would need to take some things outside of it to check if they are of any use. In order to do that you need the space outside of the storage box.
Java needs extra memory to check what data can be removed. That's why there is usually an overhead to the RAM you allocated via your Xms and Xmx flags. If there isn't enough memory for that, you will get an Out of Memory error.
Consider the following analogy (by BillyGalbreath):
Imagine you have a job where you work 12 hours a day. The other 12 hours of the day someone else comes in to do that job. the two of you alternate days and nights.
If things go smoothly, you end your days within your allotted time, or earlier. On bad days you have to stay late and work overtime until the job is finished. Same applies for the night time worker.
Oversleep is what happens when you wake up and go to work at your regularly scheduled time, but you have to sit and wait for the night time employee to finish their overtime, because they didnt finish their work.
It sounds silly, I know. Like, why can't you both just work at the same time to finish the job quicker, or why can't you just take over. That's what would happen in real life, but in computing it's a little trickier to do that. So they dont. One has to wait for the other to finish before they can start.
Doing things asynchronously isn't always better, and it's not a magical solution to every problem.
Consider another analogy, also by BillyGalbreath:
What is the fastest way of going to your neighbours house? A car is pretty fast, so why not try that. It's definitely faster than you walking, but when you calculate in having to get in the car, buckle up, start the engine, reverse out into the road, drive to the next driveway, pull in, kill the engine, unbuckle and get out, it turns out that just walking would have been faster.
Async operations usually require overhead to take place, like the steps required to enter and exit the car before being able to drive. You should generally only do things async if you know what you're doing. It's not the "magical cure" for improving performance, it can even hurt it if done wrong.
Consider another analogy, also by BillyGalbreath:
Imagine you are the server tick loop, and I tell you I need you to run around your neighborhood block in 5 minutes. You can do this easily, with lots of time to spare, even. Now i want you to stop at everyone's yard and inspect them for any animals or items and either stack/remove them if there's too many. Ok, still pretty doable within 5 minutes. Now do this for 3 blocks (overworld, nether, the end). Ok, we're getting tight now. ok, so lets add another block for spawn, and other for farms, and another for resource gathering (6 blocks). you could probably do it right around 5 minutes. but then theres lots of other tasks you have to be doing while you're running those blocks, not just the animals/items task i sent you out on. Now i need you to do 15 blocks. No way you're getting it done in time.
Thats how the server's tick loop works, but it has 50 milliseconds to do all that work. Adding more worlds just compounds the number of tasks it has to do, and it will quickly run out of time to do it all in if you add too many worlds/plugins/tasks/etc.