[Libwebsockets] Consistent delay of 20 seconds on mac for LWS_CALLBACK_CLIENT_WRITEABLE

Andy Green andy at warmcat.com
Thu Oct 15 06:20:05 CEST 2015



On 15 October 2015 13:11:35 GMT+09:00, Bruce Perens <bruce at perens.com> wrote:
>This could be the event leak problem. Check out the source and
>recompile,
>Andy has merged patches this evening.

No... on older lws Tor is using, it had no way to interrupt the poll() if the socket fds in the wait were all quiescent.  So if you set a poll timeout of 10s, no peer sends anything, but another thread decides he wanted to send something, he's SOL and just has to twiddle his thumbs until the poll() times out and restarts with his POLLOUT on the new events.

So it's not a 'bug' so much as at that point lws lacked support for breaking into a poll() wait when you wanted to update the POLLxxx flags.  Nowadays it knows how to dothat.

-Andy

>On Wed, Oct 14, 2015 at 8:25 PM, Andy Green <andy at warmcat.com> wrote:
>
>>
>>
>> On 12 September 2015 01:56:41 GMT+09:00, Tor Krill
><tor at openproducts.com>
>> wrote:
>> >Hi,
>> >
>> >A bit late on this matter but i think i'm seeing a similar problem.
>> >This
>> >is however on a x64 Linux computer.
>> >
>> >I have a similar setup. A separate thread service the websocket
>library
>> >(libwebsocket_service) and i process incoming data in that context.
>> >
>> >But when i want to send data not triggered by some received data i
>do
>> >this in another thread that queues a message and then signal
>> >libwebsockets, via libwebsocket_callback_on_writable_all_protocol,
>that
>> >there is data to be sent.
>> >
>> >The libwebsockets thread then sends the data when it revecives the
>> >LWS_CALLBACK_CLIENT_WRITEABLE reason in its callback.
>> >
>> >This setup seems to work ok but i run in to a similar problem to
>that
>> >shyam describes below.
>> >
>> >Data won't be be sent until the libwebsocket_service times out. I.e.
>if
>> >i do a:
>> >
>> >libwebsocket_service( context, 1000);
>> >
>> >it takes a second before any message is sent. I.e. the same time as
>the
>> >timeout is set to. If i change the timeout, the delay before sending
>a
>> >message is also changed.
>> >
>> >When reading up on the documentation i see a
>> >
>> >libwebsocket_cancel_service
>> >
>> >Which indicates that it could interrupt the service routine?
>> >
>> >Unfortunately the packaging of libsockets on my distro seems a bit
>old
>> >and don't have that function call.
>>
>> Yes you need this.  Because otherwise unless some action happens on
>the
>> socketsin the poll() wait, there's no way for poll() to understand it
>> should end the wait early.
>>
>> -Andy
>> >
>> >Am i doing things wrong here? Are there any other way to make the
>> >service routine process the write request more immediately?
>> >
>> >Best!
>> >
>> >/Tor
>> >
>> >
>> >On ons, 2015-08-26 at 12:38 +0000, shyam goyal wrote:
>> >> Hi,
>> >>
>> >>
>> >> I am using Libwebsockets library for real time communication in
>one
>> >of
>> >> my project. The library works extremely well on Windows and giving
>> >> very good performance also. But I am seeing some problem on Mac.
>> >There
>> >> is always a delay of 20 seconds before the socket is available
>again
>> >> for writing on Mac. I have registered the callback and waiting for
>> >> "LWS_CALLBACK_CLIENT_WRITEABLE" before writing a new message on
>the
>> >> socket. I am not able to figure it out why there is this
>consistent
>> >> delay of 20 seconds.
>> >>
>> >>
>> >> I am using lot of threads in my application while using the
>> >> LIBWebSockets. There is one thread running the service loop, one
>> >> thread writing the messages to the socket and the last thread to
>> >> process the messages received by the socket from the server.
>> >>
>> >>
>> >>
>> >> Please guide me how to resolve this. Do you think building the
>> >> libwebsockets with LIBEV can be of some help?
>> >>
>> >>
>> >> Regards:
>> >> Shyam Sunder Goyal
>> >> _______________________________________________
>> >> Libwebsockets mailing list
>> >> Libwebsockets at ml.libwebsockets.org
>> >> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
>>
>> _______________________________________________
>> Libwebsockets mailing list
>> Libwebsockets at ml.libwebsockets.org
>> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
>>




More information about the Libwebsockets mailing list