简体   繁体   English

Akka 演员之间的长时间延迟

[英]Long delay between Akka actors

I'm consistently seeing very long delays (60+ seconds) between two actors, from the time at which the first actor sends a message for the second, and when the second actor's onReceive method is actually called with the message.我一直看到两个演员之间的延迟很长(60 秒以上),从第一个演员为第二个演员发送消息的时间到第二个演员的onReceive方法实际使用消息调用时。 What kinds of things can I look for to debug this problem?我可以寻找哪些东西来调试这个问题?

Details细节

Each instance of ActorA is sending one message for ActorB with ActorRef.tell(Object, ActorRef) . ActorA 的每个实例都使用ActorRef.tell(Object, ActorRef)向 ActorB 发送一条消息。 I collect a millisecond timestamp (with System.currentTimeMillis() ) right after calling the tell method in ActorA, and getting another one at the start of ActorB's onReceive(Object) .在调用 ActorA 中的tell方法后,我立即收集了一个毫秒时间戳(使用System.currentTimeMillis() ),并在 ActorB 的onReceive(Object)开始处获取另一个时间戳。 The interval between these timestamps is consistently 60 seconds or more.这些时间戳之间的间隔始终为 60 秒或更长。 Specifically, when plotted over time, this interval follows a rough saw tooth pattern that ranges from more 60 second to almost 120 seconds, as shown in the graph below.具体而言,当随时间绘制时,此间隔遵循粗略的锯齿图案,范围从超过 60 秒到几乎 120 秒,如下图所示。

在此处输入图片说明

These actors are early in the data flow of the system, there are several other actors that follow after ActorB.这些actor在系统数据流的早期,在ActorB之后还有其他几个actor。 This large gap only occurs between these two specific actors, the gaps between other pairs of adjacent actors is typically less than a millisecond, occassionally a few tens of milliseconds.这种大的差距只发生在这两个特定的演员之间,其他相邻演员之间的差距通常小于一毫秒,偶尔几十毫秒。 Additionally, the actual time spent inside any given actor is never more than a second.此外,在任何给定actor中花费的实际时间绝不会超过一秒。

Generally, each actor in the system only passes a single message to another actor.通常,系统中的每个参与者只将一条消息传递给另一个参与者。 One of the actors (subsequent to ActorB) sends a single message to each of a few different actors, and a small percentage (less than 0.1%) of the time, certain actors will send multiple messages to the same subsequent actor (ie, multiple instances of the subsequent actor will be demanded).其中一个actor(在ActorB之后)向几个不同的actor中的每一个发送一条消息,在一小部分(小于0.1%)的时间里,某些actor会向同一个后续actor(即多个actor)发送多条消息将要求后续参与者的实例)。 When this occurs, the number of multiple messages is typically on the order of a dozen or less.发生这种情况时,多条消息的数量通常在十几个或更少的数量级。

Can this be explained (explicitely) by the normal reactive nature of Akka?这可以通过 Akka 的正常反应性质(明确地)解释吗? Does it indicate a problem with the way work is distributed or the way the actors are configured?它是否表明工作分配方式或参与者的配置方式存在问题? Is there something that can explicitly block a particular actor from spinning up?有什么可以明确阻止特定演员旋转的东西吗? What other information should I collect or look at to understand the source of this, or to understand whether or not it is actually a problem?我应该收集或查看哪些其他信息以了解其来源,或了解这是否确实是一个问题?

You have a limited thread pool.您的线程池有限。 If your Actors block, they still take up space in the thread pool.如果您的 Actor 阻塞,它们仍会占用线程池中的空间。 New threads will not be created if your thread pool is saturated.如果您的线程池已饱和,则不会创建新线程。

You may want to configure core-pool-size-factor , core-pool-size-min , and core-pool-size-max .您可能需要配置core-pool-size-factorcore-pool-size-mincore-pool-size-max

If you expect certain actions to block, you can instead wrap them in Future { blocking { ... } } and register a callback.如果您希望某些操作被阻止,您可以将它们包装在Future { blocking { ... } }并注册一个回调。 But it's better to use asynchronous, non-blocking calls.但是最好使用异步的、非阻塞的调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM