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
- A client asks for the stream to start.
- The Core activates it, with a control message on the Session.
- The Core creates the stream's transport and listens on it; the activation carries its address.
- 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>.sockunder 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 it | the ordinary case |
| the unit exiting | none of the unit's cleanup runs |
| the Session ending | a 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_loss | tolerates_reorder | Transport | Carries |
|---|---|---|---|
| false | false | an ordered, lossless stream socket | data-family messages, encoded as on the Session |
| true | any | a framed socket, one datagram per frame | the frame below |
| false | true | the framed socket, with loss still refused | the 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
| Offset | Bytes | Field |
|---|---|---|
| 0 | 8 | sequence, per stream, from 1, never reused within an activation |
| 8 | 8 | the 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 Core | never by the unit, so a crash strands nothing |
| named by derivation from the instance | these names are host-wide, and two instances must not collide |
| torn down on all three routes | a 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 object | an anonymous memory file the Core creates, labelled yoke-<instance>-<unit>-<stream> |
| how the producer gets it | a 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 writes | the producing unit alone, handed the descriptor opened for writing |
| who reads | the Core alone, which delivers to every subscriber as it does from any transport: no client reads the ring |
| how it ends | the Core closing the socket ends the stream, on every route |
| its size | 32 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 offset | Size | Field |
|---|---|---|
| 0 | 8 | magic, YOKERING in ASCII |
| 8 | 4 | version — the layout's, 1 |
| 12 | 4 | slots |
| 16 | 4 | capacity — a slot's payload capacity, in bytes |
| 20 | 4 | reserved, zero |
| 24 | 8 | published — the count of frames published, written atomically |
| 32 | 4 | wake — the word a reader waits on, bumped atomically |
| 36 | 28 | reserved, zero |
| Slot offset | Size | Field |
|---|---|---|
| 0 | 8 | sequence — the frame's, written atomically, zero while the slot is being written |
| 8 | 8 | clock — the producer's, nanoseconds |
| 16 | 4 | length — the payload's |
| 20 | 12 | padding, zero |
| 32 | capacity | the 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.inactiveis data arriving on a channel that outlived its activation. Ordinarily a unit emitting after the stop finds no reader at all.