Slow data transfer

Hi,

I'm using server SDK v3-0-24-3243-RC9 (default settings) and PUN v1.16.2 and I'm trying to send a byte array (about 35KB) as operation response (from a game server) when in a room, but before creating a game scene in Unity (the array contains some info obtained from MySQL database that will be used to instantiate objects) and my problem is that this operation takes quite a lot of time (mostly about 10-15 seconds, but sometimes even ~30s and 2 seconds was the shortest time), also, I'm the only player in a room, so there are no additional messages. I think the data amount will increase in the future about 10-20 times (since for now it's only for testing purposes), and it will take far too long to get it... The problem occurs only when sending the data from server to client, when I send the same array to server as operation request parameter it's being delivered in less than a second...

I was trying to change the channel and/or make the communication unreliable, but it doesn't help. I saw in logs that some RaiseEventRequest operations are being requested during the data transfer (I'm not sure, but I think with 202 code), is this normal? I'm new in Photon stuff, so I don't know what else I could try, but I presume it should be possible to send the data faster?

Do you have any thoughts on this? I would appreciate if you could help me.

Regards,
Sebastian

Comments

  • Do I understand that right - when you call that specific operation, Photon opens a DB connection and fetches some data and then sends the data as an OperationResponse to the client?

    Please make sure that the time is NOT spent on DB access. (add a stopwatch / timer to your code and measure the time it takes from opening the DB connection until you have all data fetched and are ready to send it back). You might consider asynchronous DB access (and send the data to the peer later as an event), or if the data is similar for all peers, store it in memory and don't access the DB each time a client connects.

    Sorry if you have already done that - but DB access is always the suspect for slow response times. ;)

    Photon in general is more optimized for smaller messages, but sending a single response of ~ 35 KB is absolutely fine and should be a matter of milliseconds. Are you testing on your local machine or with a remote server?
  • Hi Nicole, thanks for your reply :)

    Yes, you understand it right. I'm testing on my local machine, only the MySQL connection is remote, but it doesn't matter here since I was comparing the time just before/after (no difference here) calling SendOperationResponse and getting OnOperationResponse in NetworkingPeer (so the data from DB was already fetched and added as a response parameter).

    This is my operation handler, as you can see it's as simple as possible ;)
    protected virtual void HandleGetSceneDataOperation(OperationRequest operationRequest, SendParameters sendParameters)
    {
        byte[] data = GameApplication.Instance.DbConnector.GetScene( (int)operationRequest.Parameters[(byte)ParameterCode.SceneId] );
                
        var response = new OperationResponse( operationRequest.OperationCode, new Dictionary<byte, object> { { (byte)ParameterCode.SceneData, data } } );
        this.SendOperationResponse( response, sendParameters );
        log.InfoFormat( "HandleGetSceneDataOperation: {0}, {1}", DateTime.Now.ToString("hh:mm:ss"), data.Length );
    }