mirror of
https://github.com/fafhrd91/actix-net
synced 2025-06-28 15:40:36 +02:00
remove num_cpus dependency (#488)
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use std::{io, time::Duration};
|
||||
use std::{io, num::NonZeroUsize, time::Duration};
|
||||
|
||||
use actix_rt::net::TcpStream;
|
||||
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
|
||||
@ -55,7 +55,7 @@ impl ServerBuilder {
|
||||
let (cmd_tx, cmd_rx) = unbounded_channel();
|
||||
|
||||
ServerBuilder {
|
||||
threads: num_cpus::get_physical(),
|
||||
threads: std::thread::available_parallelism().map_or(2, NonZeroUsize::get),
|
||||
token: 0,
|
||||
factories: Vec::new(),
|
||||
sockets: Vec::new(),
|
||||
@ -76,6 +76,12 @@ impl ServerBuilder {
|
||||
/// 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.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `num` is 0.
|
||||
///
|
||||
/// [`num_cpus`]: https://docs.rs/num_cpus
|
||||
pub fn workers(mut self, num: usize) -> Self {
|
||||
assert_ne!(num, 0, "workers must be greater than 0");
|
||||
self.threads = num;
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std::{
|
||||
future::Future,
|
||||
io, mem,
|
||||
num::NonZeroUsize,
|
||||
pin::Pin,
|
||||
rc::Rc,
|
||||
sync::{
|
||||
@ -249,8 +250,11 @@ 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_physical(), 1);
|
||||
let parallelism = std::thread::available_parallelism().map_or(2, NonZeroUsize::get);
|
||||
|
||||
// 512 is the default max blocking thread count of a Tokio runtime.
|
||||
let max_blocking_threads = std::cmp::max(512 / parallelism, 1);
|
||||
|
||||
Self {
|
||||
shutdown_timeout: Duration::from_secs(30),
|
||||
max_blocking_threads,
|
||||
|
Reference in New Issue
Block a user