From 9f9015a35b591043ebaf6e306f967ffc62cd07f5 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 5 Nov 2026 03:37:48 +0100 Subject: measure sync envelopes --- src/swarm/sync.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/swarm/sync.rs') diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs index 6c67e57..ed4c4da 100644 --- a/src/swarm/sync.rs +++ b/src/swarm/sync.rs @@ -238,6 +238,13 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str) -> Result<()> { let Some(body) = body else { return (session, Ok(None)); }; + // What the envelope adds to an Automerge message (`swarm::stats`), and of + // that, the swarm ID and the epoch (msgpack: 36 bytes the epoch). + let inner = match &body { + transport::SyncBody::Message(payload) => Some(payload.0.len()), + transport::SyncBody::Delta(_) => None, + }; + let ids = rmp_serde::encode::to_vec(&swarm_id).map_or(0, |id| id.len()) + 36; let envelope = transport::SyncEnvelope { swarm_id, epoch, @@ -251,6 +258,9 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str) -> Result<()> { let encoded = transport .encode(&peer_owned, &ParsedMessage::Sync(envelope)) .map(Some); + if let (Ok(Some(encoded)), Some(inner)) = (&encoded, inner) { + stats.sync_framing(encoded.payload_len.saturating_sub(inner), ids); + } (session, encoded) }, ) -- cgit v1.3.1