From 7dbef63e53a816c49b806204184859d88e2452c7 Mon Sep 17 00:00:00 2001 From: Lance-Drane Date: Mon, 30 Sep 2024 10:45:55 -0400 Subject: [PATCH] broker2http - increase tokio::broadcast::channel capacity to try handling receiver lags Signed-off-by: Lance-Drane --- broker-2-http/src/broadcaster.rs | 4 ++-- broker-2-http/src/routes/subscribe.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/broker-2-http/src/broadcaster.rs b/broker-2-http/src/broadcaster.rs index 88973b8..8861ac3 100644 --- a/broker-2-http/src/broadcaster.rs +++ b/broker-2-http/src/broadcaster.rs @@ -17,8 +17,8 @@ impl Broadcaster { /// Create the broadcaster. Note that it automatically wraps it in an Arc. /// The broadcaster manages its producer but does not manage its consumers pub fn new() -> Arc { - // TODO may be able to get away with smaller capacity - let (tx, _) = broadcast::channel(1); + // use a fairly large channel capacity to account for potential receiver lags + let (tx, _) = broadcast::channel(256); Arc::new(Broadcaster { fanout: tx }) } diff --git a/broker-2-http/src/routes/subscribe.rs b/broker-2-http/src/routes/subscribe.rs index 258a389..948a2f2 100644 --- a/broker-2-http/src/routes/subscribe.rs +++ b/broker-2-http/src/routes/subscribe.rs @@ -27,6 +27,7 @@ fn sse_response( break; }, // send the broadcast message to the client, and continue listening for more messages + // TODO figure out more robust mechanism to handle "lagged" errors from the receiver. resp = rx.recv() => { match resp { Ok(event) => {