From 26135471cbe0e15cd1a0201cdf185d91a6d258ba Mon Sep 17 00:00:00 2001 From: _ <> Date: Sat, 17 Jul 2021 22:03:55 +0000 Subject: [PATCH] :loud_sound: counting active QUIC connections for P3 --- .../src/bin/quic_demo_relay_server.rs | 44 ++++++++++++++++++- prototypes/quic_demo/src/prelude.rs | 8 +++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs b/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs index beb8fb4..2f0445e 100644 --- a/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs +++ b/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs @@ -16,7 +16,16 @@ async fn main () -> anyhow::Result <()> { // Each new peer QUIC connection gets its own task tokio::spawn (async move { - handle_quic_connection (relay_state, conn).await + let active = relay_state.stats.quic.connect (); + debug! ("QUIC connections: {}", active); + + match handle_quic_connection (Arc::clone (&relay_state), conn).await { + Ok (_) => (), + Err (e) => warn! ("handle_quic_connection {:?}", e), + } + + let active = relay_state.stats.quic.disconnect (); + debug! ("QUIC connections: {}", active); }); } @@ -26,10 +35,43 @@ async fn main () -> anyhow::Result <()> { #[derive (Default)] struct RelayState { p4_server_proxies: Mutex >, + stats: Stats, +} + +#[derive (Default)] +struct Stats { + quic: ConnectEvents, +} + +#[derive (Default)] +struct ConnectEvents { + connects: AtomicU64, + disconnects: AtomicU64, +} + +impl ConnectEvents { + fn connect (&self) -> u64 { + let connects = self.connects.fetch_add (1, Ordering::Relaxed) + 1; + let disconnects = self.disconnects.load (Ordering::Relaxed); + connects - disconnects + } + + fn disconnect (&self) -> u64 { + let disconnects = self.disconnects.fetch_add (1, Ordering::Relaxed) + 1; + let connects = self.connects.load (Ordering::Relaxed); + connects - disconnects + } + + fn active (&self) -> u64 { + let connects = self.connects.load (Ordering::Relaxed); + let disconnects = self.disconnects.load (Ordering::Relaxed); + connects - disconnects + } } struct P4State { req_channel: mpsc::Sender , + } impl RelayState { diff --git a/prototypes/quic_demo/src/prelude.rs b/prototypes/quic_demo/src/prelude.rs index 8ffebb4..d09500a 100644 --- a/prototypes/quic_demo/src/prelude.rs +++ b/prototypes/quic_demo/src/prelude.rs @@ -1,6 +1,12 @@ pub use std::{ collections::*, - sync::Arc, + sync::{ + Arc, + atomic::{ + AtomicU64, + Ordering, + }, + }, time::Duration, };