Skip to main content
Version: 0.11.0

Streams and transports

What makes data flow, what a stream's declared tolerances select, and what ends a stream.

A stream flows because it was told to​

  1. A client asks for the stream to start.
  2. The Core activates it, with a control message on the Session.
  3. The Core creates the stream's transport and listens on it; the activation carries its address.
  4. The unit connects and emits.
  • A unit that was never told to emit has nothing to emit into: the transport does not exist until the Core creates it.
  • The Core listens and the unit connects.
  • The address is derived: plugins/<unit>/streams/<stream>.sock under the instance.
  • Activation and the instruction that stops a stream always travel on the Session. The data never does.

Three routes end a stream​

Route
the instruction that stops itthe ordinary case
the unit exitingnone of the unit's cleanup runs
the Session endinga unit revoked and admitted again starts with nothing open

The Core removes the transport in all three.

What the tolerances select​

A stream declares two independent properties in its Manifest: whether a lost message is acceptable (tolerates_loss), and whether messages out of order are (tolerates_reorder). Both default to false. The transport is chosen by these, never by what the data means.

tolerates_losstolerates_reorderTransportCarries
falsefalsean ordered, lossless stream socketdata-family messages, encoded as on the Session
trueanya framed socket, one datagram per framethe frame below
falsetruethe framed socket, with loss still refusedthe frame below; a gap in the sequence is a fault

This is what this release builds. Another implementation serving the same tolerances with other paths would conform, which is why the activation names the transport.

The frame​

OffsetBytesField
08sequence, per stream, from 1, never reused within an activation
88the sender's clock, nanoseconds
16—the payload, opaque
  • Little-endian. The datagram is the frame, so there is no length prefix.
  • A gap in the sequence means a frame was lost; a decrease means one arrived out of order.
  • No stream identifier and no Session identity: the transport belongs to one stream of one Session.

What every transport keeps​

  • the stream's identity;
  • the granted scope it is checked against;
  • the activation that started it and the instruction that stops it, on the Session;
  • the payload's opacity: the Core carries bytes and never interprets them.

Objects that are not sockets​

A stream delivered to several consumers may use a shared object the unit writes once and each consumer reads at its own pace.

Obligation
created and removed by the Corenever by the unit, so a crash strands nothing
named by derivation from the instancethese names are host-wide, and two instances must not collide
torn down on all three routesa stale buffer answers where a stale socket would refuse
  • The limit is 255 bytes for a host-wide object name and 107 for a socket path; both are computed before anything runs.
  • A shared object is a way to fan out, not a way around: the stream is still activated, still bound by the scope, still opaque.
  • A subscriber's socket sits under its unit: plugins/<unit>/subscribers/<stream>/….

The shared ring​

The one shared object is a ring, and it carries a stream that tolerates loss. Nothing is declared for it: the two tolerances select it, as they select a socket.

the objectan anonymous memory file the Core creates, labelled yoke-<instance>-<unit>-<stream>
how the producer gets ita descriptor, passed as ancillary data in the one byte that is the first message on a socket the Core creates; the activation names the transport shared
who writesthe producing unit alone, handed the descriptor opened for writing
who readsthe Core alone, which delivers to every subscriber as it does from any transport: no client reads the ring
how it endsthe Core closing the socket ends the stream, on every route
its size32 slots, each holding a frame of up to 1 MiB

The ring's geometry is read from its header, which the Core writes when it creates it; nothing writes it afterwards but its two counters.

Header offsetSizeField
08magic, YOKERING in ASCII
84version — the layout's, 1
124slots
164capacity — a slot's payload capacity, in bytes
204reserved, zero
248published — the count of frames published, written atomically
324wake — the word a reader waits on, bumped atomically
3628reserved, zero
Slot offsetSizeField
08sequence — the frame's, written atomically, zero while the slot is being written
88clock — the producer's, nanoseconds
164length — the payload's
2012padding, zero
32capacitythe payload

Slot i begins at 64 + i × (32 + capacity), and frame n, counted from 1, is in slot (n − 1) mod slots. A Plugin library offers the ring by naming it among the transports it offers at registration; the Core activates a stream that tolerates loss on the ring only for a library that did.

A reader that falls more than 32 frames behind, or reads a slot the producer overwrote while it read, meets a gap, as a lost datagram is one on the framed transport. The Core offers the ring from release 0.5; until then a stream that tolerates loss is carried on the framed transport.

Every Plugin library offers it. Go and C have since the Core did; Rust and Python from their 0.5, and C++ from its 0.7. A library that does not ask for it is given the framed transport, and the stream reads the same to a subscriber either way.

Order, and what relates two channels​

  • One order per channel; none across channels.
  • An error on the Session about a data message names it by correlation. On the ordered path each data message has an identity to name; on the framed path there is none.
  • stream.inactive is data arriving on a channel that outlived its activation. Ordinarily a unit emitting after the stop finds no reader at all.