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

Generate Tokio Runtime in ExecutionContext #928

Open
Dandandan opened this issue Aug 23, 2021 · 3 comments
Open

Generate Tokio Runtime in ExecutionContext #928

Dandandan opened this issue Aug 23, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@Dandandan
Copy link
Contributor

Dandandan commented Aug 23, 2021

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

Currently a Tokio runtime is created outside of the control of DataFusion, and requires another user to specify a #[tokio::main] or a custom runtime.

The downside of this is that the config is outside of the control of DataFusion and depends on it being configured externally.

Describe the solution you'd like
Create a custom Runtime when creating the execution context.
Here we can also configure the worker thread count and max threads for the blocking thread pool based on a config or on number of CPU cores.

Possibly, for some usecases it would be nice to allow plugging in a runtime (e.g. when you want to share the runtime).

Describe alternatives you've considered

Additional context
Related to #924

@Dandandan Dandandan added the enhancement New feature or request label Aug 23, 2021
@Dandandan
Copy link
Contributor Author

FYI @alamb as this also has impact on IOx

@alamb
Copy link
Contributor

alamb commented Aug 23, 2021

If we go this approach, care must be taken to ensure any newly created executor does not interfere with one created with [tokio::main]

Here is an example of such a dedicated tokio executor that we made in IOx: https://github.com/influxdata/influxdb_iox/blob/main/query/src/exec/task.rs#L48-L65

I would be willing to contribute the DedicatedExecutor code back upstream to DataFusion if there is interest -- and we could add a configuration setting for thread counts, etc. I think the DedicatedExecutorcan also be used to satisfy the usecase of "running DataFusion CPU-bound tasks on a different thread pool than IO bound tasks"

@alamb
Copy link
Contributor

alamb commented Oct 2, 2021

In case anyone is interested: https://docs.rs/tokio/1.12.0/tokio/#cpu-bound-tasks-and-blocking-code

Is upgraded to say that using a separate tokio executor is not a bad idea:

If your code is CPU-bound and you wish to limit the number of threads used to run it, you should use a separate thread pool dedicated to CPU bound tasks. For example, you could consider using the rayon library for CPU-bound tasks. It is also possible to create an extra Tokio runtime dedicated to CPU-bound tasks, but if you do this, you should be careful that the extra runtime runs only CPU-bound tasks, as IO-bound tasks on that runtime will behave poorly.

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

No branches or pull requests

2 participants