Crates.io | disruptor-rs |
lib.rs | disruptor-rs |
version | 0.1.0 |
source | src |
created_at | 2024-11-02 15:53:07.74452 |
updated_at | 2024-11-02 15:53:07.74452 |
description | A high-performance ring buffer implementation of the LMAX Disruptor pattern |
homepage | |
repository | https://github.com/khaledyassin/disruptor-rs |
max_upload_size | |
id | 1432973 |
size | 79,400 |
A heavily documented Rust implementation of the LMAX Disruptor pattern, focused on high-performance inter-thread messaging.
This project is a fork of disrustor by Sebastian Klose. While the original implementation provided an excellent foundation, this fork aims to:
The Disruptor is a high-performance inter-thread messaging library, originally developed by LMAX Exchange for their financial trading platform. It achieves superior performance through:
A fixed-size circular buffer that pre-allocates memory for events:
Cache-line padded atomic counters that track:
Coordinates access to the ring buffer:
Different strategies for thread coordination:
BusySpinWaitStrategy
: Lowest latency, highest CPU usageYieldingWaitStrategy
: Balanced approachSleepingWaitStrategy
: Lowest CPU usage, higher latencyuse disruptor_rs::{DisruptorBuilder, EventHandler};
// Define your event type
#[derive(Default)]
struct MyEvent {
data: i64,
}
// Define your event handler
#[derive(Default)]
struct MyHandler;
impl EventHandler<MyEvent> for MyHandler {
fn on_event(&self, event: &MyEvent, sequence: i64, end_of_batch: bool) {
println!("Processing event: {} at sequence {}", event.data, sequence);
}
}
// Build and run the disruptor
let (executor, producer) = DisruptorBuilder::with_ring_buffer::<MyEvent>(1024)
.with_busy_spin_waiting_strategy()
.with_single_producer_sequencer()
.with_barrier(|scope| {
scope.handle_events(MyHandler::default());
})
.build();
// Start processing
let handle = executor.spawn();
// Produce events
// ...
// Cleanup
producer.drain();
handle.join();
Contributions are welcome! Please feel free to submit a Pull Request. Areas of interest:
This project is licensed under the MIT License - see the LICENSE file for details.