简体   繁体   English

如何减慢Akka-Streams的制作人员的速度

[英]How to slow down the producer in Akka-Streams

我试图解决akka-streams的问题。我希望我的初始生产者不断获取队列/ mongodb集合并在配置的时间间隔内完成。实现它的常见做法是什么?

You mean at a fixed time interval? 你的意思是固定的时间间隔?

Start with Source.tick(...).map(loadFromMongo) ? Source.tick(...).map(loadFromMongo)开始Source.tick(...).map(loadFromMongo)

Put in a conflate that drops ticks to prevent querying the db more often than downstream can handle, if that is what you want. 如果这是你想要的,放入一个滴答滴答混合,以防止比下游更频繁地查询数据库。

Additionally, there is a concept called throttle. 此外,还有一个名为油门的概念。 It can be used as follow: 它可以用如下:

Source(...).throttle(50, 1.second, 1, ThrottleMode.Shaping)

It allows you to specify a fetching interval eg above 50 items per second. 它允许您指定一个提取间隔,例如每秒超过50个项目。 An example can be found in the documentation here: http://doc.akka.io/docs/akka/current/scala/stream/stream-quickstart.html#Time-Based_Processing 可以在此处的文档中找到一个示例: http//doc.akka.io/docs/akka/current/scala/stream/stream-quickstart.html#Time-Based_Processing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM