Tokio for CPU intensive work

48 points HeavyMath2673

Hi,

I know there have been discussions around this topic before. But I am still a bit confused. So far we use Rayon for multithreading compute intensive tasks. However, with Rayon expressing task dependencies seems difficult.

Tokio with async await looks much nicer to express complex task dependencies (see e.g. https://docs.rs/async\_dag/0.1.2/async\_dag/).

But I am still unclear about the following points.

1.) A frequent argument seems that Tokio should not be used for CPU bound tasks but for I/O bound tasks. A good discussion on this point is given here: https://thenewstack.io/using-rustlangs-async-tokio-runtime-for-cpu-bound-tasks/, where the argument is made that Tokio is well suitable for CPU bound tasks but one should not use the same runtime for I/O bound and CPU bound workloads.

2.) Rayon has very nice parallel iterators, which Tokio does not seem to have. It is easy to work around this. But is this true or have I just not found the right Tokio docs for this?

3.) What about direct comparison of Tokio and rayon for CPU bound workloads. Is there any noticeable performance difference at all?

I'd be grateful for any comment on these topics.