Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
I read an issue stating that a lot of observers causes slowdowns(#17656), so I dived into the code and found that the networking part is done in a huge while loop(on a different thread) I'd like to propose the usage of asynchrous socket usage to solve the issues the loop creates
I suggest(and am currently writing a PoC) to use Sockets instead of TcpListener and use async calls like BeginAccept, EndAccept, BeginReceive, EndReceive to not have it all going in the same thread in a huge while loop. It would definitely make the server faster and able to handle more connections.
Since I'm new to the codebase I can't predict any side effects. As far as I can see it should work out of the box without negative side effects.
Keep the while loop, but god, why.
Thanks for pointing that out, didn't see that pull. It would conflict only in the Server.cs file though, since he wants to make a list of TcpListeners whilst I think it would be more efficient to just use async. But it will need some discussing with him then
OpenRA (like most RTS games) uses a deterministic lockstep model for networking, which is inherently synchronous. Making the sockets async won't help because the game clients still need to block on orders/sync data from all clients before simulating the next tick.
The real fix for spectator lag is to change the client handling so that spectators aren't expected to send non-immediate orders, and to change the main tick loop timings to allow spectators to tick as fast as possible to catch up if they end up behind.
@lifecoder-phoenix The fix for the spectator lag is to "disconnect" all spectators from the game so the player clients no longer wait for them. My server implementation already does that and it works (but can corrupt replays due to workarounds in the replay loading code).
If you want to rewrite the networking code for async, I strongly recommend using async/await/Task based on TcpListener over using the socket directly. TLS with ALPN (currently blocked by the migration to netstandard2.1) can only be done that way: