fishfolk / jumpy

Tactical 2D shooter in fishy pixels style. Made with Rust-lang 🦀 and Bevy 🪶
https://fishfolk.org/games/jumpy/
Other
1.64k stars 117 forks source link

Networking: Network latency unexpectedly high, impacting performance #843

Closed MaxCWhitehead closed 5 months ago

MaxCWhitehead commented 1 year ago

Description

It seems that when running two clients in an online game on same machine, latency is much higher than expected.

Both clients are simulating near the max prediction window of 8 frames ahead. They often hit the maximum and freeze waiting for inputs to be replicated. Neither client is falling behind or having a hard time keeping up, but their inputs sent to one another seem to take 6-8 frames to get processed by other client, at 60fps this is over 100ms.

This does not seem like normal latency for clients on the same machine, this needs investigation. It is possible the async tasks used to implement network socket and buffering of messages may not be getting scheduled right away. This is just a guess.

This latency causes large rewinds and substantially impacts network performance.

MaxCWhitehead commented 1 year ago

I realized two clients on same machine are not directly connected - they are proxied via matchmaking server. 100ms latency seems pretty plausible. Predicted frames idles between 5 and 6 ahead, which lines up with 100ms latency at 60fps.

Sometimes when idle the predicted frames goes up, spikes and dips, sometimes freezing. Either the latency/thoughput of proxy is not stable, or clients have local performance issues causing to delay input replication.

Attached are graphs of predicted frame count of each client, both taken while idling in online match with default match maker.

image image

MaxCWhitehead commented 1 year ago

In a LAN game, one client is near 0, and other couple frames ahead, performance here is strong, latency is near 0. Not totally clear why one client is consistently ahead of the other, will look into it.

image

MaxCWhitehead commented 1 year ago

And this is example of match making server run locally on same machine as two clients. Similar behavior to LAN.

image

MaxCWhitehead commented 1 year ago

Running matchmaker / connection proxy on another machine in my home also produces lower latency, it seems like a good chunk of this problem is just latency between my home and matchmaking server.

image

I do see a bit of instability in graph though, going to visualize ping and see if this correlates, or if it's client performance.

MaxCWhitehead commented 5 months ago

Closing this, is an old issue and I def have large latency to server. This will improve once multi-regions is implemented. The inbalance of prediction between two clients is something that will happen, and GGRS occasionally requests the one that is ahead for an extended period of time to skip frames to balance this out and reduce frame advantage.