diff options
Diffstat (limited to 'src/swarm/sync.rs')
| -rw-r--r-- | src/swarm/sync.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs index adf8146..09e10f4 100644 --- a/src/swarm/sync.rs +++ b/src/swarm/sync.rs @@ -307,6 +307,8 @@ pub(crate) async fn handle_sync( let peer_state_mutex = Arc::clone(&peer_state_mutex); let stats = Arc::clone(&state.stats); let check_caught_up = !state.initial_sync_done.load(Ordering::Acquire); + // While catching up, everything arrives late; that says nothing about propagation. + let measure_propagation = !check_caught_up; let epoch = envelope.epoch; let message = envelope.message; let peer = peer.to_owned(); @@ -338,6 +340,19 @@ pub(crate) async fn handle_sync( let heads_after = replica.doc.get_heads(); stats.heads_seen(heads_after.len()); let changed = heads_after != heads_before; + if changed && measure_propagation { + let now_ms = crate::state::unix_millis() as i64; + // Time 0: not stamped (snapshots, older nodes). + let delays: Vec<i64> = replica + .doc + .get_changes(&heads_before) + .iter() + .map(|change| change.timestamp()) + .filter(|&time| time > 0) + .map(|time| now_ms - time) + .collect(); + stats.propagated(delays); + } Ok(Some(( // Only from a ready peer: a peer still catching up has empty heads, which |
