Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

ergon is a set of Rust crates you can use on their own. ergo-sbe generates Simple Binary Encoding codecs. ergo-aeron-cluster is an experimental Aeron Cluster client. ergon-tune reads a host and names the settings that will wreck a tail latency. The Kubernetes pieces give a pod exclusive CPUs and a latency-pod policy. You do not need a cluster to generate a codec, and you do not need the other crates to use one of them.

0.x alpha: any release may break the API, with no deprecation period. Pin exact versions and read the changelog before upgrading. Exit criteria: Road to 1.0.

How to read this book

The sidebar has one part per module. A module with deep pages has two parts, start here (the light pages) and in depth. Stop after the light pages and go to the next module, or carry on into the deep pages. Each module’s samples sit in its own part, and the detail chapters are linked by name.

Module (sidebar part)Light pagesDeep pagesFor
ergo-sbeGetting started, feature tourCore concepts, configuration, recipes, design notes, benchmarks, samples (including build patterns and the buffer sizing guide)Anyone with an SBE schema who wants Rust codecs
ergo-sbe-inspectInspect bytes with no codec, the sbe-inspect filterHow a reading is chosen, framing detectionAnyone who has SBE bytes and schemas but no compiled codec
ergo-aeronergo-aeron, live messages, scripts and pipesDriver tabs, counters, attached or embedded, archive tabs, in KubernetesAnyone who runs an Aeron media driver or archive
ergo-aeron-clusterCluster client, cluster tutorialSessionBuilder, egress, chained decoding, compatibility, HA order book, RFQAnyone who needs an Aeron Cluster client (experimental)
ergon-tuneHost checksNone: one pageAnyone starting a process on a latency host
Kubernetes and deploymentShared CPUs, latency podsLow-latency hosts and its pagesAnyone deploying a busy-spin pod
ProjectContributing, Road to 1.0Verification and release, performance, AI assistanceContributors and reviewers
flowchart LR
  schema["schema XML"] --> gen["ergo-sbe in build.rs"]
  gen --> enc["try_wrap or wrap"]
  enc --> fields["fields in wire order"]
  fields --> bytes["SBE frame"]
  bytes --> dec["try_decode"]
  dec --> view["flyweight view or owned snapshot"]

A message written out of tail order is a compile error. Checked constructors return Result; the three constructor tiers are specified in one place, Trust boundary. Size the buffer with the generated length API before you write; the rule table is Buffer sizing.

Crates

CrateWhat it doesWhen to use it
ergo-sbeGenerates Rust SBE codecs from schema XML. Wire layout matches official SBE for the published profile. Generated codecs embed sbe_rt, so the generator is not on the hot path.You have an SBE schema and want encode and decode in Rust. ergo_sbe::generate(source, config)?.write_to_out_dir()? in build.rs, then include! or ergo_sbe::sbe_mod!(name) (Depend).
ergo-sbe-inspectReads SBE bytes at run time against any number of schemas: which message, how sure, and every candidate when it cannot choose. No generated code.You have bytes and schemas but no compiled codec (overview).
ergo-aeron-toolsergo-aeron: an Aeron media driver’s counters, streams, errors, loss and messages, and an archive’s recordings, in a terminal UI or a pipe.You run an Aeron driver and want to see what it is doing (overview).
ergon-tuneReads the host and names what will wreck a tail latency, and the fix.At start-up on a latency host. It changes nothing (Host checks).
ergo-aeron-clusterAn Aeron Cluster client.You need a cluster client. Experimental, not a production substitute (overview).
PieceWhat it doesWhen to use it
k8s/nri-shared-cpusGives a pod its exclusive CPUs and the node’s shared housekeeping CPUs, and starts every thread on the shared ones so the busy-spin loop keeps its core.A pod that spins on exclusive CPUs. Chart oci://ghcr.io/mimran1980/charts/ergon-shared-cpus version 0.1.6, image ghcr.io/mimran1980/ergon-shared-cpus:0.1.6. Prepare the node first (chapter).
k8s/nri-latency-podsNode tuning and the hot-pod admission policy: no exec probes, no always-restart sidecars. The grants live in the shared-cpus image.After the chart. Apply the admission YAML, then label hot pods ergon.io/latency: hot (chapter).

Start with ergo-sbe. Add another row only for a need you have.

Flyweight or an owned snapshot

You haveUseCost
A few fields, and the work finishes while the frame is borrowedThe flyweight decoder (price(), and so on)No whole-message copy
A value that must outlive the bufferThe owned *Domain snapshot from with_domain_objectsAllocates. Tooling and logs, not a hot path

