如何处理与演员爆发? [英] How to handle bursts with Actors?

查看:161
本文介绍了如何处理与演员爆发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个actor,它每秒处理 X 个请求。这是平均确定,但有时有突发和客户端发送 Y> X 每秒请求数。

Suppose I have an actor, which handles X requests per second. It is ok in average but sometimes there are bursts and clients send Y > X requests per second. Suppose also that all requests have timeouts so they cannot wait in queue forever.

假设我们在Scala和 Akka中编程什么是最佳实践/设计模式,使演员处理这些突发?有没有处理突发的代码示例?

Assuming we program in Scala and Akka what are the best practices/design patterns to make the actor handle those bursts? Are there any code examples, which handle bursts?

推荐答案

只要您的机器可以处理增加的负载(即有足够的CPU),那么我建议将 Actor 使用路由器。听起来像你的例子,动态调整大小的路由器可能是最合适的,但即使是标准的Round Robin或最小的邮箱也许就够了。下面是Akka文档中的路由器部分的链接。我希望这有助于。

As long as your machine can handle the increased load (i.e. has enough CPUs), then I would suggest pooling the Actor using a Router. It sounds like from your example, a dynamically resizing router might be the best fit, but even a standard Round Robin or Smallest Mailbox might be enough. Below is the link for the routers section from the Akka documentation. I hope this helps.

http://doc.akka.io/docs/akka/2.1.2/scala/routing.html

您也可以考虑在多个节点上分配actor,但这可能对您的场景过度。如果你对这种方法有兴趣,让我知道,我可以发布更多的上下文这样做。

You could also consider distributing the actor across multiple nodes, but that might be overkill for your scenario. If you have interest in that approach, let me know and I can post more context on doing that.

现在至于做什么后,系统仍然积压,这是真的取决于你,但这里有几个选项。如果你可以处理由于突然的延迟偶尔增加,然后什么也不做。演员邮箱只会得到一点备份,但他们会清除,一旦爆裂缓解。如果不是,那么问题是如何处理传入的消息,当演员积压。如果您想在这种情况下快速失败,并且不接受您可能想使用有界邮箱( http://doc.akka.io/docs/akka/2.1.2/scala/dispatchers.html )。当邮箱达到它的大小限制,并且不能再排队消息时,呼叫者将收到发送消息的失败(我想)。不是真棒,但至少会导致系统稳定更快。

Now as far as what to do when after you pool the actors but the system still is getting backlogged, that's really up to you, but here are a few options. If you can handle the occasional increases in latency due to bursting, then do nothing. The actors mailboxes will just get a little backed up but they will clear as soon as the burst eases off. If not, then the question is how to handle incoming messages when the actors are backlogged. If you want to fast fail in that situation and not accept the message you might want to look into using a bounded mailbox (http://doc.akka.io/docs/akka/2.1.2/scala/dispatchers.html). When the mailbox reaches it's size limit and can no longer queue messages, the caller will get a failure sending the message (I think). Not awesome, but at least will lead to the system stabilizing faster.

我假设你在做 ask(?)(即请求/响应),所以当你这样做时,你会得到未来。如果它没有及时收到响应,那么未来将超时(具有隐式定义的超时值),因此在突发期间,将刚开始计时;他们不会永远呆在那里。

I assume you are doing ask (?) (i.e. request/response), so when you do that, you get a Future. That Future will time out (with an implicitly defined timeout value) if it does not receive a response in time, so during a burst, Futures attached to the calls into the backlogged actors will just start timing out; they will not be stuck there forever.

这篇关于如何处理与演员爆发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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