local loop's got way too high delay

Options
swfly
edited July 2011 in DotNet
hi guys sorry for raising topics so frequently.
i use the peer.ServerTimeInMilliSeconds as a timestamp and send it out.
in unity i call print(peer.ServerTimeInMilliSeconds - timestamp) once i receive it.
but i found that even in local loop(run two clients in the same time) the result sometimes goes even as high as 400ms.
i think there's something wrong and photon should not perform like this.
any idea with this problem? thanks.

Comments

  • Tobias
    Options
    I admit, I never tried this.
    There is a ~50ms "default" delay for Photon, which we use to accumulate commands to send to a client. More commands per package are less overhead per command and in total. You can change the PhotonServer.config to get rid of this delay.

    As events are usually not "sent back" to the player who raises them, what exactly are you doing? Start 2 clients?

    There might be local lag as well. Did you make sure you send soon after calling your opertation? Do you dispatch incoming commands asap? Both is done in loops and if these get delayed, it will show.
  • swfly
    Options
    hi tobias, thanks for the reply.
    yes i start 2 clients, or actually i started the editor and a standalone client.
    and my Game.cs has got a Update() method like this:
           if (Time.time - lastSendPos > 0.05f)
            {
                lastSendPos = Time.time;
                if (localPlayer != null && localPlayer.actorNr != 0 && Peer != null)
                    localPlayer.SendPosRot(Peer);
            }
            if (Environment.TickCount - lastSend > SendIntervalMs)
            {
                lastSend = Environment.TickCount;
                Peer.SendOutgoingCommands();
            }
            while (Peer != null && Peer.DispatchIncomingCommands()) ;
    
    don't know whether this is the right way but i think this can make sure that i can get the packets immediately.
    the only delay occurs in this could be among the first and second "if" blocks. but as i set the interval to 50ms(when using Time.time this is 0.05f as you see), i think this is not the reason why it can come with some 300+ ms delay.
    and again thank you for your reply.
  • Tobias
    Options
    You might want to check the time between the while(dispatch) loops. If anything (loading assets, etc) delays the updates, this will add "local" lag.
    I think you shouldn't check Peer != null in the loop, btw.
  • swfly
    Options
    do you mean that i should start a new thread to focus on the dispatch loop?
  • Tobias
    Options
    I wouldn't do that in Unity. If you dispatch in a separate thread, then you can't (or at least shouldn't) access the game objects in that context. So I'd say you have to live with the Update-frequency Unity gives you.

    To analyze where the 400ms delay comes from, I'd use a Stopwatch and take the time spent between the while() loop.
  • swfly
    Options
    Really thanks for your advices. I think it might be other things that courses this problem.
    I'll go and check.