Skip to content

Commit

Permalink
Display the current download rate rather than the average when syncin…
Browse files Browse the repository at this point in the history
…g the chain (#2633)

* When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process.

* Replace the explicitly ignored variables in the pattern with an implicit ignore
  • Loading branch information
Agreene authored and ignopeverell committed Mar 3, 2019
1 parent d0ade29 commit 4c9984c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
9 changes: 8 additions & 1 deletion servers/src/common/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,17 @@ impl p2p::ChainAdapter for NetToChainAdapter {
total_size: u64,
) -> bool {
match self.sync_state.status() {
SyncStatus::TxHashsetDownload { .. } => {
SyncStatus::TxHashsetDownload {
update_time: old_update_time,
downloaded_size: old_downloaded_size,
..
} => {
self.sync_state
.update_txhashset_download(SyncStatus::TxHashsetDownload {
start_time,
prev_update_time: old_update_time,
update_time: Utc::now(),
prev_downloaded_size: old_downloaded_size,
downloaded_size,
total_size,
})
Expand Down
3 changes: 3 additions & 0 deletions servers/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ pub enum SyncStatus {
/// Downloading the various txhashsets
TxHashsetDownload {
start_time: DateTime<Utc>,
prev_update_time: DateTime<Utc>,
update_time: DateTime<Utc>,
prev_downloaded_size: u64,
downloaded_size: u64,
total_size: u64,
},
Expand Down
3 changes: 3 additions & 0 deletions servers/src/grin/sync/state_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ impl StateSync {

self.sync_state.update(SyncStatus::TxHashsetDownload {
start_time: Utc::now(),
prev_update_time: Utc::now(),
update_time: Utc::now(),
prev_downloaded_size: 0,
downloaded_size: 0,
total_size: 0,
});
Expand Down
7 changes: 5 additions & 2 deletions src/bin/tui/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ impl TUIStatusListener for TUIStatusView {
}
SyncStatus::TxHashsetDownload {
start_time,
prev_update_time,
update_time: _,
prev_downloaded_size,
downloaded_size,
total_size,
} => {
Expand All @@ -137,14 +140,14 @@ impl TUIStatusListener for TUIStatusView {
} else {
0
};
let start = start_time.timestamp_nanos();
let start = prev_update_time.timestamp_nanos();
let fin = Utc::now().timestamp_nanos();
let dur_ms = (fin - start) as f64 * NANO_TO_MILLIS;

format!("Downloading {}(MB) chain state for state sync: {}% at {:.1?}(kB/s), step 2/4",
total_size / 1_000_000,
percent,
if dur_ms > 1.0f64 { downloaded_size as f64 / dur_ms as f64 } else { 0f64 },
if dur_ms > 1.0f64 { (downloaded_size - prev_downloaded_size) as f64 / dur_ms as f64 } else { 0f64 },
)
} else {
let start = start_time.timestamp_millis();
Expand Down

1 comment on commit 4c9984c

@da2ce7
Copy link

@da2ce7 da2ce7 commented on 4c9984c Mar 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.