I have a BatchBlock
with BoundedCapacity
defined on it
var _batchBlock = new BatchBlock<int>(2, new GroupingDataflowBlockOptions
{BoundedCapacity = 100 });
So if the queue capacity reaches a 100 the block postpones every message received until a spot becomes available. In this case is the batch queue considered greedy or non-greedy ?
The block is greedy, but not because of how it handles the items above 100, but the ones below 2. You can set the greedy value to false
(true
is the default) and then the block would only actually consume items when there are enough to send a batch, until then they are postponed:
var batchBlock = new BatchBlock<int>(2, new GroupingDataflowBlockOptions
{
Greedy = false,
BoundedCapacity = 100.
});
The BatchBlock class operates in either greedy or non-greedy mode. In greedy mode, which is the default, a BatchBlock object accepts every message that it is offered and propagates out an array after it receives the specified count of elements. In non-greedy mode, a BatchBlock object postpones all incoming messages until enough sources have offered messages to the block to form a batch
From Dataflow (Task Parallel Library)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With