Boost :: asio multithreaded issue

Ive got a server that uses boost::asiowhich I want to do multithreaded.

The server can be divided into several "areas", with sockets starting in the connection area, and then after connecting to a client that moves to the authentication area (that is, login or register), before moving between various other parts of the server, it depends on what makes the client.

I don’t want to just use the thread pool in one io_servicefor all sockets, as a large number of locks will be required, especially in areas with a lot of interaction with shared resources. However, instead, I want to provide each server component (e.g. authentication) with its own thread.

However, I am not sure how to do this. I considered the idea of ​​giving each component its own io_service so that it could use whatever streams it wanted, however the socket area is tied to io_service, and I'm not sure how then to move the client socket from one component to another.

+3
source share
2 answers

You can solve this with asio::io_service::strand. Create a thread pool for io_service, as usual. Once you have established a connection with the client, from there end all asynchronous calls with io_service::strand. One thread per client. This, in essence, ensures that from the point of view of the client it is single-threaded.

+4
source

-, ; , .

, - , (, (SQL, Voldemort (persistant) Redis ( - , ), memcached () ) - .

, , , UNIX sendmsg() . , .

. , , , . , IO - SSD .. - , , CPU; , , , ( ) SMP.

, , , , . .

+2

Source: https://habr.com/ru/post/1725071/


All Articles