1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-28 12:10:37 +02:00

use "physical" cpu cores as default worker count

This commit is contained in:
Rob Ede
2021-12-08 05:37:06 +00:00
parent ba901c70df
commit 3a3d654cea
3 changed files with 10 additions and 7 deletions

View File

@ -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;

View File

@ -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,