Performace Hit of SmartFox.Send()

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

wren
Posts: 6
Joined: 05 Nov 2012, 06:57

Performace Hit of SmartFox.Send()

Postby wren » 05 Nov 2012, 15:03

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.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Performace Hit of SmartFox.Send()

Postby Lapo » 06 Nov 2012, 08:19

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
Lapo
--
gotoAndPlay()
...addicted to flash games
wren
Posts: 6
Joined: 05 Nov 2012, 06:57

Re: Performace Hit of SmartFox.Send()

Postby wren » 08 Nov 2012, 06:18

Thanks. It helps.I find the performance hit actually comes from the Regex inside the Send function. I'll start another thread.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Re: Performace Hit of SmartFox.Send()

Postby ThomasLund » 25 Nov 2012, 15:46

Replying in the other thread
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 25 guests