TPL BufferBlock.ReceiveAsync两次接收相同项目



我有这样的bufferblock设置。

_inputQueue = new BufferBlock<WorkItem>(new DataflowBlockOptions
{
    BoundedCapacity = 1,
    CancellationToken = cancellationToken,
    EnsureOrdered = true
});

有多个消费者从单独的线程调用"提取"函数

public async Task<WorkItem> GetWork()
{
    WorkItem wi;
    try
    {
        wi = await _inputQueue.ReceiveAsync(new TimeSpan(0, 0, 1));
    }
    catch (Exception)
    {
        //since we supplied a timeout, this will be thrown if no items come back
        return null;
    }
    return wi;
}

偶尔,同一工作启动最终会出现在多个消费者中!输入等级中的工作数次数越多",getwork中收到的重复项的机会就越大。我的理解是通过apeiveasync获取的物品是原子的,一旦读取物品,就不会再次阅读。40平行的消费者致电GetWork。

这似乎是服务面料问题。BufferBlock仅排列一次。生产者[分区计数为5的服务面料状态服务实例]在不同分区中两次接收同一项目。必须调查此。

最新更新