RPC call optimization in Multiplayer API

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gmaps


I started with the implementation of multiplayer for a RTS game. I don’t want to implement lockstep architecture, so I decided to create a server, to which all the clients report commands, and the server returns the unit position/rotation/state/etc on each frame.

There are a lot of rpc calls, as there can be up to 1000 units. The game will be capped at 60fps. So I have next questions:

Does underlying logic aggregate the rpc calls (set_position, set_rotation etc) into large UDP requests, and sends them once per frame, or does it send an UDP request for each rpc call (which would be like 1000 * 60 * ~5 = 300k calls per second in my case? Or is an “In between” solution implemented?

If it sends an request for each rpc, I have to manually create a function that sends all the parameters for all units once per frame?

I don’t know about optimizations done by Godot (AFAIK it just uses ENet), but I’d consider not sending things every frame if there are many, maybe once every 4 frames maybe, so you can spread out the load and interpolate on the client.

Zylann | 2019-07-12 13:40

Yeah, it makes sense not to do it every frame. I implemented a simple master - slave configuration, and its working well for now. Master is computing all the physics, states (animations) and other parameters (HP, number of bullets, etc) and sending transforms and events with timestamps to puppets. Puppets then interpolate between the transformations for location and are latency + fixed 50ms interval behind the master, so the game runs smoothly. In this way, the master has slight advantage, but unless the latency’s really high, it’s no big deal.

gmaps | 2019-07-22 19:32