Akka:演员当前的邮箱大小或等待处理的邮件数 [英] Akka: actor current mailbox size or number of messages awaiting processing

查看:260
本文介绍了Akka:演员当前的邮箱大小或等待处理的邮件数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出等待参与者处理的待处理队列项目的数量。



我确信必须有一种方法可以处理从参与者上下文或从context.system.mailboxes等引用。



这里是代码示例:

 类SomeActor扩展Actor {
覆盖def接收= {

case ScanExisting => {
val queueSize = context.system.mailboxes ... size?
}


解决方案

Akka中存在这种方法1.x,但在Akka 2.0中已删除。罗兰·库恩(Roland Kuhn)撰写了详细的博客帖子(源自此在Akka用户列表上讨论)解释了此决定的依据。以下摘录概述了查询演员邮箱大小的一些问题:



  • (n)从并发队列中获得一些规模答案的时间,即在您感到最痛苦的时候查询伤害(如果在错误的时刻使用持久的邮箱,甚至可能需要几秒钟的时间)


  • 答案不正确,即在处理此请求的开始或结束时都不需要匹配实际大小


  • 使其变得更正确涉及簿记,这严重限制了可伸缩性


  • ,即使这样,该数量也可能已完全更改。在代码中收到它的时间(例如,您的线程被安排为100ms,并且在这段时间内收到100.000条新消息)。





阅读全文,然后重新考虑获取演员邮箱大小的原因。如果您仍然想要它:


如果无法避免,则可以很容易地编写自己的邮箱实现在akka.dispatch包中,并将簿记代码插入到enqueue()和dequeue()中。然后,您可以使用向下转换(邪恶),也可以在akka.actor.Extension(推荐)中跟踪您的邮箱,以从您的actor内部访问统计信息,并执行必要的操作。



但是,等一下:我是否提到过,用时间戳标记关键延迟(但不是太高频率)的消息并在处理消息时对消息的年龄做出反应甚至更容易吗?



因此,总而言之:虽然仍然有一种获取邮箱大小的方法,但您可能永远不会真正需要它。


如果您希望角色邮箱大小用于监视目的,请查看光弯遥测 Kamon 。另外,Patrik Nordwall编写了要点,当它超出配置的限制时记录邮箱的大小。 p>

I am trying to find out number of pending queue items which awaiting to be processed by the actor.

I am sure there must be a method to which you can refer to from actor context or from context.system.mailboxes etc

Here is code example:

class SomeActor extends Actor {
  override def receive = {

    case ScanExisting => {
      val queueSize = context.system.mailboxes... size ??
}

解决方案

Such a method existed in Akka 1.x but was removed in Akka 2.0. Roland Kuhn wrote a detailed blog post (derived from this discussion on the Akka User List) explaining the rationale behind this decision. Here is an excerpt that outlines some problems with querying an actor's mailbox size:

  • it takes O(n) time to get some size answer from a concurrent queue, i.e. querying hurts when you will feel the pain the most (it might even take several seconds in case of durable mailboxes at the "wrong moment")

  • the answer is not correct, i.e. it does not need to match the real size at either the beginning or the end of processing this request

  • making it "more correct" involves book-keeping which severely limits scalability

  • and even then the number might have changed completely by the time you receive it in your code (e.g. your thread is scheduled out for 100ms and you get 100.000 new messages during that time).

Read the entire post, then reconsider your reason for obtaining the actor's mailbox size. If you still want it:

In case you cannot do without, it is quite easy to write your own mailbox implementation, building on the traits in the akka.dispatch package and inserting book-keeping code into enqueue() and dequeue(). Then you could either use down-casting (evil) or keep track of your mailboxes in an akka.actor.Extension (recommended) to access the stats from within your actor and do whatever is necessary.

But wait: did I mention that it might even be easier to tag latency-critical (but not too high frequency) messages with timestamps and react on the age of a message when processing it?

So, in summary: while there still is a way to get the mailbox size, you will probably never actually need it.

If you want the actor mailbox size for monitoring purposes, look into Lightbend Telemetry or Kamon. Also, Patrik Nordwall wrote a gist that logs the mailbox size when it exceeds a configured limit.

这篇关于Akka:演员当前的邮箱大小或等待处理的邮件数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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