Skip to content

Commit 3a3d654

Browse files
committed
use "physical" cpu cores as default worker count
1 parent ba901c7 commit 3a3d654

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

actix-server/examples/tcp-echo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ async fn run() -> io::Result<()> {
3333
let addr = ("127.0.0.1", 8080);
3434
info!("starting server on port: {}", &addr.0);
3535

36-
// Bind socket address and start worker(s). By default, the server uses the number of available
37-
// logical CPU cores as the worker count. For this reason, the closure passed to bind needs
38-
// to return a service *factory*; so it can be created once per worker.
36+
// Bind socket address and start worker(s). By default, the server uses the number of physical
37+
// CPU cores as the worker count. For this reason, the closure passed to bind needs to return
38+
// a service *factory*; so it can be created once per worker.
3939
Server::build()
4040
.bind("echo", addr, move || {
4141
let count = Arc::clone(&count);

actix-server/src/builder.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl ServerBuilder {
4040
let (cmd_tx, cmd_rx) = unbounded_channel();
4141

4242
ServerBuilder {
43-
threads: num_cpus::get(),
43+
threads: num_cpus::get_physical(),
4444
token: 0,
4545
factories: Vec::new(),
4646
sockets: Vec::new(),
@@ -55,8 +55,11 @@ impl ServerBuilder {
5555

5656
/// Set number of workers to start.
5757
///
58-
/// By default server uses number of available logical CPU as workers count. Workers must be
59-
/// greater than 0.
58+
/// `num` must be greater than 0.
59+
///
60+
/// The default worker count is the number of physical CPU cores available. If your benchmark
61+
/// testing indicates that simultaneous multi-threading is beneficial to your app, you can use
62+
/// the [`num_cpus`] crate to acquire the _logical_ core count instead.
6063
pub fn workers(mut self, num: usize) -> Self {
6164
assert_ne!(num, 0, "workers must be greater than 0");
6265
self.threads = num;

actix-server/src/worker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pub(crate) struct ServerWorkerConfig {
250250
impl Default for ServerWorkerConfig {
251251
fn default() -> Self {
252252
// 512 is the default max blocking thread count of tokio runtime.
253-
let max_blocking_threads = std::cmp::max(512 / num_cpus::get(), 1);
253+
let max_blocking_threads = std::cmp::max(512 / num_cpus::get_physical(), 1);
254254
Self {
255255
shutdown_timeout: Duration::from_secs(30),
256256
max_blocking_threads,

0 commit comments

Comments
 (0)