如何使用Akka BoundedMailBox限制生产者

编程入门 行业动态 更新时间:2024-10-11 01:12:46
本文介绍了如何使用Akka BoundedMailBox限制生产者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两个参与者,一个正在制作消息,另一个正在以固定费率使用消息。

是否有可能生产者是否受到消费者BoundedMailBox的限制? (背压)

我的生产者当前是定期排定的(向其发送打勾消息),有没有办法根据消费者邮箱中的可用性来排定它? / p>

由于我不需要响应,因此我正在使用即弃即忘样式(Consumer.tell())。我应该使用其他邮件发送方法吗?

解决方案

仅指定邮箱限制,如果邮箱已满,它似乎会阻塞。 我自己还没有尝试过,但是这个线程中的家伙正在研究行为,他们俩都发现,一旦邮箱达到极限,演员就立即封锁了。

请参阅此处以进行讨论并进行更多此类测试。 groups.google/ forum /?fromgroups =#!topic / akka-user / e0tebq5V4nM

从该主题:

object ProducerConsumer扩展了App { 隐式val系统= ActorSystem( ProducerConsumer) def waitFor(actor:ActorRef){ Await.ready(gracefulStop(actor,5.seconds,5.seconds)} val消费者= system.actorOf(Props [Consumer]。 withRouter(RoundRobinRouter(4))。 withDispatcher( consumer-dispatcher), consumer) for(work<-generateWork)消费者!工作 个消费者! PoisonPill waitFor(消费者) system.shutdown }

application.conf:

消费者调度器{类型= BalancingDispatcher 邮箱容量= 100 }

I have two actors, one is producing messages and the other is consuming the messages at a fixed rate.

Is it possible to have the producer throttled by the consumers BoundedMailBox? (back pressure)

My producer is currently periodically scheduled (sending it a tick message), is there a way to have it scheduled by availability in the consumers mailbox instead?

I am using fire and forget style ( consumer.tell() ) since I do not need a response. Should I be using different message sending approach?

解决方案

Just specify a mailbox limit and it appears to block if the mailbox is full. I haven't tried this myself but the guys in this thread were looking at the behaviour and both found that the actor just blocks once the mailbox is at the limit.

See here for discussion and more testing of this nature. groups.google/forum/?fromgroups=#!topic/akka-user/e0tebq5V4nM

From that thread:

object ProducerConsumer extends App { implicit val system = ActorSystem("ProducerConsumer") def waitFor(actor: ActorRef) { Await.ready(gracefulStop(actor, 5.seconds), 5.seconds) } val consumers = system.actorOf(Props[Consumer]. withRouter(RoundRobinRouter(4)). withDispatcher("consumer-dispatcher"), "consumer") for (work <- generateWork) consumers ! work consumers ! PoisonPill waitFor(consumers) system.shutdown }

application.conf:

consumer-dispatcher { type = BalancingDispatcher mailbox-capacity = 100 }

更多推荐

如何使用Akka BoundedMailBox限制生产者

本文发布于:2023-11-25 11:17:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629531.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:生产者   如何使用   Akka   BoundedMailBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!