Skip to main content

MpmcDisruptor

Struct MpmcDisruptor 

Source
pub struct MpmcDisruptor;
Expand description

Builder + constructor. Use MpmcDisruptor::with_consumers.

Implementations§

Source§

impl MpmcDisruptor

Source

pub fn with_consumers<T: Send + 'static>( requested_capacity: usize, consumer_count: usize, ) -> (DisruptorProducer<T>, Vec<DisruptorConsumer<T>>)

Build a disruptor with consumer_count consumers and at least requested_capacity slots (rounded up to power of two, floor 2). All consumers see every published item (broadcast); for work-stealing semantics use MpscFanIn with a single consumer per producer instead.

Examples found in repository?
examples/perf_features.rs (line 411)
410        fn disruptor(cap: usize) -> (DisruptorProducer<u64>, DisruptorConsumer<u64>) {
411            let (p, mut cs) = MpmcDisruptor::with_consumers::<u64>(cap, CONSUMERS);
412            let c = cs.remove(0);
413            for i in 0..cap / 2 {
414                let _ = p.try_publish(i as u64);
415            }
416            (p, c)
417        }
More examples
Hide additional examples
examples/sample_app.rs (line 231)
226fn broadcast_to_strategy_and_risk() {
227    use subms_spsc_ring_buffer::MpmcDisruptor;
228
229    println!("\n== mpmc-disruptor: broadcast to strategy + risk ==");
230    let n = 8u64;
231    let (producer, mut consumers) = MpmcDisruptor::with_consumers::<Tick>(16, 2);
232    let (strategy, rest) = consumers.split_at_mut(1);
233    let strategy = &mut strategy[0];
234    let risk = &mut rest[0];
235
236    // Small and single-threaded so the tour self-verifies; the threaded
237    // broadcast path is pinned in the tests.
238    let mut published = 0u64;
239    let mut strat_seen = Vec::new();
240    let mut risk_seen = Vec::new();
241    while published < n {
242        while published < n
243            && producer
244                .try_publish(Tick {
245                    seq: published,
246                    price_cents: 50_000,
247                })
248                .is_ok()
249        {
250            published += 1;
251        }
252        while let Some(t) = strategy.try_consume() {
253            strat_seen.push(t.seq);
254        }
255        while let Some(t) = risk.try_consume() {
256            risk_seen.push(t.seq);
257        }
258    }
259    println!(
260        "  published {published}; strategy saw {}, risk saw {}",
261        strat_seen.len(),
262        risk_seen.len()
263    );
264    let expected: Vec<u64> = (0..n).collect();
265    assert_eq!(strat_seen, expected, "strategy sees every tick");
266    assert_eq!(risk_seen, expected, "risk monitor sees every tick too");
267}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.