To use thread pools, you don't need a special library. Instead, you can implement a scheduler that sends requests to a bunch of threads. You can even check the responses of workers to decide which thread to choose for processing, but there are ready-to-use crates that help to solve this issue more elegantly. In this section, we're going to look at the futures-cpupool and tokio-threadpool crates.Â
Using thread pools
CpuPool
Here, we'll reuse an existing microservice and remove the start_worker function, and the WorkerRequest and WorkerResult types. Keep the convert function and add a new dependency to Cargo.toml:
futures-cpupool = "0.1"
Import the CpuPool type...