Skip to content

Commit

Permalink
Use ImmediateUnpacker if system reports <=1 CPU count
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Jun 11, 2020
1 parent 003aa58 commit 9790256
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 40 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ git-testament = "0.1.4"
home = "0.5"
lazy_static = "1"
libc = "0.2"
num_cpus = "1.13"
opener = "0.4.0"
# Used by `curl` or `reqwest` backend although it isn't imported
# by our rustup.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ currently can define only `default_toolchain`.
Sets the root URL for downloading self-updates.

- `RUSTUP_IO_THREADS` *unstable* (defaults to reported cpu count). Sets the
number of threads to perform close IO in. Set to `disabled` to force
number of threads to perform close IO in. Set to `1` to force
single-threaded IO for troubleshooting, or an arbitrary number to
override automatic detection.

Expand Down
27 changes: 12 additions & 15 deletions src/diskio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::time::{Duration, Instant};

use crate::errors::{Result, ResultExt};
use crate::process;
use crate::utils::notifications::Notification;

Expand Down Expand Up @@ -194,20 +195,16 @@ pub fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
/// Get the executor for disk IO.
pub fn get_executor<'a>(
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
) -> Box<dyn Executor + 'a> {
) -> Result<Box<dyn Executor + 'a>> {
// If this gets lots of use, consider exposing via the config file.
if let Ok(thread_str) = process().var("RUSTUP_IO_THREADS") {
if thread_str == "disabled" {
Box::new(immediate::ImmediateUnpacker::new())
} else if let Ok(thread_count) = thread_str.parse::<usize>() {
Box::new(threaded::Threaded::new_with_threads(
notify_handler,
thread_count,
))
} else {
Box::new(threaded::Threaded::new(notify_handler))
}
} else {
Box::new(threaded::Threaded::new(notify_handler))
}
let thread_count = match process().var("RUSTUP_IO_THREADS") {
Err(_) => num_cpus::get(),
Ok(n) => n
.parse::<usize>()
.chain_err(|| "invalid value in RUSTUP_IO_THREADS. Must be a natural number")?,
};
Ok(match thread_count {
0 | 1 => Box::new(immediate::ImmediateUnpacker::new()),
n => Box::new(threaded::Threaded::new(notify_handler, n)),
})
}
24 changes: 1 addition & 23 deletions src/diskio/threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,7 @@ pub struct Threaded<'a> {
}

impl<'a> Threaded<'a> {
pub fn new(notify_handler: Option<&'a dyn Fn(Notification<'_>)>) -> Self {
// Defaults to hardware thread count threads; this is suitable for
// our needs as IO bound operations tend to show up as write latencies
// rather than close latencies, so we don't need to look at
// more threads to get more IO dispatched at this stage in the process.
let pool = threadpool::Builder::new()
.thread_name("CloseHandle".into())
.thread_stack_size(1_048_576)
.build();
let (tx, rx) = channel();
Self {
n_files: Arc::new(AtomicUsize::new(0)),
pool,
notify_handler,
rx,
tx,
}
}

pub fn new_with_threads(
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
thread_count: usize,
) -> Self {
pub fn new(notify_handler: Option<&'a dyn Fn(Notification<'_>)>, thread_count: usize) -> Self {
// Defaults to hardware thread count threads; this is suitable for
// our needs as IO bound operations tend to show up as write latencies
// rather than close latencies, so we don't need to look at
Expand Down
2 changes: 1 addition & 1 deletion src/dist/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ fn unpack_without_first_dir<'a, R: Read>(
path: &Path,
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
) -> Result<()> {
let mut io_executor: Box<dyn Executor> = get_executor(notify_handler);
let mut io_executor: Box<dyn Executor> = get_executor(notify_handler)?;
let entries = archive
.entries()
.chain_err(|| ErrorKind::ExtractingPackage)?;
Expand Down

0 comments on commit 9790256

Please sign in to comment.