Merge pull request #97 from AndreyAkifev/main

Fix ME relay HOL and reduce per-frame flush overhead
This commit is contained in:
Alexey
2026-02-16 10:29:40 +03:00
committed by GitHub
2 changed files with 15 additions and 5 deletions

View File

@@ -263,7 +263,14 @@ where
} }
} }
client_writer.flush().await.map_err(ProxyError::Io) // Avoid unconditional per-frame flush (throughput killer on large downloads).
// Flush only when low-latency ack semantics are requested or when
// CryptoWriter has buffered pending ciphertext that must be drained.
if quickack || client_writer.has_pending() {
client_writer.flush().await.map_err(ProxyError::Io)?;
}
Ok(())
} }
async fn write_client_ack<W>( async fn write_client_ack<W>(
@@ -283,5 +290,6 @@ where
.write_all(&bytes) .write_all(&bytes)
.await .await
.map_err(ProxyError::Io)?; .map_err(ProxyError::Io)?;
// ACK should remain low-latency.
client_writer.flush().await.map_err(ProxyError::Io) client_writer.flush().await.map_err(ProxyError::Io)
} }

View File

@@ -9,7 +9,7 @@ use std::sync::Arc;
use tokio::sync::Mutex; use tokio::sync::Mutex;
pub struct ConnRegistry { pub struct ConnRegistry {
map: RwLock<HashMap<u64, mpsc::Sender<MeResponse>>>, map: RwLock<HashMap<u64, mpsc::UnboundedSender<MeResponse>>>,
writers: RwLock<HashMap<u64, Arc<Mutex<RpcWriter>>>>, writers: RwLock<HashMap<u64, Arc<Mutex<RpcWriter>>>>,
next_id: AtomicU64, next_id: AtomicU64,
} }
@@ -25,9 +25,11 @@ impl ConnRegistry {
} }
} }
pub async fn register(&self) -> (u64, mpsc::Receiver<MeResponse>) { pub async fn register(&self) -> (u64, mpsc::UnboundedReceiver<MeResponse>) {
let id = self.next_id.fetch_add(1, Ordering::Relaxed); let id = self.next_id.fetch_add(1, Ordering::Relaxed);
let (tx, rx) = mpsc::channel(256); // Unbounded per-connection queue prevents reader-loop HOL blocking on
// slow clients: routing stays non-blocking and preserves message order.
let (tx, rx) = mpsc::unbounded_channel();
self.map.write().await.insert(id, tx); self.map.write().await.insert(id, tx);
(id, rx) (id, rx)
} }
@@ -40,7 +42,7 @@ impl ConnRegistry {
pub async fn route(&self, id: u64, resp: MeResponse) -> bool { pub async fn route(&self, id: u64, resp: MeResponse) -> bool {
let m = self.map.read().await; let m = self.map.read().await;
if let Some(tx) = m.get(&id) { if let Some(tx) = m.get(&id) {
tx.send(resp).await.is_ok() tx.send(resp).is_ok()
} else { } else {
false false
} }