[Libwebsockets] polling for file descriptor i/o

Andy Green andy at warmcat.com
Sun Mar 5 19:45:29 CET 2017

On March 6, 2017 2:04:36 AM GMT+08:00, Per Bothner <per at bothner.com> wrote:
>I do notice that poll is being called very frequently via
>the top-level lws_service function.  This seems to prevent
>the server from going to sleep when there is no activity,
>which is bad for energy usage.
>I tried setting the timeout parameter to -1 in the
>lws_service call, but then it just froze.

What happens if you set it to like 1000 (1s)?  If something is signalling POLLIN or POLLOUT (or POLLHUP...) the poll() will end early.  Otherwise the poll() will block / sleep for the timeout duration which is perfect for energy usage.

If nothing happening cpu is very low, like 0.01%, if something continuously happening it will be 100%.  So is something always wanting attention?

You can run the lws test server and measure cpu when idle as a comparison.

You should keep the poll timeout less than 1s because lws has to do timeout and other processing independent of network activity or not; it has a chance to do it each time it calls the service api.


More information about the Libwebsockets mailing list