From 579fcb214067aa1a95203132523d5c402c45f24f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Fri, 5 Jan 2024 23:13:31 +0100 Subject: [PATCH] ws: don't yield unnecessarily in run_in_message_loop, improve logging --- crates/ws/src/workers/socket/connection.rs | 8 +------- crates/ws/src/workers/socket/mod.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/ws/src/workers/socket/connection.rs b/crates/ws/src/workers/socket/connection.rs index b4fbc54..67f569c 100644 --- a/crates/ws/src/workers/socket/connection.rs +++ b/crates/ws/src/workers/socket/connection.rs @@ -20,7 +20,7 @@ use futures_rustls::TlsAcceptor; use glommio::channels::channel_mesh::Senders; use glommio::channels::local_channel::{LocalReceiver, LocalSender}; use glommio::net::TcpStream; -use glommio::timer::{sleep, timeout}; +use glommio::timer::timeout; use glommio::{enclose, prelude::*}; use hashbrown::hash_map::Entry; use hashbrown::HashMap; @@ -214,12 +214,6 @@ struct ConnectionReader { impl ConnectionReader { async fn run_in_message_loop(&mut self) -> anyhow::Result<()> { loop { - while self.out_message_sender.is_full() { - sleep(Duration::from_millis(100)).await; - - yield_if_needed().await; - } - let message = self .ws_in .next() diff --git a/crates/ws/src/workers/socket/mod.rs b/crates/ws/src/workers/socket/mod.rs index 7bc6c72..7056747 100644 --- a/crates/ws/src/workers/socket/mod.rs +++ b/crates/ws/src/workers/socket/mod.rs @@ -287,10 +287,14 @@ async fn receive_out_messages( match reference.out_message_sender.try_send((meta, out_message)) { Ok(()) => {} Err(GlommioError::Closed(_)) => {} - Err(GlommioError::WouldBlock(_)) => {} + Err(GlommioError::WouldBlock(_)) => { + ::log::debug!( + "couldn't send OutMessage over local channel to Connection, channel full" + ); + } Err(err) => { ::log::debug!( - "Couldn't send out_message from shared channel to local receiver: {:?}", + "couldn't send OutMessage over local channel to Connection: {:?}", err ); }