Working with workers
When it comes to defining workers, we can augment the Tokio runtime macro with the following code:
#[tokio::main(flavor = "multi_thread", worker_threads = 4)] async fn main() { ... }
Here, we can see that we state that the runtime is multithreaded, and we have four worker threads. Workers are essentially processes that run in constant loops. Each worker consumes tasks through a channel, putting them in a queue. The worker then works through the tasks, executing them in the order received. If a worker has finished all the tasks, it will search other queues belonging to other workers, stealing tasks if they are available, as seen here:
Figure 14.1 – Worker event loops (Work stealing runtime. By Carl Lerche – License MIT: https://tokio.rs/blog/2019-10-scheduler#the-next-generation-tokio-scheduler)
Now that we know we can alter the number of workers, we can test how the number of worker...