Browse Source

manager: calculate SpeedMeter window size from slice size

Peter Cai 1 year ago
parent
commit
ab88b0b8c3
Signed by: Peter Cai <[email protected]> GPG Key ID: 71F5FB4E4F3FD54F
1 changed files with 2 additions and 1 deletions
  1. 2
    1
      src/manager.rs

+ 2
- 1
src/manager.rs View File

@@ -43,6 +43,7 @@ impl<T> From<T> for DownloadManagerError where T: Into<Error> {
43 43
 }
44 44
 
45 45
 const TIME_SLICE_MS: u64 = 50;
46
+const PROGRESS_AVERAGE_WINDOW: u64 = 3000;
46 47
 
47 48
 #[derive(Debug)]
48 49
 pub struct DownloadManager {
@@ -134,7 +135,7 @@ impl DownloadManager {
134 135
             file_name,
135 136
             block_count,
136 137
             block_size,
137
-            meter: SpeedMeter::new(Duration::from_millis(TIME_SLICE_MS), 10),
138
+            meter: SpeedMeter::new(Duration::from_millis(TIME_SLICE_MS), (PROGRESS_AVERAGE_WINDOW / TIME_SLICE_MS) as usize),
138 139
             downloaded_len: 0,
139 140
             download_delta: Arc::new(AtomicU64::new(0)),
140 141
             blocks_state: vec![BlockState::Pending; block_count],

Loading…
Cancel
Save