[Libwebsockets] polling for file descriptor i/o

Per Bothner per at bothner.com
Sun Mar 5 21:23:47 CET 2017

On 03/05/2017 10:45 AM, Andy Green wrote:
> 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)?

Noticable delays.

With 100ms timeout I don't notice any sluggishness.

> 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.

Better for energy usage if the timeout duration were infinity.

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

It's not my field, but I would expect the CPU could go into "deeper sleep"
(and thus use less energy) if it didn't get woken up by do-nothing timeouts
multiple times a second.
	--Per Bothner
per at bothner.com   http://per.bothner.com/

More information about the Libwebsockets mailing list