Files
Jungfraujoch/docs
leonarski_fandClaude Fable 5.1 1be6093429 Writer: received images live in a byte-bounded ring buffer until written and republished
Every stage between the socket and the HDF5 write was bounded by a message count and never by
bytes: ZeroMQ receive watermark 100, cbor_fifo 200, outside_fifo 1000, repub_fifo 200 - up to
some 1500 images in flight per writer process, each a whole compressed image, so 6-12 GB for a
JUNGFRAU 4M and 30-60 GB for a 9M, and the writer's memory was a quantity nobody had chosen.

ReceiveRingBuffer is a fixed ring of bytes owned by the ImagePuller base class, so the ZeroMQ
and TCP pullers share it. A message is received straight into it (TCP reads the payload into
the ring; ZeroMQ copies the message in) and travels as a shared_ptr region in ImagePullerOutput;
the deserialised image points into that region, republish sends it as is, and the bytes come
back when the last holder lets go. Space is reclaimed in arrival order: a region released out
of turn - republish finishes with messages in its own order - is marked and waits for the ones
in front of it. Because of that, what republish may hold is capped at a quarter of the ring,
and an image over the cap is not republished, exactly as one that finds the republish queue
full; otherwise a stalled republish consumer would pin the ring and slow the writer to its
rate. A message larger than the whole ring (a START or END of a very long run) goes on the heap,
so it cannot wedge the receiver.

A full ring stalls the receive thread, and what that does depends on the stream. On TCP the
pusher waits behind the writer's BUSY heartbeats and gives up only after a minute in which no
image at all was written. On ZeroMQ the pusher's send blocks for one second, then drops the
image and sends without waiting for the rest of the run - so on ZeroMQ a ring that is smaller
than the writer's stalls costs images, where the old 1500-message queues absorbed them. That
is the trade: the budget is now a number, and it has to be chosen. jfjoch_writer sets it with
-m/--rcv_ring_mb, default 2048 MB per writer process; the ZeroMQ receive watermark default goes
from 100 to 10 messages, since it now only counts what sits beyond the ring. The ring's peak
use is in the end-of-run log line, and docs/JFJOCH_WRITER.md has a Memory section with the
sizing rule.

The puller's own default is no ring at all, which keeps every other user as it was: the
broker's DECTRIS stream2 puller (JFJochServices, JFJochReceiverService) stays zero-copy with
the ZeroMQ message as the buffer, and the broker's direct HDF5 writer (HDF5FilePusher ->
FileWriter) never goes through a puller. The puller threads now also catch std::exception, as
the writer does since the previous commit: deserialising the END message of a million-image
run allocates a vector per per-image array, and a bad_alloc leaving the thread ended the process.

Tests: ReceiveRingBufferTest (reuse, wrap-around, full ring, out-of-order release, heap
fallback, zero size, stop, a region outliving its ring); ZMQImageCommTest_SmallRingBuffer (64
one-megabyte images through a three-image ring, nothing lost, peak within the bound); one of
the two writers in TCPImageCommTest_2Writers_WithAck runs on a three-image ring.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-13 12:51:34 +02:00
..
2026-10-07 14:14:39 +02:00
2026-09-29 15:57:32 +02:00
2026-10-07 14:14:39 +02:00
2026-09-29 15:57:32 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2024-11-22 21:25:20 +01:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-29 15:57:32 +02:00
2026-09-17 14:42:52 +02:00
2026-10-06 14:03:18 +02:00
2025-11-28 12:47:35 +01:00
2026-07-11 07:19:11 +02:00
2024-12-02 21:17:14 +01:00
2026-09-29 15:57:32 +02:00
2026-09-29 15:57:32 +02:00
2026-09-29 15:57:32 +02:00
2026-09-17 14:42:52 +02:00
2024-11-22 21:25:20 +01:00
2026-09-17 14:42:52 +02:00
2026-10-06 14:03:18 +02:00
2026-10-06 14:03:18 +02:00
2026-09-22 06:48:37 +02:00
2026-09-17 14:42:52 +02:00
2026-09-17 14:42:52 +02:00
2026-09-29 15:57:32 +02:00