morb 0.2.0

A lightweight in-process publish/subscribe library for Rust
Documentation
  • Coverage
  • 80.77%
    21 out of 26 items documented0 out of 24 items with examples
  • Size
  • Source code size: 37.45 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.89 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 31s Average build duration of successful builds.
  • all releases: 33s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • HumpbackLab/morb
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Ncerzzk

morb

morb is a lightweight in-process publish/subscribe library for Rust. It provides named Topics, a fixed-size ring buffer, and poll-based notifications built on mio and eventfd.

The current implementation targets Linux.

Quick Start

use morb::{create_topic, TopicPoller};
use std::time::Duration;

fn main() -> std::io::Result<()> {
    let topic = create_topic::<u32>("numbers".to_string(), 16)?;
    let publisher = topic.create_publisher();
    let mut subscriber = topic.create_subscriber();

    publisher.publish(42);
    assert!(subscriber.check_update());
    assert_eq!(subscriber.check_update_and_copy(), Some(42));

    let mut poller = TopicPoller::new();
    poller.add_topic(&topic)?;

    publisher.publish(100);
    poller.wait(Some(Duration::from_millis(100)))?;

    for token in poller.iter() {
        if token == topic.token() {
            println!("{} updated", topic.name());
        }
    }

    Ok(())
}

Run tests:

cargo test

Run the benchmark example:

cargo run --release --example pubsub_benchmark -- 200000

Current sample results on this repository's benchmark setup (-- 200000):

morb benchmark
iterations: 200000
queue_size: 1024
publish_only             200000 ops          7.35 ns/op  136029991.89 ops/s
publish_consume          200000 ops         11.19 ns/op   89325671.57 ops/s
publish_poll             200000 ops         18.69 ns/op   53502501.11 ops/s
multi_producer           200000 ops         51.76 ns/op   19320608.20 ops/s
multi_subscriber         200000 ops         37.32 ns/op   26796238.99 ops/s
large_msg_64             200000 ops         17.26 ns/op   57953477.27 ops/s
large_msg_256            200000 ops         37.53 ns/op   26647693.51 ops/s
large_msg_1024           200000 ops         75.61 ns/op   13225916.85 ops/s
blocking_poll             50000 ops      28460.42 ns/op      35136.52 ops/s

Notes:

  • multi_subscriber runs 4 subscribers over 50,000 messages each, reported as 200,000 total subscriber reads.
  • blocking_poll is capped at 50,000 waits to keep runtime practical.
  • Results are machine-dependent and should be used for relative comparisons, not absolute guarantees.