diff --git a/actix-server/examples/tcp-echo.rs b/actix-server/examples/tcp-echo.rs index 52ae5349..548a3591 100644 --- a/actix-server/examples/tcp-echo.rs +++ b/actix-server/examples/tcp-echo.rs @@ -33,9 +33,9 @@ async fn run() -> io::Result<()> { let addr = ("127.0.0.1", 8080); info!("starting server on port: {}", &addr.0); - // Bind socket address and start worker(s). By default, the server uses the number of available - // logical CPU cores as the worker count. For this reason, the closure passed to bind needs - // to return a service *factory*; so it can be created once per worker. + // Bind socket address and start worker(s). By default, the server uses the number of physical + // CPU cores as the worker count. For this reason, the closure passed to bind needs to return + // a service *factory*; so it can be created once per worker. Server::build() .bind("echo", addr, move || { let count = Arc::clone(&count); diff --git a/actix-server/src/builder.rs b/actix-server/src/builder.rs index a63e5652..d2aa08e1 100644 --- a/actix-server/src/builder.rs +++ b/actix-server/src/builder.rs @@ -40,7 +40,7 @@ impl ServerBuilder { let (cmd_tx, cmd_rx) = unbounded_channel(); ServerBuilder { - threads: num_cpus::get(), + threads: num_cpus::get_physical(), token: 0, factories: Vec::new(), sockets: Vec::new(), @@ -55,8 +55,11 @@ impl ServerBuilder { /// Set number of workers to start. /// - /// By default server uses number of available logical CPU as workers count. Workers must be - /// greater than 0. + /// `num` must be greater than 0. + /// + /// The default worker count is the number of physical CPU cores available. If your benchmark + /// testing indicates that simultaneous multi-threading is beneficial to your app, you can use + /// the [`num_cpus`] crate to acquire the _logical_ core count instead. pub fn workers(mut self, num: usize) -> Self { assert_ne!(num, 0, "workers must be greater than 0"); self.threads = num; diff --git a/actix-server/src/worker.rs b/actix-server/src/worker.rs index 0822ab7c..2fef9a7b 100644 --- a/actix-server/src/worker.rs +++ b/actix-server/src/worker.rs @@ -250,7 +250,7 @@ pub(crate) struct ServerWorkerConfig { impl Default for ServerWorkerConfig { fn default() -> Self { // 512 is the default max blocking thread count of tokio runtime. - let max_blocking_threads = std::cmp::max(512 / num_cpus::get(), 1); + let max_blocking_threads = std::cmp::max(512 / num_cpus::get_physical(), 1); Self { shutdown_timeout: Duration::from_secs(30), max_blocking_threads,