Skip to content

Commit d5c884e

Browse files
feat(downloads): introduce RUSTUP_CONCURRENT_DOWNLOADS to control concurrency
1 parent 3d99833 commit d5c884e

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

doc/user-guide/src/environment-variables.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
- `RUSTUP_DOWNLOAD_TIMEOUT` *unstable* (default: 180). Allows to override the default
7070
timeout (in seconds) for downloading components.
7171

72+
- `RUSTUP_CONCURRENT_DOWNLOADS` *unstable* (default: the number of components to download). Controls the number of
73+
downloads made concurrently.
74+
7275
[directive syntax]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives
7376
[dc]: https://docs.docker.com/storage/storagedriver/overlayfs-driver/#modifying-files-or-directories
7477
[override]: overrides.md

src/cli/rustup_mode.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{
33
env::consts::EXE_SUFFIX,
44
fmt,
55
io::{self, Write},
6+
num::NonZeroU64,
67
path::{Path, PathBuf},
78
process::ExitStatus,
89
str::FromStr,
@@ -799,7 +800,13 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<utils::ExitCode
799800
let use_colors = matches!(t.color_choice(), ColorChoice::Auto | ColorChoice::Always);
800801
let mut update_available = false;
801802
let channels = cfg.list_channels()?;
802-
let num_channels = channels.len();
803+
let num_channels = match cfg.process.var("RUSTUP_CONCURRENT_DOWNLOADS") {
804+
Ok(s) => NonZeroU64::from_str(&s).context(
805+
"invalid value in RUSTUP_CONCURRENT_DOWNLOADS -- must be a natural number greater than zero"
806+
)?.get() as usize,
807+
Err(_) => channels.len(),
808+
};
809+
803810
// Ensure that `.buffered()` is never called with 0 as this will cause a hang.
804811
// See: https://github.com/rust-lang/futures-rs/pull/1194#discussion_r209501774
805812
if num_channels > 0 {

src/dist/manifestation.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#[cfg(test)]
55
mod tests;
66

7+
use std::num::NonZeroU64;
78
use std::path::Path;
9+
use std::str::FromStr;
810

911
use anyhow::{Context, Result, anyhow, bail};
1012
use futures_util::stream::StreamExt;
@@ -154,7 +156,12 @@ impl Manifestation {
154156
let mut things_to_install: Vec<(Component, CompressionKind, File)> = Vec::new();
155157
let mut things_downloaded: Vec<String> = Vec::new();
156158
let components = update.components_urls_and_hashes(new_manifest)?;
157-
let components_len = components.len();
159+
let num_channels = match download_cfg.process.var("RUSTUP_CONCURRENT_DOWNLOADS") {
160+
Ok(s) => NonZeroU64::from_str(&s).context(
161+
"invalid value in RUSTUP_CONCURRENT_DOWNLOADS -- must be a natural number greater than zero"
162+
)?.get() as usize,
163+
Err(_) => components.len(),
164+
};
158165

159166
const DEFAULT_MAX_RETRIES: usize = 3;
160167
let max_retries: usize = download_cfg
@@ -188,9 +195,9 @@ impl Manifestation {
188195
new_manifest,
189196
)
190197
});
191-
if components_len > 0 {
198+
if num_channels > 0 {
192199
let results = component_stream
193-
.buffered(components_len)
200+
.buffered(num_channels)
194201
.collect::<Vec<_>>()
195202
.await;
196203
for result in results {

0 commit comments

Comments
 (0)