tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
27.18k stars 2.49k forks source link

Allow runtime scaling of the number of workers #6341

Open Noah-Kennedy opened 9 months ago

Noah-Kennedy commented 9 months ago

Sometimes, it can be useful to be able to scale the amount of workers up or down.

For example, at Cloudflare we generally do graceful restarts by running both the old and new versions of a service at the same time and handing off the listener socket to the new version of the service, allowing the old one to keep running and serving traffic while the new one takes over. In cases like this, scaling down the number of workers on the old version of the service to limit it's resource usage can be a useful thing to do.

For this reason, I'm proposing allowing users to dynamically scale the number of worker threads they use at runtime up or down.

Noah-Kennedy commented 9 months ago

I think the first step here is to establish whether or not this is actually feasible - it may well not be.

wathenjiang commented 5 months ago

An idea for a smaller change is: Is it possible to add a method to create a thread specifically that is only responsible for polling the driver and not for executing tasks?