Skip to main content

Crate raio

Crate raio 

Source
Expand description

raio is a deterministic realtime runtime for apps made of nodes in separate processes.

A node’s tasks set values on output ports, and wait for values on input ports and for logical time to pass. Every value has a timestamp, a point in logical time, and a node moves to a timestamp only once none of its inputs can still bring an earlier value. So every run of an app sees the same events in the same order, however fast each process happens to be. What comes from outside the app, such as an app::Action or the future of another runtime, gets its timestamp from the wall clock and is marked physical.

use raio::app::{App, Builder, InputPort, Node, OutputPort, Ports, node};
use raio::time::MS;

#[derive(Ports)]
struct Producer {
    node: Node,
    out: OutputPort<String>,
}

#[node]
impl Producer {
    fn new(builder: &mut Builder) -> Self {
        Self {
            node: builder.node(),
            out: builder.output(),
        }
    }

    #[task]
    async fn produce(&self) {
        self.node.wait(1 * MS).await;
        self.out.set("hello world".to_string());
    }
}

#[derive(Ports)]
struct Sink {
    input: InputPort<String>,
}

#[node]
impl Sink {
    fn new(builder: &mut Builder) -> Self {
        Self {
            input: builder.input(),
        }
    }

    #[reaction(input)]
    fn show(&self) {
        println!("sink received {:?}", *self.input.get().unwrap());
    }
}

let mut app = App::new();
let producer = app.create_node(Producer::new);
let sink = app.create_node(Sink::new);
app.connect(&producer.out, &sink.input);
app.run();

§Modules

  • app: the building blocks of a node program, and the App that connects and launches nodes.
  • time: timestamps and durations.
  • serializer and transport: how a connection encodes values and carries them.
  • node: the scheduler that orders the events of one node by timestamp.
  • coordinator and messages: the graph of an app, and how its nodes are wired and shut down together.
  • diagram: a picture of an app, with its nodes, their tasks, and their connections.
  • runtime and driver: the single-threaded executor under each node, and its I/O and timers.

§Features

  • serde_bytes: encodes the value of a frame as one block of bytes, not byte by byte, which is much faster for large values. The Python binding has it on. A node built with it and a node built without it can connect.

Modules§

app
The building blocks of a node program: the ports, actions and reactions of a node, and the App that connects nodes and launches them.
coordinator
The coordinator of an app. Every node connects to it and goes through three stages: it gets its code, registers its ports and gets its wiring, and then runs, sending a heartbeat, until it ends. Every shutdown of an app comes from its coordinator: at a timestamp that the nodes agree on, or at once when the app is interrupted or one of its nodes fails. Link is the node’s side.
diagram
A diagram of an app in the style of Lingua Franca: each node is a box with its ports on its sides, their names beside them and its tasks and reactions in the middle, and each connection is a line. A task is a rectangle with rounded corners. A reaction is a box with a point, and a line joins it to each port or action that triggers it. Each task and reaction has its number in its corner. elkrs places the nodes and routes the connections; svg draws the result.
driver
The I/O driver: each thread has one, and it wakes tasks when their descriptors are ready or their timers are due.
messages
Everything that crosses a process boundary: the messages between a node and its coordinator, in the order of their stages, and the frame that a connection carries.
node
A node: the handle that its tasks hold, and the scheduler that orders its events by timestamp.
runtime
A single-threaded executor. Each waker says whether its task resumes at the node’s current timestamp or at a new physical timestamp; the node’s scheduler applies that.
serializer
Converting port values to and from bytes.
time
Logical time: a Time is a timestamp, which is a point on a node’s timeline, or a duration.
transport
Carrying bytes between processes.

Constants§

VERSION
The version of raio, with the commit hash when built from a git checkout: 0.2.0+abc1234.