playMaker

Author Topic: Performance Problem About PhotonViewRpcBroadcastFsmEvent[SOLVED]  (Read 6459 times)

human890209

  • Junior Playmaker
  • **
  • Posts: 62
Performance Problem About PhotonViewRpcBroadcastFsmEvent[SOLVED]
« on: February 11, 2017, 09:38:19 AM »
Hi,
I'm sending PUN RPC with String Data(PhotonViewRpcBroadcastFsmEvent).
It takes about 20ms CPU Time and 0.5M GC(Profiler Window, Deep Profile) to activate 1 PhotonViewRpcBroadcastFsmEvent Action(String Data is about 150 char long). If the String Data is a longer string, the time will grow but not so much.
I tried to cache the FindGameObject("(name)"), but it doesn't help much. :P

How to improve the Performance of PhotonViewRpcBroadcastFsmEvent? ???
« Last Edit: February 20, 2017, 01:24:38 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #1 on: February 14, 2017, 03:12:09 AM »
Hi,

 I don't think the problem if the the event itself but what you do around it.

 Typically using FindGameObject is definitly a very slow operation, because of the Unity Api itself.

Try to send the same event with a string that is already known at the time of sending.

 Bye,

 Jean

human890209

  • Junior Playmaker
  • **
  • Posts: 62
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #2 on: February 14, 2017, 09:12:58 PM »
Hi,
Deep Profile Mode shows the DoREC() Method got the Time and GC.
If it is another Action which generates the String Data It will show the Method Name of that Action cause your Action is written well making the work in an independent Method :)
« Last Edit: February 14, 2017, 09:42:02 PM by human890209 »

human890209

  • Junior Playmaker
  • **
  • Posts: 62
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #3 on: February 14, 2017, 09:54:05 PM »
I opened the deeper part of the Profiler Hierarchy and found that the true Method making that GC and Time is the SendEvent().
I already know that FSM SendEvent could be lag if the FSM is really busy,  so I seldom use SendEvent under that circumstance. But It seems that Sending PUN RPC have to SendEvent. Is another way(Proxy) around without SendEvent?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #4 on: February 15, 2017, 01:44:53 AM »
Hi,

 I maintain what I think is happening, but I may very well read the profilers screenshot you sent wrong. What I see in all the profilers screenshot would make me want to highlight in blue the first entry exposing the issue, starting from the bottom and deepest hierarchy depth.

so
-- in your first screen shot: NetworkingPeer.ExecuteRPC()
-- in your second screenshot, I would scroll down and see when it all starts, For example what are all the actions being activated, and what they do, what Unity api are they using. This is likely the source of the problem.


Within this Proxy, Typically, yes Sending a PunRPC will have to be catch on targets and executed as an Event, but you can perfectly not doing this and create your own custom action that sends an RPC using the PhotonSDK and have your own RPC method in your own script that then do what ever you want with it.

 this framework for working with PUN from within PlayMaker is not mandatory nor mutually exclusive with any other scripts. Pun SDK comes with lots of examples, so simply dive into them demo scripts to

If you need help on this with pure scripting, go to the ExitGames Forum, and ping me on the thread you created, I'll reply on that thread.

Bye,

 Jean


human890209

  • Junior Playmaker
  • **
  • Posts: 62
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #5 on: February 15, 2017, 02:23:34 AM »
Hi, Jean.

Thanks for your indication. I read some PUN Documentation SDKs and make a custom proxy and actions. They works and the Profiler Show that the GC and Lag are caused by RUN FSM and Actions about String(Array Get Next (string array), String Conversion...)

Does RUN FSM Action itself cause any Performance Consumption?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #6 on: February 15, 2017, 02:27:35 AM »
Hi,

 yes, Run Fsm will cause performance hit because it has to run a template, but no GC for sure.

String conversion would also create issues possibly. Can you describe what your are doing?

Bye,

 Jean

human890209

  • Junior Playmaker
  • **
  • Posts: 62
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #7 on: February 15, 2017, 03:00:42 AM »
Hi, Jean.
Profiler Show that the GC and Lag are caused by RUN FSM and it's sub-Actions about Event and String(Array Get Next (), String Switch and String Conversion...)

Fsm.Event() (from Array Get Next ,XXX Switch/Compare)is always a target for me and Regex.Match()(from String Conversion) is new to me.

