如何使用Akka BoundedMailBox限制生产者 [英] How to use Akka BoundedMailBox to throttle a producer

查看:276
本文介绍了如何使用Akka BoundedMailBox限制生产者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



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

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

解决方案

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



请参阅此处以进行讨论并进行更多此类测试。
https://groups.google.com/ 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. https://groups.google.com/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限制生产者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