Skip to content

Commit

Permalink
feat: add printing progress and ETA for uploader canister (#338)
Browse files Browse the repository at this point in the history
This PR adds printing progress status and ETA information for uploader
canister.

Uploading big canister states can take a lot of time and printing such
information is a nice improvement.
```shell
...
Uploading chunk 455/51307 (0.9%), index 38161, ETA: 25h 27m 16s
...
```
  • Loading branch information
maksymar authored Nov 15, 2024
1 parent 5e7ee44 commit 07d4d9c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions bootstrap/uploader/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ async fn main() {
} else {
missing_chunk_indices.into_iter().collect()
};
for chunk_index in chunk_indices {

let total_chunks = chunk_indices.len();
let start_time = std::time::Instant::now();

for (i, &chunk_index) in chunk_indices.iter().enumerate() {
let offset = chunk_index * PAGE_SIZE_IN_BYTES;
let mut buf = vec![0; CHUNK_SIZE_IN_BYTES as usize];
reader
Expand All @@ -106,7 +110,21 @@ async fn main() {
break;
}

println!("Uploading chunk at {}", chunk_index);
let percentage = (i as f64 / total_chunks as f64) * 100.0;
let elapsed_secs = start_time.elapsed().as_secs_f64();
let estimated_time_left = if percentage > 0.0 {
(100.0 - percentage) * elapsed_secs / percentage
} else {
0.0
};
let hours = (estimated_time_left / 3600.0).floor() as u64;
let minutes = ((estimated_time_left % 3600.0) / 60.0).floor() as u64;
let seconds = (estimated_time_left % 60.0).floor() as u64;
let current_chunk = i + 1;
println!(
"Uploading chunk {current_chunk}/{total_chunks} ({percentage:.1}%), index {chunk_index}, ETA: {hours}h {minutes:02}m {seconds:02}s",
);

upload(&agent, &args.canister_id, chunk_index, &buf[..bytes_read]).await;
}
}

0 comments on commit 07d4d9c

Please sign in to comment.