Closed tomaszhlawiczka closed 2 months ago
Hi,
I've never thought about this too much but there is no intended mecanism for a procedure to identify the source connection, meaning you can't dispatch the work based on the connection. That said you have access to a fully async server so you don't need to have one thread per client to maximize CPU occupancy, you can just run the io_context on many threads. You can also have two thread pool, one for the io_context and one to process the CPU intensive part of your processing if you can to make sure the io_context will not starve.
Is there a way to handle each connection by a separate thread?
Background: clients keep the connections alive (connection pool) for long period of the time to send many requests to one connection (one after another). Processing of a request, including reading it and writing it to the socket, is quite heavy (consumes a lot of CPU).
How can I start a new thread for each connection, right after
accept()
? The new thread suppose to be created once for entire connection, not for each request.Thank you in advance.