Akka 2:如何暂停邮件处理?

编程入门 行业动态 更新时间:2024-10-10 23:24:23
本文介绍了Akka 2:如何暂停邮件处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我使用Akka掌握Actor模型的过程中,弹出了许多问题。这是另一个。假设我们有一个Actor,由于某些业务逻辑或可用资源,该Actor必须在给定时间内停止处理消息。可能发生这种情况的情况可能是:

On my journey to grasp the Actor model using Akka many questions pop up. Here is another one. Say we have an Actor which has to stop processing messages for a given time because of some business logic or available resources. Cases where this might occur could be:

  • 节流。可能有一个Actor发送电子邮件,但仅限于每秒仅发送一封电子邮件。

  • Throttling. There might be an Actor which sends e-mails but is restricted to sent only one e-mail per second.

Actor可能使用某些只能同时处理x消息的系统。这可能是一个具有固定线程池的AsyncHttpClient,我不想使其过载。

The Actor might employ some system which can only process x-messages simultaneity. This could be an AsyncHttpClient which has a fixed thread pool and I do not want to overload it.

某些外部资源不可用,无法处理消息(阅读:外部REST-API)

Some external resource is unavailable which is required to process messages (read: external REST-API)

很有可能我的大脑还没有为演员做好准备,我只是需要提示如何以行动者的方式解决此类问题。

It is highly possible that my brain is not yet actor-ready and I just need a hint how to tackle such problems in an actor-y way.

推荐答案

一般回答

Actor始终以最快的速度处理消息,其中处理意味着将其从邮箱中取出并传递给Actor的行为。因此,行为就是答案所在的地方:在需要非正常动作的时间段内将其更改为更合适的内容。

General Answer

Actors process messages always as fast as they can, where processing means taking them out of their mailbox and passing them into the actor’s behavior. The behavior is thus the place where your answer lies: change it to something more appropriate during periods of time which require non-nominal actions.

如果一个组件正在以比其产生的速率低的速率处理消息,则最终将不得不丢弃消息。要么使用有界邮箱,要么在前面放置一个经理,以跟踪工人的进度,并在压力大的时候进入负面结果答复模式。

If one component is processing messages at a lower rate than they are produced, it will have to drop messages eventually. Either use a bounded mailbox or put a manager in front which keeps track of the worker’s progress and goes into "reply with negative result" mode during periods of stress.

演员想限制自己的输出速率,请使用 context.system.scheduler 。

When an actor wants to throttle its own output rate, use the context.system.scheduler.

这应该回答您的第一个问题两分。

This should answer your first two points.

在无法使用所需资源的期间,根据情况,有两种选择要求:要么在内部对消息进行排队,要么进入乱序答复模式。您还可以混合使用,即在具有特定时间和空间限制的情况下排队,并在达到限制时失败。

During periods where a required resource is unavailable, you have two options depending on the requirements: either queue messages internally, or go into "out-of-order" reply mode. You can also mix, i.e. queue with certain time and space limits and fail when the limits are hit.

始终将参与者所处理的工作单元保持得很小,以使参与者可以在其延迟要求内做出反应。后者可能非常放松(不间断运行数小时)或非常严格(必须以kHz速率处理消息)。

Always keep the units of work processed by actors so small that the actor can react within its latency requirements. The latter could be very relaxed (running for hours uninterruptibly) or very strict (must process messages at kHz rate).

更多推荐

Akka 2:如何暂停邮件处理?

本文发布于:2023-07-15 13:14:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1111423.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:邮件处理   Akka

发布评论

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

>www.elefans.com

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