Skip to main content
Version: 0.15.1

Streams and transports

A stream is live data from a unit, and it flows only when a client has asked for it. The Core activates it on the Session, creates a transport for it and tells the unit where that transport is; the unit connects and writes. The data never passes through the Session. Which transport the Core creates is chosen by two answers in the Manifest: whether a lost frame is acceptable, and whether frames out of order are. This page gives the activation, what ends a stream, the transports the two answers select, the largest frame a stream may declare, and the byte layout of each.

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, each after its length
trueanya framed stream socket, or the shared ring where the library offers ita length, then the frame below
falsetruethe framed socket, with loss still refusedthe same; 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 length before every message​

A socket that carries a stream's data is a stream socket, and each message on it is preceded by its length: a u32, little-endian, counting what follows.

  • A Plugin library offers the stream socket at registration, among the transports it offers. For a library that does not, the socket stays a packet socket, where one packet is one message and nothing precedes it.
  • A packet's size is bounded by a send buffer the host sizes, 212 992 bytes on a stock kernel. A stream socket has no such bound, and the length restores the boundary between two messages.
  • A frame is whole or absent. A writer that cannot write a whole frame without waiting writes none of it, and on the framed transport the library drops the next frame rather than interleave two.
  • The Core offers the stream socket from release 0.15, and so does every library published with it.

The largest frame​

A stream declares the largest payload it emits, max_frame, in bytes, in its Manifest.

when absent1 MiB
at most64 MiB; a Manifest declaring more, or less than one byte, is refused as stream.max_frame
on a stream socketa message longer than it ends the stream's transport
on the shared ringit is a slot's capacity, and a larger frame is refused to the producer

Every other payload a unit sends or receives keeps the bound of 1 MiB.

The frame​

OffsetBytesField
08sequence, per stream, from 1, never reused within an activation
88the sender's clock, nanoseconds
16—the payload, opaque
  • Little-endian. On a stream socket the frame follows its length; on a packet socket the packet is the frame.
  • 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, for every delivery it relays; and a client on the host whose library offers to read the ring, handed a descriptor of it opened for reading alone (streams to clients)
how it endsthe Core closing the socket ends the stream, on every route
a new activationa new ring: one a reader still holds after its stream ended is never written again
its size32 slots, each holding a frame of up to the stream's max_frame; above 4 MiB, as many slots as fit in 128 MiB, never fewer than 4

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 the ring's slots 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.