LiteNetLib icon indicating copy to clipboard operation
LiteNetLib copied to clipboard

Blocking mode support for pollevents

Open akash14darshan opened this issue 3 years ago • 5 comments

It's a cleaner approach to continuously process the events for server. For a high loaded server, we do not have to make the thread sleep when it shouldn't For a low loaded server, where Thread Sleep is set to 15ms or similar, this will prevent possible scenarios where packets wait for the same duration without any additional performance penalty

In other words: If packets are sent every 1ms, this will ensure that the packets processed every 1ms aswell. If packets are sent every 15ms, then also this will ensure that the packets will be processed at the same interval. If no packets are received, then the poll thread will remain blocked.

akash14darshan avatar May 20 '21 20:05 akash14darshan

So, uh... Why not take advantage of async instead of processing stuff on the update thread?

Edit: Like, Given the option, I would prefer not to handle network messages from my game server's update thread.

sunkin351 avatar Sep 11 '21 04:09 sunkin351

@sunkin351 this is not intended for multi threading. its a typical console based echo server use case scenario where you want to immediately respond back to any packet received without having to overshooting our cpu you can still use the good old Update method polling if you dont want to stick with this method :)

akash14darshan avatar Sep 11 '21 11:09 akash14darshan

Just curious, what is your use case that you would need changes like this?

sunkin351 avatar Sep 11 '21 18:09 sunkin351

Any PCM signal. Application was VoIP in my case which needs a constant spacing

akash14darshan avatar Sep 16 '21 09:09 akash14darshan

It's a cleaner approach to continuously process the events for server. For a high loaded server, we do not have to make the thread sleep when it shouldn't For a low loaded server, where Thread Sleep is set to 15ms or similar, this will prevent possible scenarios where packets wait for the same duration without any additional performance penalty

In other words: If packets are sent every 1ms, this will ensure that the packets processed every 1ms aswell. If packets are sent every 15ms, then also this will ensure that the packets will be processed at the same interval. If no packets are received, then the poll thread will remain blocked.

It is better to use UnsyncedEvents (or UnsyncedReceiveEvent) in this case

RevenantX avatar Oct 31 '21 12:10 RevenantX