Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Understanding snapshot size

Discussion in 'NetCode for ECS' started by StickyTommie, May 4, 2021.

  1. StickyTommie

    StickyTommie

    Joined:
    Oct 23, 2019
    Posts:
    13
    Hey,

    I was trying to debug some of the snapshot sizes in my other project and noticed that the snapshot size would increase x2 if my network tickrate is changed to x3 what it was... I expected the change of the networkTickRate to change the speed at which the snapshots are send, not to actually increase the size of them.. So I'm curious as to why... So I looked at the DOTSSample for reference and found this to be the case aswell...

    So let me demonstrate.

    I only changed the NetworkTickRate in ServerGameLoop.cs for both tests.
    Code (CSharp):
    1.         EntityManager.AddComponentData(tickRate, new ClientServerTickRate
    2.         {
    3.             MaxSimulationStepsPerFrame = 4,
    4.             // Hardcoded for now, should be a setting
    5.             NetworkTickRate = Game.serverTickRate.IntValue /* / 3 */,
    6.             SimulationTickRate = Game.serverTickRate.IntValue,
    7.             TargetFrameRateMode = Game.IsHeadless() ? ClientServerTickRate.FrameRateMode.Sleep : ClientServerTickRate.FrameRateMode.BusyWait
    8.         });
    During this test I always had only 1 client and 1 thin client.
    When you're in game and you shoot at the wall, this is what the NetDbg shows...

    NetworkTickRate: 20
    upload_2021-5-4_13-24-55.png
    The total size in bits is 193 and 24 bytes.

    NetworkTickRate: 60
    upload_2021-5-4_13-19-11.png
    The total size in bits is 366 and 46 bytes. We can also see that the instances have doubled.

    Why does this occur? Both tests use the same setup, 1 Client + 1 Thin client, on 20 Tickrate the instances are what I would expect them to be. 2 weapons on the server , 1 for the client, 1 for the thin client. However when changing it to a 60 tickrate we get double the ghost instances? So 2 weapons for the client and 2 weapons for the thin client?

    Hopefully someone can clarify why this happens.
    Best regards!
     
  2. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    I assume this is the snapshot size / instances on the server, not on the client?

    The server will send both weapons (client and thin) to both clients, so the total number of instances the server sends will be 2 weapons * 2 clients = 4.
    When your network send rate is lower than sim rate the server will alternate and send the data to client 1 on odd frames and data to client 2 even frames (will actually be every third frame w/ 20hz send rate). So the data the server sends every frame will be lower if you have a lower send rate.
     
    StickyTommie likes this.
  3. StickyTommie

    StickyTommie

    Joined:
    Oct 23, 2019
    Posts:
    13
    Yes, this is the snapshot size/instances on the server!

    Thank you for clarifying!

    Does this also mean then that the snapshot we see in the NetDbg Tool actually consist of multiple smaller snapshots that are being sent to each client seperately, but are just combined into a singular vertical bar in the NetDbg tool?

    And if this is indeed the case, will there be a possibility of looking into these seperate snapshots for each client? Or maybe there already is some way to do this?

    And finally, can you possibly point us to some kind of documentation regarding this alternating sending when your network send rate < sim rate, or even give clarity to this decision that even though network rate is set to 20, it's actually, in my case (1 client + 1 thin client) sending 40 snapshots a second?

    Thank you for your speedy responses!
     
  4. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    Yes, we present a single value for snapshot data on the server, but it consists of one snapshot per client. The only way to see the data per client is to look at the graphs for the client instead of the server. If you are using client + server play mode you should have those graphs in the NetDbg.

    The send rate setting controls send rate per client. If we sent all the clients the same tick and nothing the other ticks you would get one tick with really high cpu time and 1-2 ticks of no cost for sending - so the update frequency would be very uneven.
    We need to send one packet per client anyway, so the number of packets per second and bytes per second is identical, we just split the cost more evenly between ticks.
    The logic is in GhostSendSystem, it will calculate the send interval (send data every N frames) as simulation rate / send rate rounded up, then it will calculate the number of connections to process per simulation tick as number of connection / send interval and process that many connections starting just after the last one we processed previous frame.
     
    StickyTommie likes this.