[Libwebsockets] Repetitive LWS_CALLBACK_SERVER_WRITABLE making cpu load 99%

Shmuel Weiss sweiss at kramerel.com
Sun Jul 3 20:00:09 CEST 2016


Thread still at 99%.

My HTTP callback is called 4 times with LWS_CALLBACK_LOCK_POLL and then my WEBSOCKET callback once (every 200msec, corresponding to my TIMEOUT in  lsw_service).

But why the HTTP callback is called so many times? What means this LOCK_POLL event ?

Thanks.


-----Original Message-----
From: Andy Green [mailto:andy at warmcat.com] 
Sent: Thursday, June 30, 2016 02:24
To: Shmuel Weiss; libwebsockets at ml.libwebsockets.org
Subject: Re: [Libwebsockets] Repetitive LWS_CALLBACK_SERVER_WRITABLE making cpu load 99%

On Wed, 2016-06-29 at 23:17 +0000, Shmuel Weiss wrote:
>  I have to check, I am not using neither compiling the testserver.
> Tell me if the flow is as following:
> 
> My Main loop is doing the following 
> 
> while(running)
> {
> 	For all my protocol do:
> 		lws_callback_on_writable_all_protocol(context,
> protocol);
> 
> 	lws_service(context,timeout); ===> here it is no more waiting.
> }
> 
> My LWS Callback is doing:
> 
> ONREAD:
> 	Read the data send and send it to the main engine for processing
> 
> ONWRITE:
> If lws_partial_buffered != 1

It's not a problem, but lws guarantees if there is some partial buffered, you will not get the WRITEABLE callback again until it has been cleared, basically it uses up the writability internally to clear the buffered partial first.

So you only need that check if you will loop sending things in your WRITABLE callback.

> 	Check if there is something to send from the main engine and send it 
> Else
>  	lws_callback_on_writable();

This means you will continuously get WRITEABLE callbacks...

> I expected to have ONWRITE called each time lws_service returns after 
> timeout, but it never blocks (except at startup until the first ONREAD 
> happen).

That is not how poll() works.  If any of his fds have active events, he returns immediately.  If nothing has any events, he will return anyway after the timeout period.

So you are getting exactly what you asked for here I think.

-Andy

> 
> -----Original Message-----
> From: Andy Green [mailto:andy at warmcat.com]
> Sent: Thursday, June 30, 2016 00:11
> To: Shmuel Weiss; libwebsockets at ml.libwebsockets.org
> Subject: Re: [Libwebsockets] Repetitive LWS_CALLBACK_SERVER_WRITABLE 
> making cpu load 99%
> 
> On Wed, 2016-06-29 at 20:02 +0000, Shmuel Weiss wrote:
> > Hi Andy,
> >  
> > A new phenomena.
> > The  LWS main thread is quiet until I initiate the first
> connection,
> > where sending data and receiving data is OK but since this moment
> the
> > lws_service function doesn’t block until timeout and process 
> > immediately even if no data arrived.
> >  
> > What I missed ?
> 
> Does the test server, without your code, act like that?
> 
> -Andy
> 
> > My lws callback return 0 , should I return -1 ?
> >  
> > thanks
> > This mail was sent via Mail-SeCure System.
> >  _______________________________________________
> > Libwebsockets mailing list
> > Libwebsockets at ml.libwebsockets.org
> > http://libwebsockets.org/mailman/listinfo/libwebsockets
> This mail was sent via Mail-SeCure System.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libwebsockets.org/pipermail/libwebsockets/attachments/20160703/3ec25a70/attachment.html>


More information about the Libwebsockets mailing list