Akka 2中调度程序的区别和使用模式是什么? [英] What are the differences and useage patterns for dispatchers in Akka 2?

查看:116
本文介绍了Akka 2中调度程序的区别和使用模式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解调度程序在以下方面的区别和建议用法Akka 2 。我想我了解 BalancingDispatcher CallingThreadDispatcher 表现正常,但我对分发器 PinnedDispatcher

I've trouble understanding the differences and recommended usage of the dispatchers in Akka 2. I think I understand how the BalancingDispatcher and the CallingThreadDispatcher behave but I have no idea about the Dispatcher and PinnedDispatcher.

我不理解<$ c的概念$ c>可共享性和舱壁

推荐答案

我相信可共享性是指可以共享特定类型调度程序的参与者的数量/类型。我不确定是否要进行散装处理,但我将假定它是指某种演员分区,在该分区中,您只希望一个演员拥有线程。

I believe Sharability refers to the number/type of actors that can share a particular type of dispatcher. I'm not sure on bulkheading, but I'm going to assume it refers to some sort of actor partitioning where you only want one actor to "own" a thread.

这里是各种调度程序类型的代码/ scaladoc注释中的描述。如果需要更多说明,请描述不清楚的地方:

Here are the descriptions from the code/scaladoc comments for the various dispatcher types. If there is more clarification needed, please describe what is unclear:

调度程序:

基于事件的 Dispatcher 将一组Actors绑定到由 BlockingQueue 支持的线程池。

The event-based Dispatcher binds a set of Actors to a thread pool backed up by a BlockingQueue.

BalancingDispatcher:

基于执行者的事件驱动调度程序,将尝试重新分配从忙碌的演员到闲散的演员。假定使用此调度程序的同一实例的所有参与者都可以处理已发送给参与者之一的所有消息。即参与者属于参与者池,并且对于客户端来说,不能保证哪个参与者实例实际处理给定消息。

An executor based event driven dispatcher which will try to redistribute work from busy actors to idle actors. It is assumed that all actors using the same instance of this dispatcher can process all messages that have been sent to one of the actors. I.e. the actors belong to a pool of actors, and to the client there is no guarantee about which actor instance actually processes a given message.

尽管此实现中使用的技术是通常被称为窃取工作,实际的实现方式最好用捐献工作来形容,因为被窃取工作的行为者会主动采取行动。

Although the technique used in this implementation is commonly known as "work stealing", the actual implementation is probably best described as "work donating" because the actor of which work is being stolen takes the initiative.

PinnedDispatcher:

为作为参考传递的每个参与者指定一个唯一线程。通过其messageQueue服务。

Dedicates a unique thread for each actor passed in as reference. Served through its messageQueue.

CallingThreadDispatcher(在akka.testkit中):

分派器,仅在当前线程上运行调用。该分派器不会创建任何新线程,但是可以为同一角色同时从不同线程中使用它。调度策略是在当前线程上运行,除非目标参与者已挂起或已在当前线程上运行(如果它正在其他线程上运行,则该线程将阻塞直到其他调用完成);如果调用未运行,则在调用堆栈之后的活动调用完成后,它将在线程本地队列中排队等待执行。如果仅使用一个线程,这将导致完全确定的执行顺序。

Dispatcher which runs invocations on the current thread only. This dispatcher does not create any new threads, but it can be used from different threads concurrently for the same actor. The dispatch strategy is to run on the current thread unless the target actor is either suspended or already running on the current thread (if it is running on a different thread, then this thread will block until that other invocation is finished); if the invocation is not run, it is queued in a thread-local queue to be executed once the active invocation further up the call stack finishes. This leads to completely deterministic execution order if only one thread is used.

暂停和恢复是一个参与者的全局操作,这意味着它们可能影响不同的线程,从而导致复杂化。如果消息在暂停期间(在本地线程中)排队,则在恢复时运行消息的唯一线程是实际调用resume方法的线程。因此,所有当前未耗尽的线程本地队列(可能的,因为在另一个线程上调用期间可能完全挂起了挂起队列),因此被搜集到当前的线程本地队列中,然后执行该队列。可以从其调用堆栈中暂停演员。

Suspending and resuming are global actions for one actor, meaning they can affect different threads, which leads to complications. If messages are queued (thread-locally) during the suspended period, the only thread to run them upon resume is the thread actually calling the resume method. Hence, all thread-local queues which are not currently being drained (possible, since suspend-queue-resume might happen entirely during an invocation on a different thread) are scooped up into the current thread-local queue which is then executed. It is possible to suspend an actor from within its call stack.

这篇关于Akka 2中调度程序的区别和使用模式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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