Jump to content

Optimizing Client/Server Communication


driver2

Recommended Posts

Hi,

I've been making lots of scripts that use events to communicate. However, I can't really assess which changes might be sensible to optimize network traffic.

I want to send something in a pretty small intervall (like 500ms) to all clients, like:

triggerClientEvent(client,"onClientEventName",root,"doThis",123456)

I can't really tell how much an impact will that really have on the network traffic, also compared to what MTA uses for syncing the other stuff, and thus how much work should be put into optimizing it. Maybe someone can help me and clear up some of the questions:

1. Does it make a difference to trigger the event on all players one by one in a loop or trigger it once to root?

2. Does it make any sense to use shorter Event Names? Of course, in this case having a readable name that is unique might be more important, but still, does it make a difference?

3. Does it make a difference to use a single table in one argument for all the data or to put each chunk of data in argument by itself?

4. Would {123456} instead of {12345,6} save a significant amount given the short intervall?

Greetings

Link to comment

The format of the event packet can be seen in the code here: http://github.com/multitheftauto/multit ... Packet.cpp

So its:

2 bytes for name length

The name itself (however many bytes that is)

The element ID you triggered it on

The number of arguments

The arguments themselves

1: Not in terms of network performance, but it will probably be slow the server down more

2: Yes, shorter event names will make the packet shorter, but the effect will probably be negligible, unless you've got really long names.

3: Fewer, larger events is probably better than smaller events in general as there's an overhead for each event you trigger.

4: Sending {123456} vs {12345,6} would save up to 4 bytes per packet, depending on how well the compression works. This would probably equate to under 10% of the packet length in practice.

Bear in mind that sending a table has an overhead and using keys in tables will have an overhead.

I'd be interested to know what you're sending, there may be a better way to do it.

Link to comment
I'd be interested to know what you're sending, there may be a better way to do it.

I need to send the distance each player on the server travelled. The more often it is sent, the smoother the display. Would you care to optimize it further, or is it negligible compared to other stuff?

I need to do the calculation serverside because I need the checkpoints to do it and I'm not sure if sending all checkpoints to the client is a good idea. I also don't know if all player positions are always available clientside?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...