Author Topic: SetChannelData Performance / Best Practice  (Read 207 times)

rxmarcus

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 60
    • View Profile
SetChannelData Performance / Best Practice
« on: September 05, 2017, 03:18:59 PM »
I have lots of "game match" related data in my game currently (like teams, player stats, etc) that I've been tracking manually, and I instead want to let TNet do the heavy lifting.

I'm wondering what the best practices / structuring of data using the SetChannelData method is? I assume using a DataNode is a good way to do things.... but let's say I want to update a single stat for a player.... will it be a hit on performance / bandwidth if I have a single DataNode object that holds a large number of children nodes which in turn could hold a ton of player stats nodes?

For example, a player gets a kill, so I want to update in my stats that the player has +1 kill now. Will that require that the entire node object gets serialized, sent over the network and deserialized on everyone elses clients?

Just looking for some direction / best practices with dealing with this type of data and syncing it easily using TNets toolset.

cmifwdll

  • Global Moderator
  • Full Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 132
  • Posts: 241
  • TNet Alchemist
    • View Profile
Re: SetChannelData Performance / Best Practice
« Reply #1 on: September 05, 2017, 08:45:22 PM »
I'd look at what you're already syncing over the network. For example, I'm sure each client already knows when a player is killed, so why not perform the +1 kill in that existing net call?

But if you've got data that isn't already known to every client that you want to sync: each channel's data is already a DataNode, and SetChannelData takes the path within the hierarchy and the value you want to set. This is the only data that's sent over the network: the string and the object. The value should be kept as a primitive if you're concerned about performance.
An example: TNManager.SetChannelData(2, "PlayerOne/Kills", 2)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 327
  • -Receive: 1153
  • Posts: 22,063
  • Toronto, Canada
    • View Profile
Re: SetChannelData Performance / Best Practice
« Reply #2 on: September 06, 2017, 01:02:06 AM »
Personally, I use the following rules:
- If something can be set several times per second, make it an RFC.
- If something should be associated with an object, use tno.Set.
- If something should be associated with the channel, use TNManager.SetChannelData.
- If something should be server-wide, and only set by admins (such as configuration data), use TNManager.SetServerData.

For player kills, I wouldn't set them as channel data. That seems like an odd place for something that's player-related. Use tno.Set("kills", 123) instead on the player's avatar.

rxmarcus

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 60
    • View Profile
Re: SetChannelData Performance / Best Practice
« Reply #3 on: September 06, 2017, 10:58:32 AM »
Thanks for the recommendations!