我有一个定义了BoundedCapacity的BatchBlock
var _batchBlock = new BatchBlock<int>(2,new GroupingDataflowBlockOptions {BoundedCapacity = 100 });
因此,如果队列容量达到100,则该块会推迟收到的每条消息,直到某个地点可用.
在这种情况下,批处理队列被认为是贪婪还是非贪婪?
解决方法
该块是贪婪的,但不是因为它如何处理100以上的项目,而是因为2以下的项目.您可以将贪婪值设置为false(默认值为true)然后块只会在有足够数量时实际使用项目发送一批,直到那时它们被推迟:
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。