Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing dependency to num_cpus (as the info is available in the std #4947

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 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,12 @@ 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
13 changes: 6 additions & 7 deletions quickwit/quickwit-serve/src/build_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ impl BuildInfo {

#[derive(Debug, Eq, PartialEq, Serialize, utoipa::ToSchema)]
pub struct RuntimeInfo {
pub num_cpus_logical: usize,
pub num_cpus_physical: usize,
// This is a number of logical cpus: vCPU or hyperthread depending on where you are running.
// This is usually NOT necessarily the number of cores.
pub num_cpus: usize,
pub num_threads_blocking: usize,
pub num_threads_non_blocking: usize,
}
Expand All @@ -108,12 +109,10 @@ impl RuntimeInfo {
static INSTANCE: OnceCell<RuntimeInfo> = OnceCell::new();

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

let num_cpus = quickwit_common::num_cpus();
let runtimes_config = RuntimesConfig::with_num_cpus(num_cpus);
Self {
num_cpus_logical,
num_cpus_physical: num_cpus::get_physical(),
num_cpus,
num_threads_blocking: runtimes_config.num_threads_blocking,
num_threads_non_blocking: runtimes_config.num_threads_non_blocking,
}
Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-serve/src/node_info_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mod tests {

let runtime_info_json = info_json.get("runtime").unwrap();
let expected_runtime_info_json = serde_json::json!({
"num_cpus_physical": runtime_info.num_cpus_physical,
"num_cpus": runtime_info.num_cpus,
});
assert_json_include!(
actual: runtime_info_json,
Expand Down
Loading