This is a flaw of the polling strategy used by the Server:
Async code runs in separate threads, waiting for messages coming from clients
Sync code tries to pull messages from a shared channel, but it does this in a loop
So currently in the sync code, if there are no messages found in the shared message channel, will just loop back and check again, again, again, until there is a message. This constant checking uses near 100% of CPU.
How does one fix this? One solution would be to remove the Sync code ... unfortunately, this would break the Bevy adapter.
The other solution might be to constantly measure time between new incoming messages, and then at the average measured duration. This makes the Server potentially less responsive, but it will poll less frequently.
I need to learn what strategies have been used in the past to overcome this - it's a common, old problem for Servers. If anyone has any ideas or any learning resources .. please let me know!
This is a flaw of the polling strategy used by the Server:
So currently in the sync code, if there are no messages found in the shared message channel, will just loop back and check again, again, again, until there is a message. This constant checking uses near 100% of CPU.
How does one fix this? One solution would be to remove the Sync code ... unfortunately, this would break the Bevy adapter. The other solution might be to constantly measure time between new incoming messages, and then at the average measured duration. This makes the Server potentially less responsive, but it will poll less frequently.
I need to learn what strategies have been used in the past to overcome this - it's a common, old problem for Servers. If anyone has any ideas or any learning resources .. please let me know!