multiqueue icon indicating copy to clipboard operation
multiqueue copied to clipboard

Clarification on the nature of "starving"

Open dylanede opened this issue 7 years ago • 2 comments

The examples mention that unsubscribing from certain streams is necessary in order to stop other streams from "starving". It would be helpful if the documentation could explain what the conditions that lead to starvation are, as there doesn't appear to be any other mention of it.

dylanede avatar Aug 21 '17 14:08 dylanede

As I understand, in the current API:

let (send, recv) = multiqueue::broadcast_queue(4);
for i in 0..2 { // or n
    let cur_recv = recv.add_stream();
    thread::spawn(move || {
        for val in cur_recv {
            println!("Stream {} got {}", i, val);
        }
    });
}

The recv itself is a stream - a reader with cursor into the queue (each cur_recv in the loop is also an another stream), so if recv not moving its cursor (by reading/iterating), the queue will not accept more message if it is already at its limit, thus, prevent producer from producing.

And @schets addressed this API problem in this: https://github.com/schets/multiqueue/issues/15

unrealhoang avatar Aug 29 '17 18:08 unrealhoang

The issue is caused since multiqueue currently stalls the producer when a consumer is behind. I'm looking into an api that allows consumers to remain unmonitored by the producer and error when they are overwritten. I'll update the docs with a good example when I have some time

schets avatar Oct 25 '17 02:10 schets