The role of the CPU in a Bungee Network

Discussion in 'Server & Community Management' started by Fetzu, Mar 26, 2017.

  1. Hey Spigoteers,

    I have some questions around the details of how the CPU factors into a Bungee Network.

    My main question is, considering that Minecraft is single threaded, how does the CPU work with multiple servers and Bungee running? For example, do the servers get given a single CPU core each, or is the work from all the servers being divided amongst all the CPU cores at the same time?

    - If they are given a single core each, can you control how the servers are grouped?

    - If not (most likely), is it then better to create many servers with a low player count on each, or one single server to handle the max amount of players based on other factors of the server (e.g. RAM)? My thinking is that each server has a standard overhead, so the more servers you launch, the more resources are taken up in these overheads BEFORE the server is even under load.

    This brings me to the mini games. Performance wise (and lets pretend we are speaking of a well built mini game plugin with negligible performance issues) would it be better to run multiple games (e.g. 4 seperate arena's, 16 players each) each on it's own server OR run multiple arenas (and potentially multiple games) in a single server. Again, my thinking is that running games, each on their own server, uses overhead that otherwise wouldn't be used if they were all run on a single server.

    I know that it is more complicated, with plugins, hardware specs, player number fluctuations and many more factors, but there must be some idea about the role of the CPU and the best way to approach a network of servers.

    NOTE.
    To give a specific example, I have (currently offline) a Dedicated that runs a Xeon E3-1241v3 (3.5ghz) with 32GB of RAM. I have two main servers running, a lobby and a survival world. There are also 3 mini game servers running Eggwars (gaelitoelquesito), Skywars (gabbo200), and Super Paintball (iSach). I have the basic group of plugins most have, including Essentials, PowerfulPerms, Minecompass and a 6 or so others. I intend to build in more plugins, but I am starting off slim, and building slowly.

    Thank you for any thoughts.
     
    #1 Fetzu, Mar 26, 2017
    Last edited: Mar 26, 2017
  2. Minecraft servers are single threaded (not sure about bungee, might be multi threaded). Therefore, each server is assigned 1 thread, but not an actual CPU thread, since there isn't that many. Not sure how to describe these, but take a look at this:
    [​IMG]
    Pretty sure it's these kinds of threads.
     
  3. Depends on your OS's scheduler: Linux's scheduler assigns roughly a thread per core (switches them around every 10 or so seconds), while windows just switches the threads around all the time.

    As a rule of thumb, number of threads = number of cores gives maximum performance.
     
    • Like Like x 1
  4. Thank you, but that unfortunately makes no sense to me! :)

    Thanks for the reply, are you implying that on a 4 core CPU, 4servers (4threads) would be the best performance? Or that, for example with Hyperthreading, a 4 core/8HT CPU would be good with 8 servers? If this is so, what about multiarena worlds vs single arena/single server?

    NOTE. My understanding of Threads is that they are (overly simplified to my peril) streams of calculations that are being 'feed' to the processing unit. So Hyperthreading is when the CPU manages two Threads simultaneously and feeds them evenly to a single processing core. It does this for each core, meaning 8 Threads are being 'feed' to the cores. It apparently does not make the chip go twice as fast, but manages the threads in an efficient way that allows programs to 'balance' out their loads... Thereby making the chip run more efficiently, and a little faster.
     
  5. CPU threads are not the same as programmable threads. I'm not entirely sure how it works, but I do know that it doesn't mean a 4 thread CPU can only have 4 threads, that's a fact. That's also shown in the screnshoot. It's pretty hard to explain, you should Google for furthur detail on this.

    I doubt it. A computer can run thousands of "threads" at once, so it would be unrealistic if BungeeCord would take up so much.

    Again, I highly doubt that they are given a single core each. That would mean Hypixel has like... what, a 1200 core CPU? :p

    BungeeCord is just a proxy, that's it. Nothing more nothing less. That's the reason you can run houndreds of players on a very small (500mb RAM) server. It just accepts a connection, and redirects it to a Minecraft server. Spreading this playercount over multiple Spigot servers should not be of any affect for BungeeCord. Only the Spigot server should notice a performance difference when having a low playercount or when having a high playercount. All that matters to BungeeCord is the total connected to it, not how they're spreaded out.

    I would personally spread every game acros its own server to increase performance. Yes you may end up with a shitload of servers, but running them all seperately allows them to focus on just the single game, and way fewer players. That should increase performance.

    Computers can create thousands of threads as seen in the screenshot of @DotRar. My suggestion is that you should not be afraid to use these. Got some data to load from a database? New thread! (IO methods should always be async by the way, but it's an example). With a Minecraft server, you shouldn't be afraid of having too many threads. A computer can handle a crap ton of them, believe me. With Minecraft servers, the most important common issue with performance is thread blocking. When executing a line of code that takes much longer than any other (database queries for example) you block the main thread. The server cannot continue untill this is done. Do this several times a second, heck, maybe even houndreds of times a second, and your server will drop performance. Unexperienced programmers are not aware of this and lots of plugins nowadays don't have this async feature built in.

    Fun fact; even WorldGuard's SQL isn't async, I personally tested that. Really poor programming if you ask me. I complained about that, but they didn't care.
     
    • Like Like x 1
    • Informative Informative x 1
  6. Well, you sure did answer a few questions there bud! :) Thanks for that.

    So, with spreading the games out on their own servers, how much of the resources do you think are used up in the overhead of running each server as compared to a single server with many arenas?

    For example, 1 server with two arenas may have X resources being used, but would 2 servers with 2 arenas (one each) be using much more in terms of overall resources?

    I am looking to have value over raw performance. If multiarena runs only with a small hit in performance, but uses substantially less resources, I would rather the multiarena. If the difference is negligible I will, as you recommend, go one arena per server.

    Thanks again for the thorough reply! :)
     
  7. The thing is that I am not sure about hyperthreading, but in general, X CPUS can handle more than X threads by switching between then really quickly. Of course switching takes time, meaning that more than X threads will just take useless "effort" taken by switching.

    Generally servers run on one "main" thread and sometimes pop up a small helper thread, like for the occasional async operation, so number of servers = number of cores should optimise performance. (Because the small helper threads can be pretty much ignored)
     
    • Like Like x 1
  8. That's a tough question.

    When using a single server for multiple games, you have to take a few things in consideration:
    • You'll be using multiple worlds (I assume). More worlds cause more load on the server overall.
    • You'd be running mutliple games of the minigame (duh), but if it's poorly programmed, running multiple games might cause some performance issues.
    • When a server has performance issues, you may need to restart it. When seperating all games over multiple servers, you could for example restart the server after every X amount of games. Thats gonna be slightly hard to do when you're running multiple games on one server.
    I think in regards of performance, you shouldn't notice an extreme difference. It's rather about simplicity & maintaining the servers. How well are the plugins programmed to handle multiple games? Are they programmed to handle multiple at all? iSach's paintball isn't as far as I know.

    Seperating them all over multiple servers is simply ease of mind.
     
    • Winner Winner x 1
  9. Perfect. Thank you for your answers Dienns.

    It was this practicality that I was really after. I will split up the servers.

    On a side note, something like Skywars 16 players, how much RAM would you consider?

    I am using 512mb, but I have not had high traffic at all, so not sure if it will handle if more players?

    The reason I ask, is that I am building my lobbies next month (having them built I should say) and I need to have an idea of the amount of minigames I should be catering for. Portals etc....
     
  10. I would personally give BungeeCord 1GB, just because. BungeeCord should always be online and you should not be restarting it all the time to change the RAM for example. Set it to 1GB and you're set for a while. For each game server, 512MB might do. When optimizing it just enough (entities and such) it should do. If not, 1GB will do the job for sure.
     
    • Like Like x 1
    • Agree Agree x 1
  11. BungeeCord is fully multithreaded, there's no kind of main thread on bungeecord.

    The most important thing is to make sure that your cpu is not getting above ~90% under normal work.
     
  12. Okay, so a well answered question is begging to be asked after this.

    Would a E3-1241v3 (4 cores @ 3.5ghz) be better than 2x E5-2670 (16 cores @ 2.6ghz) on a network with more than 4 servers (say 16 servers)?

    In other words, would the increase in ghz beat out the higher number of cores provided to the increased amount of servers?
     
  13. well if all your servers are not handling more than 30 players with well-written plugins the 16 cores cpu are far better because if you run 16 servers on the 4-core cpu the servers overall have in average 3.5/4 ghz cpu, while on one 16-core cpu each server has 2.6 ghz an the OS would not have to switch thread contexts that often (lower kernel time consumption).
     
  14. I know my question is a bit offtopic but...

    Does it really lag a lot? When I'm programming server events, I always do them in separate worlds because... well, it's easier when I'm programming it but I don't know if doing in separate worlds will create a huge amount of load or not. (keep in mind that all of those worlds are an empty void (EmptyWorldGenerator) with something in the world.
     
  15. More worlds equals more data. More entities for the server to control. More things that can happen. More more more. So yes, having multiple worlds will always lag a more than having only one.
     
    • Informative Informative x 1
  16. This is around the most we have had, but hope to see more. Would it then be best to spread players around lobbies so servers never get above 30 - 50 players at any time?
     
  17. For a lobby its not an extreme issue if it lags a little. Ofcourse it doesn't give a good first look when a player already lags in the lobby, but having lag in a game server is worse than in the lobby. 30 players should overall be the max for a lobby. If you go above the 30 you should spread the players over multiple lobbies. Having more than 30 players in a lobby is just... meh, even if your server can handle it
     
    • Like Like x 1