`Source.queue` 中的 `BoundedSourceQueue` 是否适合并发生产者?

Is `BoundedSourceQueue` from `Source.queue` ok with concurrent producers?

Source.queue 最近在旧版本中添加了一个 overload which specializes to OverflowStrategy.dropNew and avoids the async mechanism. The result of materializing this is a BoundedSourceQueue[T] (compared to SourceQueueWithComplete[T])。 Source.queueSourceQueueWithComplete 变体的文档清楚地表明物化队列应该被任意数量的并发生产者使用:

The materialized SourceQueue may be used by up to maxConcurrentOffers concurrent producers.

BoundedSourceQueue 的文档对此没有任何说明。 是否为 BoundedSourceQueue 取消了此限制?它可以被任意数量的并发生产者使用吗?

从技术上讲,如果 OverflowStrategy.dropNew 生效,SourceQueueWithComplete 变体没有 maxConcurrentOffers 限制。

但是,由于向 SourceQueueWithComplete 提供元素的结果是异步通信的,这确实意味着如果生产者生产的速度快于处理未来的速度,它可能会占用内存。异步消除了背压,毕竟除非有其他机制重新引入它。

因为当策略是 dropNew 时,可以立即知道元素被丢弃,提供的结果可以同步通信(即阻塞生产者直到它 handles/throws 离开结果).这允许有任意多的生产者而没有 OOM 风险。出于这个原因,如果使用 dropNew 策略,建议使用 BoundedSourceQueue 版本(即,如果正在使用其他策略,则仅使用 SourceQueueWithComplete),随着负载的增加,建议会越来越强.

是的,运行 线程的数量是 BoundedSourceQueue 变体的并发生产者数量的限制。