From f0e181d6b80a925540bc4efc512f579ba1cd1a66 Mon Sep 17 00:00:00 2001 From: alpha-nerd-nomyo Date: Fri, 19 Sep 2025 16:38:48 +0200 Subject: [PATCH] improving queue logic for high load scenarios --- router.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/router.py b/router.py index 374ccbc..6243dee 100644 --- a/router.py +++ b/router.py @@ -327,12 +327,16 @@ class rechunk: # SSE Helpser # ------------------------------------------------------------------ async def publish_snapshot(): - snapshot = json.dumps({"usage_counts": usage_counts}) + async with usage_lock: + snapshot = json.dumps({"usage_counts": usage_counts}) async with _subscribers_lock: for q in _subscribers: # If the queue is full, drop the message to avoid back‑pressure. if q.full(): - continue + try: + await q.get() + except asyncio.QueueEmpty: + pass await q.put(snapshot) async def close_all_sse_queues():