Using CAF with Boost.Beast

84 views
Skip to first unread message

Krzysztof Woś

unread,
Feb 13, 2020, 11:37:15 PM2/13/20
to actor-framework
I would like to build an application that uses CAF for concurrency. The app requires a REST API and hundreds or perhaps even thousands of WebSocket listeners. The architecture of what I have in mind is reminiscent of https://stiffstream.com/en/docs/shrimp-demo.html, which is also built on top of an actor framework. The request comes through a REST API and triggers a CPU-intensive task that depends on data obtained from WebSocket listeners, database, etc.

I am wondering how to fit similar pattern into the CAF model. In particular, I would like to run Asio in a multi-threaded context, with multiple threads serving IO to allow hundreds or thousands of WebSocket connections. Potentially I would also like to use separate thread pool for REST API and WebSocket IO. The networking part is easy enough: create separate IO context for each group of IO tasks and then dedicate some threads to run the first one and some threads to run the other. But how to combine this with CAF to implement processing of all that data?

Dominik Charousset

unread,
Feb 16, 2020, 2:46:26 PM2/16/20
to actor-f...@googlegroups.com
> I would like to build an application that uses CAF for concurrency. The app requires a REST API and hundreds or perhaps even thousands of WebSocket listeners. The architecture of what I have in mind is reminiscent of https://stiffstream.com/en/docs/shrimp-demo.html, which is also built on top of an actor framework. The request comes through a REST API and triggers a CPU-intensive task that depends on data obtained from WebSocket listeners, database, etc.
>
> I am wondering how to fit similar pattern into the CAF model. In particular, I would like to run Asio in a multi-threaded context, with multiple threads serving IO to allow hundreds or thousands of WebSocket connections. Potentially I would also like to use separate thread pool for REST API and WebSocket IO. The networking part is easy enough: create separate IO context for each group of IO tasks and then dedicate some threads to run the first one and some threads to run the other. But how to combine this with CAF to implement processing of all that data?

CAF already has its own thread pool for scheduling actors. I think the simplest model is having one thread pool for parsing HTTP requests and doing I/O and then just sending to CAF actors. CAF then will take take of putting those actors onto available threads. Also, CAF actors have a couple hundred bytes overhead each, so you can spawn *many* of them.


Hope that helps,

Dominik

Krzysztof Woś

unread,
Mar 3, 2020, 10:55:53 PM3/3/20
to actor-framework
I have cobbled together an example of how to use Beast with CAF


However, it is far from being satisfactory. I am trying to design a nice interface for the WebSocket actor so that the REPL part could also be written as an actor that would both receive messages from the WebSocket actor when messages are read from the WebSocket and send messages to the WebSocket actor when user types something in the terminal.

Any opinions, suggestions, critique, etc. would be much appreciated.
Reply all
Reply to author
Forward
0 new messages