Skip to main content

Crate yo_reactor

Crate yo_reactor 

Source
Expand description

The shard loop.

04 section 2 is nine lines of pseudocode and this crate is those nine lines with the bookkeeping filled in. Six stages, in one order, forever:

  1. hand the submission queue to the kernel, which is one syscall or none,
  2. drain up to BATCH_MAX commands out of the intake lanes,
  3. enter the epoch,
  4. walk the batch once for the prefetch and once for the work,
  5. leave the epoch, then flush one reply buffer per connection touched,
  6. pick up completions and spend a bounded slice on maintenance.

There is no executor here, no future, no waker, no .await and no work stealing. The loop is the scheduler. That is not a stylistic preference: the VLDB 2026 io_uring ladder is 16.5 thousand transactions a second when every submission is waited on and 546.5 thousand when the shard keeps going and picks completions up later, and an async runtime in the middle is how a system gives that back.

§What this crate is and is not

It is the loop, the batch, the two walks, the epoch discipline and the maintenance budget. It is not the commands, the connections or the parser. Those arrive through Engine, which is the seam a shard is plugged in through, and the loop does not know what a command is beyond having a key hash or not having one.

use yo_reactor::{Engine, Flow, Reactor};

struct Counting(u64);

impl Engine for Counting {
    type Work = u64;
    fn key_hash(&self, w: &u64) -> Option<u64> { Some(*w) }
    fn prefetch(&self, _w: &u64, _hash: u64) {}
    fn run(&mut self, w: u64, _hash: Option<u64>) -> Flow { self.0 += w; Flow::Next }
    fn flush(&mut self) {}
}

let mut r = Reactor::inline(Counting(0));
for i in 1..=10 { r.execute(i); }
assert_eq!(r.engine().0, 55);

Structs§

Budget
A slice’s remaining allowance.
Reactor
The loop, and what it keeps between turns.
Turn
What one turn of the loop did.

Enums§

Flow
What the loop does after a command.

Constants§

BATCH_MAX
Commands taken out of the intake lanes in one turn.
MAINTENANCE_UNITS
Units a maintenance slice gets by default, per turn of the loop.

Traits§

Engine
The shard behind the loop.