[Libwebsockets] Scalability - overhead, perf, etc

Andy Green andy at warmcat.com
Sun Jan 22 22:47:55 CET 2017



On 23 January 2017 03:20:20 GMT+08:00, Joel Winarske <joel.winarske at gmail.com> wrote:
>What is the overhead per WS protocol implementation, when it comes to
>performance?  I'm thinking, event list looping overhead, threading,
>context
>switches, etc.  What is the point of diminishing return, when adding
>additional WS protocols?

Well once the protocol is negotiated, the individual connection object in lws points to the negotiated protocol struct directly.

One of the things in there is the associated callback pointer.  So there is no cost to having many protocols over having one for that common case of doing a callback.

If there were a huge number of protocols the negotiation would slow down a tiny bit but it's once per connection.

The only other time it cares is the api that asks for callback when writable "all protocol", meaning every connection using that protocol is asked to call back when it becomes writable.  This is the basic primitive for maintaining 'shared worlds', where every client should see the same event.

Connections using the same protocol on the same vhost are connected togther in a linked-list.  So skipping over connections that are on a different protocol costs nothing, it does not dumbly iterate all connections to broadside requests to all guys on one protocol.

>Would it be better to use a single WS, and unify an upper layer
>protocol,
>or multiple WS implementations with a thinly spread protocol?

Depends what you are doing, but generally the painful bloat here is less the lws overhead and more the issue of informing connections about events they ultimately filter or never cared about.  Eg if it was a server for doom, client events in one game session are of no interest to clients in a different game session.  So the choice of how many protocols should be aimed at optimizing network traffic for "callback on writable all protocol" if that's what you'll be doing a lot.

-Andy

>I know what my instinct tells me, but I would like to hear it from
>someone
>else ;)
>
>
>Also is the Nagle algorithm flag touched in libwebsockets?
>
>
>Thanks,
>Joel

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



More information about the Libwebsockets mailing list