From 4c3b0ce64d59fa401913158a15d6a2c33232d56d Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Tue, 8 Sep 2026 11:36:04 +0200 Subject: [PATCH] fix: bound the sample camera SUB receive queue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The socket used library defaults, so a GUI that stalls builds its own private FIFO of up to 1000 messages — 20 s of video at 50 Hz — plus whatever the autotuned kernel receive buffer holds on top. PUB/SUB pipes are per-subscriber, which is why only aareGUI lagged while the other receivers stayed current. RCVHWM=4 makes the producer drop frames for this subscriber once it is muted, instead of queueing them, and a fixed RCVBUF stops the kernel hiding a further few dozen frames behind the HWM. Measured against a flooding publisher, the buffered backlog drops from 1000 frames to 4. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01DVqbXPoeHyqrQq5Vc8EcYP --- src/aare/gui/threads/prediction_subscriber.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/aare/gui/threads/prediction_subscriber.py b/src/aare/gui/threads/prediction_subscriber.py index b5234948..42032d82 100644 --- a/src/aare/gui/threads/prediction_subscriber.py +++ b/src/aare/gui/threads/prediction_subscriber.py @@ -30,6 +30,14 @@ class PredictionSubscriber(QThread): self._sock = self._ctx.socket(zmq.SUB) self._sock.setsockopt(zmq.RCVTIMEO, 500) self._sock.setsockopt(zmq.LINGER, 0) + # Cap the backlog the socket may hold. Both must be set before connect() + # to take effect on the pipe. Defaults let the SUB queue grow to 1000 + # messages (20 s of video at 50 Hz) with megabytes more hidden in the + # kernel buffer, which is the backlog _recv_latest would then have to + # throw away every frame. RCVBUF stays well above the ~2.5 MB/s the + # stream actually needs, so it costs no throughput. + self._sock.setsockopt(zmq.RCVHWM, 4) + self._sock.setsockopt(zmq.RCVBUF, 512 * 1024) self._emit_images = True self.running = True