Page 1 of 1

Performace Hit of SmartFox.Send()

Posted: 05 Nov 2012, 15:03
by wren
Hello,

I'm new to both SmartFoxServer and Unity.

I have an array of some objects. Each frame I want to broadcast to other clients some information about the objects. My code looks like this.

Code: Select all

foreach(KeyValuePair<string, MyGameObject> entry in objects)
{       
   MyGameObject obj = entry.Value;
   transferObjectSend = new SFSObject();
   transferObjectSend.PutUtfString("messageID", "gameObject");
   transferObjectSend.PutUtfString("objectID", obj.objectID);
   transferObjectSend.PutUtfString("userID", obj.userID);
   transferObjectSend.PutUtfString("prefab", obj.prefab);
   transferObjectSend.PutFloatArray("locomotion", new float[]
           {
               obj.transform.position.x,
               obj.transform.position.y,
               obj.transform.position.z,
               obj.transform.rotation.x,
               obj.transform.rotation.y,
               obj.transform.rotation.z,
               obj.transform.rotation.w
           });
   transferObjectSend.PutUtfString("currentState", obj.currentState);
   smartFox.Send(new ObjectMessageRequest(transferObjectSend, smartFox.LastJoinedRoom));
}


My test only has 3 such objects in the array, and the frame rate is already very low (< 10 fps). When I remove the call of smartFox.send. The frame rate goes back to good.

The login and room joining is all successful. I only have one client as myself in this test.

I know the code looks stupid, but it's only a test before I decide to continue my work using Unity/SmartFox combination. Optimizing those strings above could make performance better, but the point is that I intended to have a hundred such objects in my game, I guess it’s not a matter of optimization. Did I miss something? or it’s totally wrong?

Could anybody help? Thank you very much.

Re: Performace Hit of SmartFox.Send()

Posted: 06 Nov 2012, 08:19
by Lapo
I think Thomas can answer this question much better than me but I would just recommend to avoid sending data on every frame.
Running a 10fps rate is okay for networking but it is not for rendering and animations. I would suggest to separate the fps rate and network messaging so that each one runs on its own. Instead you could use a timer/thread to send positional data every 1-200ms, possibly using UDP.

For more on this you can check the First person shooter demo and tutorial provided here: http://docs2x.smartfoxserver.com/ExamplesUnity/fps

Re: Performace Hit of SmartFox.Send()

Posted: 08 Nov 2012, 06:18
by wren
Thanks. It helps.I find the performance hit actually comes from the Regex inside the Send function. I'll start another thread.

Re: Performace Hit of SmartFox.Send()

Posted: 25 Nov 2012, 15:46
by ThomasLund
Replying in the other thread