Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connections handling by separate threads #78

Open
tomaszhlawiczka opened this issue Dec 28, 2023 · 1 comment
Open

Connections handling by separate threads #78

tomaszhlawiczka opened this issue Dec 28, 2023 · 1 comment

Comments

@tomaszhlawiczka
Copy link

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.

@qchateau
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants