Search Unity

Unet - How many clients per server?

Discussion in 'UNet' started by Aca, Mar 17, 2017.

  1. Aca

    Aca

    Joined:
    Apr 22, 2014
    Posts:
    10
    Hi all,

    I've made a multiplayer game, where I have one dedicated server. Game is turn-based for 4 players.
    I'm renting a Linux server (1 CPU, 512 MB, 30 GB) for test purposes.
    When I run 1 Linux headless server, it uses 8% of CPU and 26% (~130MB) of memory.
    Which means that I can have maximum 3 servers simultaneously running.
    The game have only 1 terrain, very simple terrain, with not so much grass and trees. That's all.

    I'm doing money math now and it does not going well.
    I need to pay for this one computer $5 per month.
    But on other side, I can have 3 servers on it x 4 players = 12 players for $5 per month.

    What solutions do I have?
    How can I decrease memory usage?
    Or how can I use one server to host maybe 100 games = 400 players, is that even possible?
     
  2. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    220
    This is where things can get really tough, as you do everything you can to try and squeeze as much performance out of your networking as you can. Here's a few tips to get you started:

    Your cpu is quite good, but I recommend reading through the various tutorials/documents provided by unity on the topic of optimization. There are a lot of things that you wouldn't naturally think to do, such as offloading some heavier processes on to co-routines and/or not running those processes every frame. In headless mode, you should be able to get your cpu down to around 3% while idle (my servers sit at this when idling). Pay attention too to various project settings such as physics and quality settings. Although headless mode means no rendering, other things will still be happening based on the objects that are loaded into the scene that your server application is running.

    As for memory, yeah that's rather high. This one will be a bit harder to resolve, so what I will say is ram is much cheaper than cpu (based on general usage), so don't go pulling your hair out here but you will definitely be able to get that number lower. Here's some tips off the top of my head:
    • don't load textured models into your server scene. Even though you can't see the textures, they are still loaded into memory
    • create server versions of objects with reduced numbers of vertices
    • don't load or reference audio files/media files. Again although you wont be able to see or hear these, holding a reference to an audio clip or similar media means that the object exists in memory. So if you see a reference to an audio file somewhere in your inspector for example, it is taking up memory
    There are other things that you can do such as optimizing your code to ensure that you are only storing information in your variables/properties/arrays etc that you absolutely need to. More importantly though, make sure that you are keeping your arrays nice and tidy. One of the most common memory issues is caused by arrays being filled up with useless information that isn't being cleared.

    That moves me onto my final suggestion: keep an eye on garbage collection. In the profiler, the GC Alloc column shows you how much garbage is being created due to the calling of certain methods and so on. Garbage, if not handled properly, can end up causing huge memory overheads to the point that your memory usage seems to constantly grow over time because the automated clean-up of garbage can't clean things up quick enough. So ultimately, you want to ensure that the GC Alloc column is 0, or very close to 0 at all times. Unity have provided a few documents/tutorials on how to manage memory which talks about garbage collection so take a look at those if you get stuck.

    Good luck!
     
    dsafew likes this.