Photon Plugin not receiving some events from the PUN client?

Hello, I'm working on creating an authoritative server using a Photon Plugin. I seem to be able to send out events properly and at a frequency I choose (currently 20 updates per second). However, I'm trying to send inputs from the PUN client at 20 updates per second, but only receiving around 5 updates per second from the client. I've verified (at least using Unity's Debug.Log) that the client is indeed calling PhotonNetwork.RaiseEvent(PhotonConstants.EvCommand, serializedCommand, false, defaultRaiseEventOptions); which does not cache anything and is sent as unreliable. Is there a reason the server might be dropping most of these updates? What's the easiest way to debug the potential cause, and/or what are some potential causes of this?

Any help would be appreciated, thanks!
Curt

Comments

  • A related question as I dig into this further is:
    In a photon plugin can I use a standard C# stopwatch to figure out what time it is and how much time has passed? eg.

    physicsTimer = new Stopwatch();
    and look at physicsTimer.ElapsedMilliseconds ?

    It seems that setting a desired Server Frame rate of 10 ms (100fps) using :smile: gameTimer = pluginHost.CreateTimer(
    GameManagerUpdate,
    10,
    10);

    Seems to only call GameManagerUpdate every 50 milliseconds, not every 10 milliseconds. Is that right or is there something about the way plugins work that doesn't play nice with Stopwatch/timers or other standard C# timing methods?

    Thanks,
    C
  • OK, further investigation for those who eventually find this, my experience so far:
    - StopWatch C# functionality (and pure Date/Time methods) do seem to work correctly and you should not expect pluginHost.CreateTimer to execute at exactly the correct frequency. Definitely look into it if it's not running as frequently as you expect. ( I've found that it executes somewhere between 1/2 and 1/5 the rate it's supposed to. Not sure why.
    - This was the source of my perceived issues with send/receive rates, which were in fact correct, just mismeasured due to the above problem.

  • hi, @bererton

    let me give a clue about timer. It is impelemented using System.Timer, but you should know that when timer callback is called it enqueues user callback to room fiber. if there is any actions in fiber they will be executed first and then timer callback. we/you can not predict how many actions in fiber right now, so there is no any guaranties about timer accuracy. make sure that all you code is executed as fast as possible, then timer accuracy will be better

    best,
    ilya
  • Hi @bererton,

    Thank you for choosing Photon!

    I could not understand the problem here.
    I thought you were reporting that some OnRaiseEvent plugin callbacks are not being called then you started talking about timer and StopWatch and reported that plugin timers do not work as intended.
    So what are you trying to do and what issues do you have?
  • Thanks for the followup guys. So ilya's answer lines up with my question and makes sense.

    Basically I was finding that the server was not receiving 20 updates per second from the client which was using PUN's raise event functionality. However that seemed to be because I was assuming that the Photon Plugin was *actually* executing at the frame rate my timer requested which turned out to be false. Here is how I call the initial timer of the pluginhost to set up my server update loop:
    int timeBetweenFrames = (int)Math.Round(1000.0 / (double)desiredFramesPerSecond);
    pluginHost.LogDebug("IOGameManager.cs timeBetweenFrames in milliseconds is: " + timeBetweenFrames);
    gameTimer = pluginHost.CreateTimer(
    GameManagerUpdate,
    timeBetweenFrames,
    timeBetweenFrames);

    Let's say I set desiredFramesPerSecond to be 100fps. However, when I use a Stopwatch or System.timer to measure the actual update loop frequency, I find it only achieves 60 fps. Even if I set it to 30fps, it doesn't achieve 30fps. It's always some lower fps than what I request... possibly a bug? So I cannot rely on the requested frequency for counting of updates (which is why I thought that the server was not receiving enough updates per second from the client).

    One thing I've found is that if you have any pluginHost.LogDebug() commands present that really slows things down for some reason. So avoid those if you're trying to measure any real-time frequencies like FPS etc.
  • hi, @bererton
    >One thing I've found is that if you have any pluginHost.LogDebug()
    that is not something new. loggin was always slow.

    not really sure how do you calculate how many requests you got from client using timer. it is not really good idea to use timer for such precise calculation. you may use timer to update some logic on server, there is is not really important whether it will be called 1 ms before or after.

    for calculations you do you need to use other way
    best,
    ilya
  • @bererton,

    FYI:
    If you are running a local Photon Server and noticed a bad event rate then this is most likely caused by logging. For instance, we noticed that enabling both Photon Server logging and Windows Defender may cause the event rate to slow down considerably. That is why we recommend disabling all virus scanners and firewalls when enabling Photon logging so you can have the expected events rate. You can enable back the virus scanners and firewalls once you stop logging on Photon Servers.

    source
Sign In or Register to comment.