Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enet_host_service performance #223

Open
DevilLord41 opened this issue Mar 10, 2023 · 1 comment
Open

enet_host_service performance #223

DevilLord41 opened this issue Mar 10, 2023 · 1 comment

Comments

@DevilLord41
Copy link

Hi,
I have enet_host_service with timeout 0ms on client and it seems eating my cpu alot compared to using 10ms.
while (enet_host_service(client, &event, 0) > 0) {
using 10ms seems work, but not always because sometimes my client cant send packet anymore but still able to receive packet.

@mman
Copy link

mman commented Mar 10, 2023

@DevilLord41 actively polling socket with 0 timeout like this will always consume lot of CPU. It's best to combine with some higher level routines like select(2) or poll(2) so that you only call enet_host_service when you know the the underlying socket is readable - some data are waiting in the kernel to be read, or after you generate a packet to be sent, and eventually re-sent.

Logic I have come up with calls enet_host_service periodically to make sure outgoing packets, and pings are sent and re-sent as needed and fast enough, say 10 times per second, and then I call it immediately I am notified when data is available.

There is unfortunately no magic here, you have to do the plumbing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants