nicholassm / disruptor-rs

Low latency inter-thread communication library in Rust inspired by the LMAX Disruptor.
MIT License
618 stars 18 forks source link

Can Consumers be Producers? #6

Closed ghost closed 4 months ago

ghost commented 4 months ago

Not sure if this fit the LMAX framework, but does that make sense to have a consumer that also produce?

Let's say I want to compute statistics on my flow of events, and I want to publish them. If the computation is cpu-bound, it would make sense to isolate it in a thread.

Thanks

nicholassm commented 4 months ago

You can have consumers that also produce. Just not to the same Disruptor - at least in this library's version of the Disruptor. You can think of this as a chain of Disruptors where the consuming thread (or processor) reads data from one Disruptor and publishes to the next in the chain. You can see an example in the test module in lib.rs - it's the test function called pipeline_of_two_spsc_disruptors().

In the Java version you can publish to the same Disruptor you read from - but you have to add logic to skip the events you published yourself.

ghost commented 4 months ago

Very clear, thanks!