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

Replace num_cpus with std::thread::available_parallelism. #912

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ futures = "0.3.4"
hyper = { version = "0.14", features = [ "server", "stream" ] }
listenfd = "1"
log = "0.4.8"
num_cpus = "1.12.0"
pin-project-lite = "0.2.4"
rand = "0.8.1"
reqwest = { version = "0.11.0", default-features = false, features = ["blocking", "rustls-tls" ] }
Expand Down
25 changes: 20 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::io::Read;
use std::net::{IpAddr, SocketAddr};
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::thread::available_parallelism;
use std::time::Duration;
use clap::{
Command, Args, ArgAction, ArgMatches, FromArgMatches, Parser,
Expand Down Expand Up @@ -955,8 +956,11 @@ impl Config {

dirty_repository: file.take_bool("dirty")?.unwrap_or(false),
validation_threads: {
file.take_small_usize("validation-threads")?
.unwrap_or_else(::num_cpus::get)
file.take_small_usize(
"validation-threads"
)?.unwrap_or_else(|| {
Config::default_validation_threads()
})
},
refresh: {
Duration::from_secs(
Expand Down Expand Up @@ -1155,7 +1159,7 @@ impl Config {
enable_bgpsec: false,
enable_aspa: false,
dirty_repository: DEFAULT_DIRTY_REPOSITORY,
validation_threads: ::num_cpus::get(),
validation_threads: Config::default_validation_threads(),
refresh: Duration::from_secs(DEFAULT_REFRESH),
retry: Duration::from_secs(DEFAULT_RETRY),
expire: Duration::from_secs(DEFAULT_EXPIRE),
Expand All @@ -1182,6 +1186,11 @@ impl Config {
}
}

/// Returns the default value for validation threads.
fn default_validation_threads() -> usize {
available_parallelism().map(|x| x.get()).unwrap_or(1)
}

/// Alters paths so that they are relative to a possible chroot.
pub fn adjust_chroot_paths(&mut self) -> Result<(), Failed> {
if let Some(ref chroot) = self.chroot {
Expand Down Expand Up @@ -2590,7 +2599,10 @@ mod test {
assert!(config.extra_tals_dir.is_none());
assert!(config.exceptions.is_empty());
assert_eq!(config.strict, DEFAULT_STRICT);
assert_eq!(config.validation_threads, ::num_cpus::get());
assert_eq!(
config.validation_threads,
Config::default_validation_threads(),
);
assert_eq!(config.refresh, Duration::from_secs(DEFAULT_REFRESH));
assert_eq!(config.retry, Duration::from_secs(DEFAULT_RETRY));
assert_eq!(config.expire, Duration::from_secs(DEFAULT_EXPIRE));
Expand Down Expand Up @@ -2673,7 +2685,10 @@ mod test {
);
assert!(config.exceptions.is_empty());
assert!(!config.strict);
assert_eq!(config.validation_threads, ::num_cpus::get());
assert_eq!(
config.validation_threads,
Config::default_validation_threads()
);
assert_eq!(config.refresh, Duration::from_secs(DEFAULT_REFRESH));
assert_eq!(config.retry, Duration::from_secs(DEFAULT_RETRY));
assert_eq!(config.expire, Duration::from_secs(DEFAULT_EXPIRE));
Expand Down
Loading