driver2 Posted December 26, 2009 Share Posted December 26, 2009 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
eAi Posted December 26, 2009 Share Posted December 26, 2009 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
driver2 Posted December 26, 2009 Author Share Posted December 26, 2009 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
eAi Posted December 26, 2009 Share Posted December 26, 2009 All player positions are available client-side, though distant players may be somewhat less accurate or updated less often. If your checkpoints are already elements, then they already exist on each client... Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now