Skip to content

Commit 2880f30

Browse files
faernrbtcollins
authored andcommitted
Use ImmediateUnpacker if system reports <=1 CPU count
1 parent 003aa58 commit 2880f30

File tree

6 files changed

+17
-40
lines changed

6 files changed

+17
-40
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ git-testament = "0.1.4"
3131
home = "0.5"
3232
lazy_static = "1"
3333
libc = "0.2"
34+
num_cpus = "1.13"
3435
opener = "0.4.0"
3536
# Used by `curl` or `reqwest` backend although it isn't imported
3637
# by our rustup.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ currently can define only `default_toolchain`.
697697
Sets the root URL for downloading self-updates.
698698

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

src/diskio/mod.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use std::io::{self, Write};
5959
use std::path::{Path, PathBuf};
6060
use std::time::{Duration, Instant};
6161

62+
use crate::errors::{Result, ResultExt};
6263
use crate::process;
6364
use crate::utils::notifications::Notification;
6465

@@ -194,20 +195,16 @@ pub fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
194195
/// Get the executor for disk IO.
195196
pub fn get_executor<'a>(
196197
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
197-
) -> Box<dyn Executor + 'a> {
198+
) -> Result<Box<dyn Executor + 'a>> {
198199
// If this gets lots of use, consider exposing via the config file.
199-
if let Ok(thread_str) = process().var("RUSTUP_IO_THREADS") {
200-
if thread_str == "disabled" {
201-
Box::new(immediate::ImmediateUnpacker::new())
202-
} else if let Ok(thread_count) = thread_str.parse::<usize>() {
203-
Box::new(threaded::Threaded::new_with_threads(
204-
notify_handler,
205-
thread_count,
206-
))
207-
} else {
208-
Box::new(threaded::Threaded::new(notify_handler))
209-
}
210-
} else {
211-
Box::new(threaded::Threaded::new(notify_handler))
212-
}
200+
let thread_count = match process().var("RUSTUP_IO_THREADS") {
201+
Err(_) => num_cpus::get(),
202+
Ok(n) => n
203+
.parse::<usize>()
204+
.chain_err(|| "invalid value in RUSTUP_IO_THREADS. Must be a natural number")?,
205+
};
206+
Ok(match thread_count {
207+
0 | 1 => Box::new(immediate::ImmediateUnpacker::new()),
208+
n => Box::new(threaded::Threaded::new(notify_handler, n)),
209+
})
213210
}

src/diskio/threaded.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,7 @@ pub struct Threaded<'a> {
3434
}
3535

3636
impl<'a> Threaded<'a> {
37-
pub fn new(notify_handler: Option<&'a dyn Fn(Notification<'_>)>) -> Self {
38-
// Defaults to hardware thread count threads; this is suitable for
39-
// our needs as IO bound operations tend to show up as write latencies
40-
// rather than close latencies, so we don't need to look at
41-
// more threads to get more IO dispatched at this stage in the process.
42-
let pool = threadpool::Builder::new()
43-
.thread_name("CloseHandle".into())
44-
.thread_stack_size(1_048_576)
45-
.build();
46-
let (tx, rx) = channel();
47-
Self {
48-
n_files: Arc::new(AtomicUsize::new(0)),
49-
pool,
50-
notify_handler,
51-
rx,
52-
tx,
53-
}
54-
}
55-
56-
pub fn new_with_threads(
57-
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
58-
thread_count: usize,
59-
) -> Self {
37+
pub fn new(notify_handler: Option<&'a dyn Fn(Notification<'_>)>, thread_count: usize) -> Self {
6038
// Defaults to hardware thread count threads; this is suitable for
6139
// our needs as IO bound operations tend to show up as write latencies
6240
// rather than close latencies, so we don't need to look at

src/dist/component/package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ fn unpack_without_first_dir<'a, R: Read>(
293293
path: &Path,
294294
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
295295
) -> Result<()> {
296-
let mut io_executor: Box<dyn Executor> = get_executor(notify_handler);
296+
let mut io_executor: Box<dyn Executor> = get_executor(notify_handler)?;
297297
let entries = archive
298298
.entries()
299299
.chain_err(|| ErrorKind::ExtractingPackage)?;

0 commit comments

Comments
 (0)