[Libwebsockets] libwebsocket message loop thread take 100% of the CPU

Andy Green andy at warmcat.com
Thu Sep 24 09:44:56 CEST 2020



On 9/24/20 8:32 AM, Peiffer Eric wrote:
> 
> Hi,
> 
> I have another question about the same issue. Our application use 2 
> libwebsockets context in the same process, but two different threads:
> The first context for a web socket server that connect about 300 clients
> The second for clients web socket, some thousand client connect to a 
> external web socket server.
> 
> For both context: info.fd_limit_per_thread = 0;
> Is there any conflict for example file descriptor or memory  or socket, 
> between the two context?

It's not an lws thing, but fds are a processwide resource, so naturally 
two threads in the same process operate from the same pool of fds.

How much physical memory you have is a devicewide thing, naturally two 
threads whether in the same process or not compete for that.

> In this case which parameters I have to adjust?

fd_limit_per_thread as zero means use whatever the process has without 
making a lower limit.  On Linux (you don't mention your platform...) 
that's set by ulimit -n, and that in turn defaults to whatever it set by 
sysctl -w fs.file-max=

On recent lws, if you are on unix, you have the option to set 
.rlimit_nofile in the context creation info struct

https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-context-vhost.h#n764

this will attempt to change the file limit for the current process 
before continuing to create the context.  If you start your app as root 
and then drop privileges, this can provide a convenient way, but have a 
google for linux soft and hard limits for ulimit if problems.

-Andy

> Regards,
> 
> Eric
> 
> ------------------------------------------------------------------------
> *De :* Andy Green <andy at warmcat.com>
> *Envoyé :* mercredi 16 septembre 2020 13:48
> *À :* Peiffer Eric <eric.peiffer at al-enterprise.com>
> *Objet :* EXT: Re: EXT: Re: EXT: Re: [Libwebsockets] libwebsocket 
> message loop thread take 100% of the CPU
> 
> ** External email - Please consider with caution **
> 
> 
> On 9/16/20 12:29 PM, Peiffer Eric wrote:
> 
>>
>> You don't mention the lws version I would definitely try master and see
>> if acts the same.
> 
> Advice is still the same, try master.  v3.2 is not maintained any more,
> v4.0 and v4.1 now are released after that.
> 
>> And you don't mention your platform.
> 
> What's the platform?
> 
>>> But I have activated the trace in libwebsockets. When this issue occurs
>>> no more event are fired except the LWS_CALLBACK_EVENT_WAIT_CANCELLED.
>>
>> So it's still going around the event loop...
>>
>>> The remote part then close the web socket because no more data are rsend
>>> from our application.
>>
>> ... it's this one connection that suffers that or everything that is
>> connected drops dead?
>>
>> The problem goes away when this one connection is closed?  Or it does
>> not understand it should be closed and that makes the spinning?
>>
>> The symptoms are the following;
>> for a unexpected reason  our application that open a large number of
>> client web socket connections to a web socket server, does not received
>> any more event from libwebsockets (no LWS_CALLBACK_CLIENT_ESTABLISHED,
>> no LWS_CALLBACK_CLIENT_WRITEABLE, , .LWS_CALLBACK_CLIENT_RECEIVE..)  only
>> LWS_CALLBACK_EVENT_WAIT_CANCELLEDis received , then none web socket
>> client are notified for incoming data and can not send data. Then the
>> web socket server (the remote part) close all client web socket. When
>> our application try to re open the client web socket it fails and we get
>> the trace below:
> 
> So can you remove your application from the isse and reproduce it just
> with, eg, lws + apache or something I can try here?
> 
> But first see if the problem still exists on master...
> 
> -Andy
> 
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets
> 


More information about the Libwebsockets mailing list