Difference between greedy and non-greedy data block with limited boundedness

I have a BatchBlock with BoundedCapacity defined on it

 var _batchBlock = new BatchBlock<int>(2, new GroupingDataflowBlockOptions {BoundedCapacity = 100 }); 

Therefore, if the capacity of the queue reaches 100, the unit defers each received message until a place becomes available. In this case, the packet queue is considered greedy or not greedy?

+6
source share
1 answer

The block is greedy, but not because of how it processes elements above 100, but those below 2. You can set the greedy value to false ( true by default), and then the block will only actually consume objects when there are enough of them to send the package until they are delayed:

 var batchBlock = new BatchBlock<int>(2, new GroupingDataflowBlockOptions { Greedy = false, BoundedCapacity = 100. }); 

The BatchBlock class works in either greedy or non-greedy mode. In hot mode, which is the default, the BatchBlock object receives every message that is offered to it, and distributes the array after receiving the specified number of elements. In non-greedy mode, the BatchBlock object carries all incoming messages until a sufficient number of sources offers messages to the block to form a packet

From Dataflow (parallel task library)

+5
source

Source: https://habr.com/ru/post/976813/


All Articles