加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 定义了boundedcapacity的贪婪和非贪婪数据流块之间的差异

发布时间:2020-12-15 08:45:46 所属栏目:百科 来源:网络整理
导读:我有一个定义了BoundedCapacity的BatchBlock var _batchBlock = new BatchBlockint(2,new GroupingDataflowBlockOptions {BoundedCapacity = 100 }); 因此,如果队列容量达到100,则该块会推迟收到的每条消息,直到某个地点可用. 在这种情况下,批处理队列被认为
我有一个定义了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

从Dataflow (Task Parallel Library)起

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读