Fsm.Event() sending Local Event is unavoidable, is there a way out?
Is Regex.Match() necessary for String2Vector3 functions? is there a way out?

I've packaged my NPC(and Pickup)'s command(NPC ID int, NPC Position(vector3), Y Rotation float, TargetGO PUN view ID/Target Position(vector3), Damage float,  ActionString.....) into String and Send them N times(now is 2) per second to Sync hundreds of NPC's Action. Now it holds 256 NPCs at 70ms/frame in the editor play. It works smoothly in the built play.
I'm using a NPCPickupManager GameObject (with 5 Manager FSMs on it) to manage them. NO FSM on NPC, Playmaker's FSM is number sensible, I don't let too many FSMs running at the same time.
« Last Edit: February 15, 2017, 03:58:47 AM by human890209 »

human890209

  • Junior Playmaker
  • **
  • Posts: 62
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #8 on: February 15, 2017, 03:01:36 AM »
Fsm.Event() is annoying.
« Last Edit: February 15, 2017, 03:59:18 AM by human890209 »

human890209

  • Junior Playmaker
  • **
  • Posts: 62
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #9 on: February 15, 2017, 03:02:05 AM »
Regex Match causes GC
« Last Edit: February 15, 2017, 03:58:10 AM by human890209 »

human890209

  • Junior Playmaker
  • **
  • Posts: 62
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #10 on: February 15, 2017, 03:57:31 AM »
It seems Regular Expression cause GC.
https://unity3d.com/cn/learn/tutorials/topics/performance-optimization/optimizing-garbage-collection-unity-games

Is Regex = Regular Expression?

Is there a way around?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #11 on: February 15, 2017, 04:35:53 AM »
Hi,

 Nice, indeed this is very much likely the source of the problem.

- regex means Regular Expression yes.

- why Fsm.Event() is annoying?

- running lots of FSM isn't the source of any problems for 99.99% of the cases, so here you should reconsider your assumptions on Fsm performances impact. As you saw with this, you initially though playmaker or the proxy was at fault, but it turns out it was about using Unity api to produce a string from a complex set of data.

 I have projects with hundreds and hundreds of Fsm doing crazy stuff :) and performances is fine, yes, I have experience on what to do and what not to do in Unity so I avoid all these pitfalls, but rest assure I went through the same hurdles as you with all of this :)

As for your technic of RPC sync, you are indeed pushing the envelop here :) you are going brute force and likely missing out on the a lot of the great photon internal optimization when it comes to serialization.

I would go on exitGame forum and ask for your case and how to handle it the best way possible.

If your problem is just because you are using regex, then it's cool, simply do it a different way, by for example letting each npc build up their own string of content that you then combine when you need to send that rpc.

If you are ok with sharing your regex queries, I can have a loot and possibly give some alternatives without using regex.

 Bye,

 Jean

human890209

  • Junior Playmaker
  • **
  • Posts: 62
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #12 on: February 15, 2017, 06:46:13 AM »
Hi, Jean.

The Regex is from the ConvertStringToVector3 Action which is original or from Ecosystem.(I attached pic below)

Yeap, my NPC GameObject got AI (Behavior Designer) on them and they do the Sensor and Action Job, the Decision and Sync Job is done by the Manager. So NPC doesn't send Request to Manager all the time, which depends on the situation (Wander, Pursue, Attack or Hit.....). So the individual string of content is done easily by Manager's Listener FSM and Cached for sending. When the Sending Time comes the Cached strings are combined and Synced.
After the Manager gets the Sync Strings it will do frames of crazy job which split, convert, send to each related NPC's BT.

