Question

I've got some questions about Bufferblock and Dataflow processing in general. Suppose I have a set up something like the following (I copied this code from another question, but it serves to illustrate)

var forwarder = new BufferBlock<SomeType>();
forwarder.LinkTo(target1, item => matchesTarget1(item));
forwarder.LinkTo(target2, item => matchesTarget2(item));
forwarder.LinkTo(DataflowBlock.NullTarget<SomeType>());

Q1. Assuming no concurrency settings, if I add 1000 items which match Target1 to the forwarder, are they all instantly posted to target1? i.e. Does the queuing occur within target1, and so the forwarder (BufferBlock) is now empty? I believe yes, which means that the buffer instantly empties itself? Or does target1 refuse things when it decides it can't cope with any more?

Q2. Assuming I set maxdegreeofparallelism of target1 to, say, 4, I believe this will mean that things will stay in the buffer until the target is capable of processing them. But does that mean that, if my queue looked like this, for example:

target1Item

target1Item

target1Item

target1Item

target1Item

target2Item

target2Item

target2Item

Then target2 would not be offered anything to do at all until all 5 target1Items had been accepted. If target1 is a slow process, that means that target2 may sit around doing nothing when it could be making itself useful.

I've read and read about this, but I can't find anything which definitively answers this. Any help would be greatly appreciated. Thanks

Was it helpful?

Solution

a1. That depends on the Bounded Capacity of the target block. The default is -1 (unbounded), so yes, the buffer will empty itself and move all items to target1. If it had a capacity set, and it was reached then the rest of the items would have stayed in the buffer.

a2. AFAIK If we assume that the targets' capacities are unbounded, then all the items will move from the buffer to the target1 and target2. Setting the maxdegreeofparallelism on target1 only allows multiple items to be processed in parallel.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top