Skip to content

Commit

Permalink
Removing dependency to num_cpus (as the info is available in the std
Browse files Browse the repository at this point in the history
nowadays).
  • Loading branch information
fulmicoton committed May 7, 2024
1 parent f62e425 commit 22f2a09
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 14 deletions.
3 changes: 0 additions & 3 deletions quickwit/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion quickwit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ mockall = "0.11"
mrecordlog = { git = "https://github.com/quickwit-oss/mrecordlog", rev = "306c0a7" }
new_string_template = "1.5.1"
nom = "7.1.3"
num_cpus = "1"
numfmt = "1.1.1"
once_cell = "1"
oneshot = "0.1.5"
Expand Down
1 change: 0 additions & 1 deletion quickwit/quickwit-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ hostname = { workspace = true }
http = { workspace = true }
hyper = { workspace = true }
itertools = { workspace = true }
num_cpus = { workspace = true }
once_cell = { workspace = true }
pin-project = { workspace = true }
pnet = { workspace = true }
Expand Down
4 changes: 4 additions & 0 deletions quickwit/quickwit-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ pub const fn div_ceil(lhs: i64, rhs: i64) -> i64 {
}
}

pub fn num_cpus() -> usize {
std::thread::available_parallelism().unwrap().get()
}

// The following are helpers to build named tasks.
//
// Named tasks require the tokio feature `tracing` to be enabled.
Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-common/src/runtimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl RuntimesConfig {

impl Default for RuntimesConfig {
fn default() -> Self {
let num_cpus = num_cpus::get();
let num_cpus = crate::num_cpus();
Self::with_num_cpus(num_cpus)
}
}
Expand Down
1 change: 0 additions & 1 deletion quickwit/quickwit-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ humantime = { workspace = true }
itertools = { workspace = true }
json_comments = { workspace = true }
new_string_template = { workspace = true }
num_cpus = { workspace = true }
once_cell = { workspace = true }
regex = { workspace = true }
serde = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions quickwit/quickwit-config/src/node_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ impl IndexerConfig {
}

pub fn default_merge_concurrency() -> NonZeroUsize {
NonZeroUsize::new(num_cpus::get() * 2 / 3).unwrap_or(NonZeroUsize::new(1).unwrap())
NonZeroUsize::new(quickwit_common::num_cpus() * 2 / 3).unwrap_or(NonZeroUsize::new(1).unwrap())
}

fn default_cpu_capacity() -> CpuCapacity {
CpuCapacity::one_cpu_thread() * (num_cpus::get() as u32)
CpuCapacity::one_cpu_thread() * (quickwit_common::num_cpus() as u32)
}

#[cfg(any(test, feature = "testsuite"))]
Expand Down
1 change: 0 additions & 1 deletion quickwit/quickwit-serve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ humantime = { workspace = true }
hyper = { workspace = true }
itertools = { workspace = true }
mime_guess = { workspace = true }
num_cpus = { workspace = true }
once_cell = { workspace = true }
opentelemetry = { workspace = true }
percent-encoding = { workspace = true }
Expand Down
5 changes: 1 addition & 4 deletions quickwit/quickwit-serve/src/build_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ impl BuildInfo {
#[derive(Debug, Eq, PartialEq, Serialize, utoipa::ToSchema)]
pub struct RuntimeInfo {
pub num_cpus_logical: usize,
pub num_cpus_physical: usize,
pub num_threads_blocking: usize,
pub num_threads_non_blocking: usize,
}
Expand All @@ -108,12 +107,10 @@ impl RuntimeInfo {
static INSTANCE: OnceCell<RuntimeInfo> = OnceCell::new();

INSTANCE.get_or_init(|| {
let num_cpus_logical = num_cpus::get();
let num_cpus_logical = quickwit_common::num_cpus();
let runtimes_config = RuntimesConfig::with_num_cpus(num_cpus_logical);

Self {
num_cpus_logical,
num_cpus_physical: num_cpus::get_physical(),
num_threads_blocking: runtimes_config.num_threads_blocking,
num_threads_non_blocking: runtimes_config.num_threads_non_blocking,
}
Expand Down

0 comments on commit 22f2a09

Please sign in to comment.