Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

HLAPI and packet jitter

Discussion in 'Multiplayer' started by alan-lawrance, Apr 10, 2018.

  1. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    354
    When sending messages with NetworkServer.SendByChannelToAll() at 60Hz from server to client, I can see up to 7 of these packets arrive at the same time on the client, which seems unusual given:

    * This is on a LAN (all machines wired -- ping as returned by GetCurrentRTT is low single digits)

    * Connection SendDelay is set to 1ms (other connection settings are default)

    * Sent on channel with QoS UnreliableSequenced

    * The data isn't overly large (payload is about 48 bytes + packet overhead)

    Interestingly the Client sends to the Server at 60Hz with same payload, any I've only seen up to 3 packets arrive at once. It's important for us to get these messages transmitted with minimal delay and hopefully keep the jitter to 3 packets at once or less (I know it's unrealistic to expect them to arrive evenly at the same 60Hz frequency they were sent).

    This is with 2017.1.p2

    Before I take the time to replicate in a smaller test project, I was hoping someone would say "Oh, you have to change XXX to YYY in the Connection Config to make sure there is no delay on either end".
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    What happens when you set sendDelay to 0?
     
  3. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    354
    I tried setting SendDelay to 0, and got the same results.

    Doing a bit of research in the forums, I see there is another parameter that affects send latency:

    GlobalConfig.ThreadAwakeTimeout

    The docs don't say what the default value is, and it's a bit unclear to me how this gets used if you are using the HLAPI. Specifically we use NetworkServer + NetworkClient.
     
    Last edited: Apr 10, 2018
  4. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    354
  5. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    It's a common problem not only because of UNet but also because the networks, software, and hardware are not perfect. You are trying to find a source of the problem this is what comes to mind intuitively. But such things should be resolved with the well-known, wise, and practical solutions. That's why a de-jitter buffer exists.
     
    Last edited: Apr 10, 2018
  6. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    354
    Cranking the bandwidth super high didn't have any impact, still seeing up to 8 packets arrive simultaneously on the client when they were sent at a 60Hz send rate from server.
     
  7. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    And it will happen all the time at this frequency and rarely at lower. A low-level transport is smart, and it will try to merge packets into one due to different conditions to avoid issues with throughput, performance, latency and other stuff. You are trying to solve the problem in wrong way. Here's another low-level transport where I send sequenced reliable and unreliable packets at the same frequency:

    test.PNG

    And it's not even a network but my local machine.
     
    Last edited: Apr 18, 2018
  8. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    354
    For my particular use case, I need to minimize the latency between the packet being sent and the packet being processed on the other side. It's simple to buffer on the receiving end to ensure that they "play back" at 60 Hz, but I'm looking to minimize how much I buffer.

    I'll try out a lower frequency to see how that impacts things... one of the reasons I'm using 60Hz is to minimize latency, but that is counter productive if I end up receiving packets in batches of 5 - 8.

    Like I mentioned above though, the problem is less severe going from client to server (worst case I've seen is a clumping of 3 packets)... which I can't explain.
     
  9. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    354
  10. jose-araujo

    jose-araujo

    Joined:
    Nov 17, 2016
    Posts:
    34
    Hi @alan-lawrance, I just came across this post and I am having a similar issue, but my burst is of a single message and not 7 or 8 as you reported. This happens to around 40% to 50% of all the packets transmitted at 60 Hz, and it doesnt happen if I lower the rate. Did you ever solve your problem? I tried setting the networkserver.maxdelay (0.01 and lower) but got no improvement, but maybe I am not calling it correctly? I just added this to my server script, after setting it up.

    I also got the recommendation to configure the threadawaketimeout and the senddelay, but it didnt have any impact, but I was told I am probably not calling this correctly either but havent figured out how to call it correctly.

    Code (CSharp):
    1. GlobalConfig globalConfig = new GlobalConfig();
    2. globalConfig.ThreadAwakeTimeout = 1;
    3. ConnectionConfig config = new ConnectionConfig();
    4. config.SendDelay = 0;

    Here is my post about my issue and the very simple scripts to reproduce the https://forum.unity.com/threads/une...rval-not-consistent-and-burst-arrival.586468/

    Thanks a lot for the help!
     
    Last edited: Jan 22, 2019