Server: Use min instead of max to limit the number of threads (#17421)

## Summary

Prevent overcommit by using max 4 threads as intended.

Unintuitively, `.max()` returns the maximum value of `self` and the
argument (not limiting to the argument). To limit the value to 4, one
needs to use `.min()`.

https://doc.rust-lang.org/std/cmp/trait.Ord.html#method.max
This commit is contained in:
Nuri Jung 2025-04-18 05:02:12 +09:00 committed by GitHub
parent 9c47b6dbb0
commit 58807b2980
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View file

@ -30,7 +30,7 @@ pub fn run_server() -> anyhow::Result<()> {
// by default, we set the number of worker threads to `num_cpus`, with a maximum of 4.
let worker_threads = std::thread::available_parallelism()
.unwrap_or(four)
.max(four);
.min(four);
Server::new(worker_threads)
.context("Failed to start server")?

View file

@ -228,7 +228,7 @@ fn server(args: ServerCommand) -> Result<ExitStatus> {
// by default, we set the number of worker threads to `num_cpus`, with a maximum of 4.
let worker_threads = std::thread::available_parallelism()
.unwrap_or(four)
.max(four);
.min(four);
commands::server::run_server(worker_threads, args.resolve_preview())
}