Skip to content

Conversation

@BlackWolf
Copy link

This commit changes the polling behaviour to exploit the blocking behaviour of libwebsocket_service().
This means:

  1. The dispatch timer is now fired immediately
  2. libwebsocket_service() is called with a very long timeout, which will block until the callback is called. After the callback has been executed, the dispatch timer will fire immediately again

In some small tests, I could see a large improvement of round-trip-time, in particular when lots of small messages are received in rapid succession (up to 50% less RTT). There seems to be no increase in CPU usage. The only downside I can think of is that the networkQueue is blocked, which shouldn't matter as its only purpose is to wait for an event and execute the callback.

Note that such an approach is also mentioned in the API description of libwebsocket_service:

"Alternatively you can fork a new process that asynchronously handles calling this service in a loop. In that case you are happy if this call blocks your thread until it needs to take care of something and would call it with a large nonzero timeout. Your loop then takes no CPU while there is nothing happening." (https://libwebsockets.org/libwebsockets-api-doc.html)

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

Successfully merging this pull request may close these issues.

1 participant