From fd268e2a7c8ff7e7707ae79b4f4916a50f222188 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 5 Nov 2026 04:11:34 +0100 Subject: measure deflated chunks --- src/swarm/blob.rs | 22 ++++++++++++++-------- src/swarm/stats.rs | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'src/swarm') diff --git a/src/swarm/blob.rs b/src/swarm/blob.rs index 0bd2d37..f06b251 100644 --- a/src/swarm/blob.rs +++ b/src/swarm/blob.rs @@ -339,14 +339,20 @@ async fn serve( let chunk = &prepared.bytes[start..end]; // Deflated where it shrinks (`compress`): changes are stored uncompressed. let body = match crate::compress::deflate(chunk) { - Some(deflated) => BlobBody::DeflatedChunk { - index, - data: deflated.into(), - }, - None => BlobBody::Chunk { - index, - data: bytes::Bytes::copy_from_slice(chunk), - }, + Some(deflated) => { + state.stats.chunk_served(chunk.len(), deflated.len()); + BlobBody::DeflatedChunk { + index, + data: deflated.into(), + } + } + None => { + state.stats.chunk_served(chunk.len(), chunk.len()); + BlobBody::Chunk { + index, + data: bytes::Bytes::copy_from_slice(chunk), + } + } }; reply(state, peer, id, body).await; } diff --git a/src/swarm/stats.rs b/src/swarm/stats.rs index 6332901..31b6a3b 100644 --- a/src/swarm/stats.rs +++ b/src/swarm/stats.rs @@ -137,6 +137,11 @@ pub(crate) struct Relay { pub(crate) deflated: u64, pub(crate) deflated_from: u64, pub(crate) deflated_to: u64, + /// Blob chunks served, those of them deflated, and their bytes before and as sent. + pub(crate) chunks_served: u64, + pub(crate) chunks_deflated: u64, + pub(crate) chunk_bytes: u64, + pub(crate) chunk_bytes_sent: u64, /// Sync messages received that carried changes, all of which we had already, and /// their payload's bytes: changes that came twice. Of those, how many came along a /// writer's tree (`SyncEnvelope::writer`), and how many were taken as delivered by @@ -258,6 +263,15 @@ impl NodeStats { self.lock().relay.tree_forwards += 1; } + /// A blob chunk of `bytes` was served as `sent` bytes (fewer if deflated). + pub(crate) fn chunk_served(&self, bytes: usize, sent: usize) { + let mut inner = self.lock(); + inner.relay.chunks_served += 1; + inner.relay.chunks_deflated += u64::from(sent < bytes); + inner.relay.chunk_bytes += bytes as u64; + inner.relay.chunk_bytes_sent += sent as u64; + } + /// A sync message of `from` bytes went out deflated to `to`. pub(crate) fn deflated(&self, from: usize, to: usize) { let mut inner = self.lock(); -- cgit v1.3.1