I am working on designing a websocket server which receives a message and saves it to an embedded database. For reading the messages I am using boost asio. To save the messages to the embedded database I see a few options in front of me:
- Save the messages synchronously as soon as I receive them over the same thread.
- Save the messages asynchronously on a separate thread.
I am pretty sure the second answer is what I want. However, I am not sure how to pass messages from the socket thread to the IO thread. I see the following options:
- Use one io service per thread and use the post function to communicate between threads. Here I have to worry about lock contention. Should I?
- Use Linux domain sockets to pass messages between threads. No lock contention as far as I understand. Here I can probably use BOOST_ASIO_DISABLE_THREADS macro to get some performance boost.
Also, I believe it would help to have multiple IO threads which would receive messages in a round robin fashion to save to the embedded database.
Which architecture would be the most performant? Are there any other alternatives from the ones I mentioned?
A few things to note:
- The messages are exactly 8 bytes in length.
- Cannot use an external database. The database must be embedded in the running process.
- I am thinking about using RocksDB as the embedded database.