[Libwebsockets] libwebsocket vs regular-sockets performance

Andy Green andy at warmcat.com
Wed Nov 13 22:18:16 CET 2013

Hemant Kumar <hkumar at arubanetworks.com> wrote:
>Thanks!! Edwin.

Yes thanks for explaining Edwin.

>I read the RFC part regarding masking data from client to server and
>that a random key is generated out of possible 32 bit values to mask
>the data. The same is not applicable from server to client data.
>I don't have any active connection extension, so going through the code
>of libwebsocket_write(), I still do not expect overhead of 4 ms just
>because we are masking and framing the data everytime we send. Can you
>please further clarify on the mechanism for client packet send when

You have the lws sources, so if you want to understand you can read them.

Only you have your test sources though so if you want us to understand or reproduce or debug your situation you should provide them.

If you're seeing latencies or bad performance you can also instrument the code directly and measure where it's coming from.

You don't say what is receiving the data, a browser or another lws client?  If it's a browser, it has the overhead of collecting the data into a large javascript object as part of receiving it.

I didn't see what platform you are on, you can also use perf on Linux or even top to understand where the time is going.  Windows no idea, but someone was saying recently there are problems with spinning in wsa sockets there.


>libwebsocket_write() which can add extra overhead. The handshake
>mechanism is done only at the beginning and from the capture data , it
>doesn't seems heavy either.
>From: Andy Green [extracats at googlemail.com] on behalf of Edwin van den
>Oetelaar [andy.green at linaro.org]
>Sent: Wednesday, November 13, 2013 11:12 AM
>To: Hemant Kumar
>Cc: libwebsockets at ml.libwebsockets.org
>Subject: Re: [Libwebsockets] libwebsocket vs regular-sockets
>Websockets are not just streaming sockets like TCP they add an extra
>layer and Framing.
>Please read : http://tools.ietf.org/html/rfc6455
>Quoting from the RFC:
>o  adds a web origin-based security model for browsers
>o  adds an addressing and protocol naming mechanism to support
>      multiple services on one port and multiple host names on one IP
>      address
>o  layers a framing mechanism on top of TCP to get back to the IP
>      packet mechanism that TCP is built on, but without length limits
>o  includes an additional closing handshake in-band that is designed
>      to work in the presence of proxies and other intermediaries
>Have a good day,
>Edwin van den Oetelaar
>On Wed, Nov 13, 2013 at 8:03 PM, Hemant Kumar
><andy.green at linaro.org<mailto:andy.green at linaro.org>> wrote:
>I am performing some benchmarking study for traffic flow in between
>libwebsocket client -server and regular tcp client-server. My tcp
>client is making writes  to blocking sockets.
>I am sending 1000 MB of char buffer. In case of regular tcp sockets, it
>takes Total time of 4 sec 525 ms 317 us 0 ns but in case of websockets,
>it takes total time of 8 sec 844 ms 365 us 832 ns.
>This experiment was conducted on same local machine so , in between
>network latency is not involved.
>I have couple of questions based on above observation:
>1. I understand that websocket is doing some protocol specific
>operations when we call libwebsocket_write() , it does some operations
>,calls lws_issue_raw() and then calls send().
>My callback is sending data in chunks of 64K , even 32 K also yields
>the same result.
>I want to understand, if websocket does HTTP processing only for
>handshake and after that, it is supposed to muck only pre-append and
>post-append buffer , when we send TEXT/BINARY data, then is the
>overhead of protocol specific operations  add on to increase the time
>of transfer of
>buffer data to almost double in comparison to normal socket case.
>2. When I send websocket messages all filled with character lets say
>'5',and capture the same of wireshark, I do not see character 5 in
>payload of HTTP. Every time, I repeat the experiment it prints
>different character. When I send Binary data, (use LWS_BINARY) is it
>supposed to send just binary without any encoding and when I send
>LWS_TEXT, is it not supposed to send plane text. Is there some kind of
>encryption or encoding involved for every message sent? If so, is it
>base64 encoding ? Can I turn off these encoding of data and see what I
>send on wireshark capture?
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org<mailto:Libwebsockets at ml.libwebsockets.org>
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org

Sent from my Android device with K-9 Mail. Please excuse my brevity.

More information about the Libwebsockets mailing list