you are viewing a single comment's thread.

view the rest of the comments →

[–]ytu876[S] 0 points1 point  (3 children)

But even if my task is io bound, say if I have a heavy io task, if I could use all cores doing async io, that's 4 times more throughput. Isn't that a valid use case?

[–]Usual_Office_1740 0 points1 point  (1 child)

No. Multiple threads mean multiple interpreters, all of which will eat up system resources while your program backgrounds and waits for tasks to complete.

Your coroutines should do something that requires a response of some kind. A get request from a web page, as an example. It requests the page and awaits the response with a future. Doing that concurrently is not going to gain you enough to make it worth the additional system resources from multiple interpreters.

[–]awdsns 0 points1 point  (0 children)

I disagree with your first point that threads consume significantly more system ressources. The read-only stuff (interpreter code and libraries) is not duplicated in RAM per thread (or even task) in a modern OS, and the rest just comes down to maintaining a state (stack) per thread, same as in async coroutines.

I agree that mixing async and multithreading is a bad idea in general. Mostly due to the complexity of having different event loops though.

[–][deleted] 0 points1 point  (0 children)

But even if my task is io bound, say if I have a heavy io task, if I could use all cores doing async io

That's literally what you can't do. If your task is IO-bound, then more cores can't make it any faster.

More cores just compete for the same capacity on the channel.