[Libwebsockets] advice on best way to implement ws_server for my use case

Dave Horton daveh at beachdognet.com
Sun May 19 23:58:52 CEST 2019

Thanks.  In the minimal example, I am not quite clear on the purpose of this line:

lws_set_timeout(wsi, PENDING_TIMEOUT_THREADPOOL, 30);

which is called when a new connection (wsi) is created.

Is it because it expecting the task to “check in” at least every 30 secs?  What happens if the timeout is reached?  What resets the timeout?
On May 18, 2019, at 14 PM, Andy Green <andy at warmcat.com> wrote:

On May 18, 2019 11:59:25 AM PDT, Dave Horton <daveh at beachdognet.com> wrote:
> My use case is lots of clients connecting via websockets to my server,
> each client sending lots of data (e.g audio or video feed), minimal
> data going from server to client, and the server needing to do some
> computationally expensive processing of the data once received.  Would
> either the minimal-ws-server-threads or minimal-ws-server-threadpool
> examples be a better starting point for me?  Or something else?  Before
> I get started I just thought I would ask for a quick word on how you
> would architect a server app like this.  Thanks

If it doesn't have to happen in realtime, it should be possible, but you only have so many cpu cores and so much memory, so it will mainly feel resource constrained if there are "lots of clients"... they ultimately find it's busy and they have to wait.

Threadpool looks like a good fit from what you described... it understands it can only have n threads going,  and other guys waiting must queue. It also hides and manages the async io.  Although what it gives you for your pool are pthread threads, actually you can wire it up to a spawned process stdin and stdout in there.



...gives another example of how it can be used with http rather than ws in the minimal example.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20190519/0f6c03db/attachment.htm>

More information about the Libwebsockets mailing list