Tokio for compute bound tasks #5068
-
Hi, I have been trying to figure out how good Tokio is for compute purposes and this resulted in an active Reddit discussion a few days ago. The main pro and cons arguments seemed to be as follows: Pro:
Cons:
At the moment we are tending towards the decision to stick with Rayon for compute tasks even though this would limit some more complex tasking scenarios. I'd be very interested to hear more opinions about this topic from the Tokio community. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
It certainly can work for this, it's just not what it is designed for. Tokio is designed around the assumption that tasks are going to be generally nonblocking and will yield to the runtime frequently. This assumption is baked into a number of things, such as our parking routine and our workstealing implementation. I'd generally suggest sticking with Rayon for compute-bound workloads. If you have a workload that is bound by both IO and compute, then I would recommend mixing Tokio with Rayon. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your response. Do you know of any plans or a project that aims to develop a compute optimised task scheduler for async/await? There are lots of compute applications that would strongly benefit from concurrency directly baked into the programming language. Rayon is great. But its fork/join model is much less flexible than async/await would be. |
Beta Was this translation helpful? Give feedback.
It certainly can work for this, it's just not what it is designed for. Tokio is designed around the assumption that tasks are going to be generally nonblocking and will yield to the runtime frequently. This assumption is baked into a number of things, such as our parking routine and our workstealing implementation.
I'd generally suggest sticking with Rayon for compute-bound workloads. If you have a workload that is bound by both IO and compute, then I would recommend mixing Tokio with Rayon.