From 42d38d5d46f6d8850f97d5e90a82eb0ac7d3a2d1 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 24 Oct 2026 06:43:16 +0200 Subject: add throughput stats --- src/state.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/state.rs') diff --git a/src/state.rs b/src/state.rs index b8944ab..d8f0bbf 100644 --- a/src/state.rs +++ b/src/state.rs @@ -16,6 +16,7 @@ use crate::backoff::Backoff; use crate::document::replica::{Epoch, Replica}; use crate::remake::{Host, PeerSummary, RemakeState}; use crate::swarm::sync::{ChangeSet, SyncEvent}; +use crate::swarm::throughput::{SyncBytes, ThroughputTable}; use crate::transport; use crate::transport::firewall::Firewall; @@ -204,6 +205,9 @@ pub(crate) struct SyncSession { #[derive(Clone, Debug)] pub(crate) struct SyncReplyWait { pub(crate) deadline: Instant, + /// When the first of the unanswered messages was generated, and the sync bytes + /// exchanged with the peer by then (`swarm::throughput`). + pub(crate) started: (Instant, SyncBytes), /// Changes first sent in the unanswered messages. pub(crate) sent: Vec, } @@ -266,13 +270,20 @@ impl SyncSession { } /// A sync message went out; `sent` are the changes it carried for the first time. - pub(crate) fn expect_reply(&mut self, sent: Vec, now: Instant) { + /// `bytes` are the sync bytes exchanged with the peer before it. + pub(crate) fn expect_reply( + &mut self, + sent: Vec, + now: Instant, + bytes: SyncBytes, + ) { match &mut self.reply { // Still waiting for an earlier one: keep its deadline, remember these too. Some(wait) => wait.sent.extend(sent), None => { self.reply = Some(SyncReplyWait { deadline: now + self.reply_backoff.current(), + started: (now, bytes), sent, }); } @@ -586,6 +597,8 @@ pub(crate) struct AppState { pub(crate) stability: Arc>, /// Round-trip times to peers (`swarm::rtt`). pub(crate) rtt: Arc>, + /// Sync throughput with peers (`swarm::throughput`). + pub(crate) throughput: Arc>, /// The neighbour we are pulling changes from, and since when (`swarm::relay`). pub(crate) pulling: Arc>>, /// Our neighbours, once known (`swarm::topology`). -- cgit v1.3.1