The full comparison, including *FixedFields and the *Source trait, is Flyweight vs whole struct. Mapping a wire field to an application type (with_conversion or with_domain_type) is a different switch: with_conversion vs with_domain_type.

Detail chapters

Read these when the light pages are not enough. Each topic is written in full on the page named here.

TopicChapter
Constructor tiers, acting block length, and group tailsTrust boundary
compute_length_with_header and *EncodedLengthBuffer sizing
Borrowed view versus owned snapshotFlyweight vs whole struct
with_conversion versus with_domain_typewith_conversion vs with_domain_type
Wire order as named stagesWire order
Cluster session, egress, chained decode, compatibilitySessionBuilder, egress, chained decoding, compatibility
Node tuning and clocksHFT tuning, clocks

Use the animations

The diagrams in the detail chapters show work and ownership step by step. Use Next to inspect one transition, Back to compare it with the previous state, or Play for the whole sequence, or drag the timeline directly to a step. With focus inside a diagram, arrow keys step and Space plays or pauses. Reduced-motion preferences turn movement off; the controls still work. Each diagram has captions and an accompanying text explanation, so its lesson also works without animation or JavaScript. Schematic widths and illustrative byte counts are labelled; movement is not a timing measurement.

A first encode

[build-dependencies]
ergo-sbe = "0.1"

[dependencies]
ergo-sbe = "0.1"   # only for sbe_mod! / include_sbe!
#![allow(unused)]
fn main() {
let mut buf = [0u8; HeartbeatEncoder::compute_length_with_header()];
// Buffer is exact size from const compute_length_with_header — no bounds check needed.
let len = HeartbeatEncoder::try_wrap_and_apply_header(&mut buf, 0)?
    .fixed(&HeartbeatFixedFields { sequence: 7, timestamp: 0 })
    .encoded_length_with_header();
let dec = HeartbeatDecoder::try_from(&buf[..len])?;
assert_eq!(dec.sequence(), 7);
}

(From book/examples/heartbeat-encode.rs, compiled against the feature-tour codec.)

Set up → · Feature tour → · Coming from sbe-tool →

Nested groups use scoped closures, so you do not hand encoder ownership back with .parent():

#![allow(unused)]
fn main() {
pub fn encode_sample_car(buf: &mut [u8]) -> Result<usize, sbe_rt::EncodeError> {
    let mut extras = OptionalExtras::default();
    extras.cruise_control(true).sports_pack(true);

    // Buffer pre-sized from EncodedLength; try_* still validates extent.
    let len = CarEncoder::try_wrap_and_apply_header(buf, 0)
        .unwrap()
        .fixed(&CarFixedFields {
            serial_number: 1234,
            model_year: 2013,
            available: true.into(),
            code: Model::A,
            some_numbers: [10, 20, 30, 40],
            vehicle_code: [b'A', b'B', b'C', b'D', b'E', b'F'],
            extras,
            engine: Engine::new(
                2000,
                4,
                [b'1', b'2', b'3'],
                0i8,
                false.into(),
                Booster::new(BoostType::TURBO, 210),
            ),
        })
        .fuel_figures(2, |g| {
            g.add(|mut e| {
                e.speed(30).mpg(35.9);
                e.usage_description_as_str("Urban")
            })?;
            g.add(|mut e| {
                e.speed(60).mpg(25.0);
                e.usage_description_as_str("Highway")
            })?;
            Ok(())
        })?
        .performance_figures(1, |g| {
            g.add(|mut e| {
                e.octane_rating(95);
                e.acceleration(2, |a| {
                    a.add(|x| {
                        x.mph(30).seconds(4.0);
                        Ok(())
                    })?;
                    a.add(|x| {
                        x.mph(60).seconds(7.5);
                        Ok(())
                    })
                })
            })?;
            Ok(())
        })?
        .manufacturer_as_str("Honda")?
        .model_as_str("Civic VTi")?
        .activation_code_as_str("abcdef")?
        .encoded_length_with_header();

    Ok(len)
}
}

(Compiled and run in CI.)

It is not a line-for-line port of sbe-tool. The generated API is meant to be easier under Rust’s borrow checker, safer at untrusted boundaries, and still official-SBE on the wire for the shapes under test. Wire parity is tested by the dual-encode suite (sbe_tool_wire_parity_test, sbe_tool_multi_schema_wire_parity_test). The benchmarks also assert byte parity before timing: Benchmarks. Encode and decode of the generated codecs do not allocate on the hot path (allocation_count_test).

Hosts and Kubernetes: Deployment. Which clock to read: Clocks.

Rust 1.99+. Clone setup and checks: repository README.