Let's adapt our overwhelmed TCP server to use a fixed number of threads. We'll start a new project whose Cargo.toml looks like:
[package] name = "fixed_threads_server" version = "0.1.0" authors = ["Brian L. Troutwine <brian@troutwine.us>"] [dependencies] clap = "2.31" slog = "2.2" slog-term = "2.4" slog-async = "2.3" threadpool = "1.7" [[bin]] name = "server" [[bin]] name = "client"
This is almost exactly the same as the unbounded thread project, save that the name has been changed from overwhelmed_tpc_server to fixed_threads_tcp_server and we've added a new dependency–threadpool. There are a few different, stable thread-pool libraries available in crates, each with a slightly different feature set or focus. The workerpool ...