Here I paste the longest command string I got from DebugLog Action during last editor run:
SceneObjectManager : NPCListener : SendRPC2LMRPC : DebugLog : N^C^M%28%-151.5,0.2,11.5%182.5%-159.0,0.2,-5.1|M%103%-148.4,0.2,0.2%47.1%-143.2,0.2,9.0|M%171%-160.8,0.2,-2.9%206.0%-171.0,0.2,-14.3|M%183%-156.6,0.2,4.7%57.4%-142.3,0.2,10.4|M%232%-159.5,0.2,-0.5%217.2%-159.1,0.2,-2.7|M%233%-157.7,0.2,0.3%281.0%-160.4,0.2,-0.2|M%4%-170.9,0.2,4.7%12.0%-179.0,0.2,14.9|M%29%-155.0,0.2,12.0%171.4%-154.2,0.2,-7.9|M%96%-164.5,0.2,6.9%318.9%-159.0,0.2,12.1|M%167%-151.7,0.2,-3.2%96.7%-152.3,0.2,2.5|M%188%-152.7,0.2,2.3%137.2%-139.7,0.2,-9.3|M%231%-156.5,0.2,0.5%169.1%-161.4,0.2,-7.7|M%34%-165.0,0.2,-10.1%133.2%-149.9,0.2,-4.8|M%55%-168.2,0.2,-3.7%74.7%-164.5,0.2,-3.6|M%87%-151.7,0.2,-9.4%356.9%-145.3,0.2,0.2|M%89%-167.3,0.2,0.6%332.6%-163.5,0.2,6.8|M%104%-152.8,0.2,-8.0%70.3%-150.1,0.2,-12.3|M%126%-152.1,0.2,-6.3%4.8%-148.0,0.2,-3.3|M%129%-163.4,0.2,-3.5%216.8%-168.4,0.2,-22.1|M%131%-156.6,0.2,-7.8%173.9%-161.4,0.2,-16.3|M%137%-164.7,0.2,-0.5%228.1%-165.9,0.2,1.3|M%172%-161.1,0.2,4.5%198.0%-159.8,0.2,-1.0|M%184%-157.9,0.2,-5.3%165.8%-159.5,0.2,-8.1|M%186%-159.4,0.2,-2.5%276.8%-169.2,0.2,-2.3|M%196%-157.3,0.2,4.2%145.1%-155.1,0.2,4.7|M%230%-158.1,0.2,2.1%325.7%-155.2,0.2,12.2|M%234%-154.8,0.2,-0.8%347.7%-154.8,0.2,13.6

(There are 27 NPCs should "Move" to different places last 0.5 sec.)

Please help me with the ConvertStringToVector3's Regex Hurdle. It's beyond my knowledge. ;)
« Last Edit: February 15, 2017, 06:51:46 AM by human890209 »

human890209

  • Junior Playmaker
  • **
  • Posts: 62
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #13 on: February 15, 2017, 08:55:49 AM »
I tried to replace the ConvertStringToVector3 Action with the following Actions.
It works fine.

And I looked deeper in every GC Target, All caused by fsm.event(). When I go deeper, that FsmLog.Log...() is the "only" cause. I'm wondering if FsmLog.Log...() causes the GC which may only be activated on editor run? So Everything will work well if in a Built Run?

I closed the FSM Log window but FsmLog.LogEnterState() FsmLog.LogEvent() FsmLog.LogTransition() still appears.
What do FsmLog.Log...() do? Do they cause GC in a Built Run?
« Last Edit: February 15, 2017, 09:42:54 AM by human890209 »

human890209

  • Junior Playmaker
  • **
  • Posts: 62
Re: Performance Problem About PhotonViewRpcBroadcastFsmEvent
« Reply #14 on: February 15, 2017, 10:07:20 AM »
Find this Post:
http://hutonggames.com/playmakerforum/index.php?topic=13464.msg62620#msg62620

I'm satisfied  ;D

But keep asking about the FSM Number Sensitive Question. I think Playmaker is Number Sensitive (Activated FSM only), 10000 blank activated FSM will make my run really lag which I think State Tracing may consume performance. I tested on Number, C# the winner and PM the last one ;) (other Plugins are so-so). So we should make every FSM functions 10 times than a C# script. ;) Afterall No Compiling, Smooth, Integration Playmaker wins the war.  ;D

The test is simple: hundreds of box rotating. Using C# and other Plug-in to do that. You will find the difference.

So I don't put FSM like C# on Doors(eg for trigger open) if I got many Doors. I put FSMs and Colliders on Players or Managers to move them or choose C#.

And writing PlayMaker Actions by Nottorus is cool, Action Script can be debugged during run time in Nottorus. I've tested the combination but not started to do my project like that. Cause Original and Ecosystem Actions work great for me.
The PM+BD+Nottorus is the last weapon if I meat Performance Challange of Actions and Templates which I survived for now. :)