fix: bound the sample camera SUB receive queue
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DVqbXPoeHyqrQq5Vc8EcYP
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user