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

Documentation misleading suggests tokio should not be used for CPU bound tasks #4104

Closed
alamb opened this issue Sep 13, 2021 · 1 comment · Fixed by #4105
Closed

Documentation misleading suggests tokio should not be used for CPU bound tasks #4104

alamb opened this issue Sep 13, 2021 · 1 comment · Fixed by #4105
Labels
A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime T-docs Topic: documentation

Comments

@alamb
Copy link
Contributor

alamb commented Sep 13, 2021

Is your feature request related to a problem? Please describe.
First of all, Tokio is awesome and very flexible -- we have used it extensively in InfluxDB IOx, Apache Arrow DataFusion and elsewhere and it works great. Thank you very much ❤️

In DataFusion, InfluxDB IOx and other applications, there is a mix of CPU bound and I/O work and we use thread pools to manage the execution of those tasks.

I realize the design goals and optimization point for tokio is a large number of IO tasks, but its core threading model and support for the async / Future machinery of the Rust language and ecosystem makes it a very compelling thread (task) pool implementation as well. We have used tokio effectively for both types of work and found significant value of doing so.

However, on many occasions over the last few years, the following note from https://docs.rs/tokio/1.11.0/tokio/#cpu-bound-tasks-and-blocking-code

If your code is CPU-bound and you wish to limit the number of threads used to run it, you should run it on another thread pool such as rayon

Has geenrated significant discussion and confusion as it implies to some that the tokio Runtime should never be used for CPU bound tasks.

I believe the intent of this section is to warn people against using the same thread pool (Runtime) for I/O and CPU bound work, which is definitely sage advice to avoid significant and potentially unbounded latencies responding to IO. However I don't think there is anything specific to tokio that prevents it being used for CPU bound work.

Describe the solution you'd like
Make it clear in the documentation that the situation to avoid is using the same tokio threadpool, and point readers to the apis to create their own thread pools.

Additional context

I think this advice may be from an earlier time when it wasn't possible (or easy?) to create a separate tokio Runtime, for CPU bound tasks (which indeed serves as a "dedicated thread pool"). We have created a wrapper to do this for us in IOx DedicatedExecutor and it has worked well for us in practice.

Examples of confusion / questions:

@alamb alamb added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Sep 13, 2021
@Darksonn Darksonn added M-runtime Module: tokio/runtime T-docs Topic: documentation and removed C-feature-request Category: A feature request. labels Sep 13, 2021
@zuston
Copy link

zuston commented Sep 28, 2023

This is really helpful for me! Thanks for you share @alamb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime T-docs Topic: documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants