-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Change progress indicator for sparse registries #11068
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ use cargo_util::paths; | |
use curl::easy::{HttpVersion, List}; | ||
use curl::multi::{EasyHandle, Multi}; | ||
use log::{debug, trace}; | ||
use std::cell::{Cell, RefCell}; | ||
use std::cell::RefCell; | ||
use std::collections::{HashMap, HashSet}; | ||
use std::fs::{self, File}; | ||
use std::path::{Path, PathBuf}; | ||
|
@@ -98,6 +98,9 @@ pub struct Downloads<'cfg> { | |
progress: RefCell<Option<Progress<'cfg>>>, | ||
/// Number of downloads that have successfully finished. | ||
downloads_finished: usize, | ||
/// Number of times the caller has requested blocking. This is used for | ||
/// an estimate of progress. | ||
blocking_calls: usize, | ||
} | ||
|
||
struct Download { | ||
|
@@ -113,10 +116,6 @@ struct Download { | |
|
||
/// ETag or Last-Modified header received from the server (if any). | ||
index_version: RefCell<Option<String>>, | ||
|
||
/// Statistics updated from the progress callback in libcurl. | ||
total: Cell<u64>, | ||
current: Cell<u64>, | ||
} | ||
|
||
struct CompletedDownload { | ||
|
@@ -159,10 +158,11 @@ impl<'cfg> HttpRegistry<'cfg> { | |
results: HashMap::new(), | ||
progress: RefCell::new(Some(Progress::with_style( | ||
"Fetch", | ||
ProgressStyle::Ratio, | ||
ProgressStyle::Indeterminate, | ||
config, | ||
))), | ||
downloads_finished: 0, | ||
blocking_calls: 0, | ||
}, | ||
fresh: HashSet::new(), | ||
requested_update: false, | ||
|
@@ -457,15 +457,6 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> { | |
Ok(buf.len()) | ||
})?; | ||
|
||
// Same goes for the progress function -- it goes through thread-local storage. | ||
handle.progress(true)?; | ||
handle.progress_function(move |dl_total, dl_cur, _, _| { | ||
tls::with(|downloads| match downloads { | ||
Some(d) => d.progress(token, dl_total as u64, dl_cur as u64), | ||
None => false, | ||
}) | ||
})?; | ||
|
||
// And ditto for the header function. | ||
handle.header_function(move |buf| { | ||
if let Some((tag, value)) = Self::handle_http_header(buf) { | ||
|
@@ -494,8 +485,6 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> { | |
data: RefCell::new(Vec::new()), | ||
path: path.to_path_buf(), | ||
index_version: RefCell::new(None), | ||
total: Cell::new(0), | ||
current: Cell::new(0), | ||
}; | ||
|
||
// Finally add the request we've lined up to the pool of requests that cURL manages. | ||
|
@@ -588,11 +577,11 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> { | |
} | ||
|
||
fn block_until_ready(&mut self) -> CargoResult<()> { | ||
let initial_pending_count = self.downloads.pending.len(); | ||
trace!( | ||
"block_until_ready: {} transfers pending", | ||
initial_pending_count | ||
self.downloads.pending.len() | ||
); | ||
self.downloads.blocking_calls += 1; | ||
|
||
loop { | ||
self.handle_completed_downloads()?; | ||
|
@@ -622,21 +611,31 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> { | |
} | ||
|
||
impl<'cfg> Downloads<'cfg> { | ||
fn progress(&self, token: usize, total: u64, cur: u64) -> bool { | ||
let dl = &self.pending[&token].0; | ||
dl.total.set(total); | ||
dl.current.set(cur); | ||
true | ||
} | ||
|
||
fn tick(&self) -> CargoResult<()> { | ||
let mut progress = self.progress.borrow_mut(); | ||
let progress = progress.as_mut().unwrap(); | ||
|
||
// Since the sparse protocol discovers dependencies as it goes, | ||
// it's not possible to get an accurate progress indication. | ||
// | ||
// As an approximation, we assume that the depth of the dependency graph | ||
// is fixed, and base the progress on how many times the caller has asked | ||
// for blocking. If there are actually additional dependencies, the progress | ||
// bar will get stuck. If there are fewer dependencies, it will disappear | ||
// early. It will never go backwards. | ||
// | ||
// The status text also contains the number of completed & pending requests, which | ||
// gives an better indication of forward progress. | ||
let approximate_tree_depth = 10; | ||
|
||
progress.tick( | ||
self.downloads_finished, | ||
self.downloads_finished + self.pending.len(), | ||
"", | ||
self.blocking_calls.min(approximate_tree_depth), | ||
approximate_tree_depth + 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if the blocking_calls is larger than approximate_tree_depth? Maybe the denominator should be |
||
&format!( | ||
" {} complete; {} pending", | ||
self.downloads_finished, | ||
self.pending.len() | ||
), | ||
) | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.