Search Unity

Question Networked variable/object limit or advice on performance.

Discussion in 'Netcode for GameObjects' started by Kyperr, Jan 18, 2022.

  1. Kyperr

    Kyperr

    Joined:
    Jul 15, 2016
    Posts:
    32
    Hello. I am working on a high-projectile portion of my project. I believe that, in a worst-case scenario, I will need to handle between 250 - 300 projectiles for a 2D game. I didn't think this would be too much, but it appears that it might be. By the time I get to ~100 projectiles, I am below 30 fps and the clients begin to fail.
    Running 1.0.0-pre.4

    Profiling blames it on a massive amount of GC.Allocs and network activity.

    I've tried a couple of approaches, and I'm looking for any other approach that might help.

    At first, because these are simple and only need to visually represented on clients, I attached a NetworkTransform to them. This actually seems to hit an issue before other approaches. In 1.0.0-pre.2, they introduced the BufferedLinearInterpolator which throws an overflow exception any time the render time falls behind (I'm doing some guessing here, I didn't look too far into it). I am getting the following error which leads me to this conclusion:
    Another approach I've used is NetworkVariables and set them in code. I think this might actually be a worse solution. It avoids the Interpolator bug, and while I'm not able to check it, I assume this would actually result in more network activity than NetworkTransform.

    A third approach (one I am currently looking for advice on) is to come up with a system to potentially batch the position update messages and rate limit them. I could probably get away with updating them every 50-100ms instead of every FixedUpdate. I would like to A) Know if this functionality already exists. Perhaps NetworkVariables already do this under the hood and I just don't see any documentation for it and B) Is there a better alternative that I haven't though of.

    I'd also be interested in knowing if there is a way to make these specific NetworkVariables use a different transport model. I only care about the most recent value so if there's a bit of lag, any other messages can be happily discarded. I don't know if I can do it as granular as per-variable.
     
    Last edited: Jan 18, 2022
  2. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    69
    Hi there,

    You can indeed try limiting the number of updates either on the NetworkTransform of your projectile prefabs or for the NetworkVariables you use for the second method (I'm like you assuming that NetworkTransform is more efficient since it is designed for this).

    I'm having a similar pb with that interpolation error but for some reason only on the client (not the host).

    Have you tried the Network Profiler? I'm going to spin it up to have a look at what's going on in my own project.
     
  3. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    While reducing network traffic will certainly help, if you're seeing a lot of time allocated to GC.Allocs then you're probably instantiating and destroying bullets a lot, and should definitely benefit from doing object pooling instead. You can find an example of how to do this in Netcode here.
     
  4. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    69
    Thanks but in my case I think that's probably a bug because if I build the game and run a host + a client on the same computer there are no issues and the game runs normally (not very slowly like in the editor with ParrelSync).
     
  5. CosmicStud

    CosmicStud

    Joined:
    Jun 13, 2017
    Posts:
    55
    I'd hate to say Network Transform uses a lot of data. 100-300 projectiles use more than 2000 bytes per second EACH per change in position values. The Network Transform is under development and still needs a lot of work. I'd suggest a more stable replacement, like SmoothSync, which is about 32 bytes per SEND with extrapolation and interpolation.

    The server can only handle about 1 mb reliable data per second to each client (messages/rpcs), with a max of about 10 mb for the entire buffer each second on the server before overflows or free space errors/log. Buffer max depends on server fps

    Ultimately, the server can handle hundreds to thousands of networked objects, its just the buffer memory to keep in mind and how much stress is on the network that'll determine your low performance
     
    Last edited: Dec 14, 2022
    Roidz99 and bing2 like this.