Akka参与者如何在基础线程上实现? [英] How are akka actors implemented on underlying threads?

查看:95
本文介绍了Akka参与者如何在基础线程上实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于执行上下文和线程池,如何在其上计划/实现akka/scala actor?

Given an execution context and a thread pool, how are akka/scala actors scheduled/implemented on that?

推荐答案

我很长时间以来一直对此主题感到困惑.我假设线程和参与者之间存在某种关系.每个演员都有一个主持它的线程,所以我在想.在协作多任务模式下工作的每个线程可能都有几个参与者.

I was confused with this topic for a long time. I assumed that there is some relation between threads and actors. For each actor there is a thread that hosts it, so I was thinking. Probably there are several actors for each thread that works in cooperative multitasking mode.

文档侧重于用法,并简要介绍了内部体系结构.您只需要扩展Actor类,您就可以成为演员.因此,我试图猜测如何做到这一点.并想象每个Actor都有生命周期.诸如异步等待消息队列之类的东西.然后处理消息.开始吧.

Documentation is focused on usage and cover internal architecture lightly. You just should extend Actor class and you would get working actor. So I tried to guess how can this be done. And imagined that each Actor has life-cycle. Something like wait asynchronously for message queue. Then process message. Go to start.

那是完全错误的假设.尽管文档中说演员生命周期",但这并不意味着Actor生命周期.提到的 Actor 是一个概念,而不是实现Actor类的实际对象.该对象位于Java堆中是被动的.

That was totally false assumption. Although the documentation says "actor life-cycle" it does not mean Actor life-cycle. Actor mentioned is a conception rather than actual object implementing the Actor class. The object resides passive in the java heap.

要使生活更加生动,就需要涉及一群真正的工人的协调工作.它的核心是 dispatcher .它包含所有参与者,线程和消息.当资源可用并且有消息可用于处理 dispatcher 激活时.它使用适当的Actor对象,将其receive方法包装在runnable中,并将其传递给备用线程.因此,仅从actor系统偶尔调用方法的对象就没有生命周期.

To breath life into the conception coordinated work involving bunch of real workers is needed. And the heart of it is dispatcher. It holds all actors, threads and messages. And when resources become available and there are message available for processing the dispatcher activates. It takes appropriate Actor object, wraps its receive method in runnable and pass it to a spare thread. So there is no life-cycle for the object only occasional method calls from the actor system.

当您想到它时,它比我早先设想的方案有意义得多.但是,我很难从可用的文档中推断出它.它是由经验丰富的并发程序员编写的.区分演员类和背后的 actor 概念的区别.他们知道actor系统的 dispatcher 就像OS的任务调度程序一样.因此,他们很快找到了要点,并描述了各种口味,并实现了每个人都熟悉的概念.

When you think of it, it makes much more sense than scheme I assumed early. But it was hard for me to deduce it from available documentation. It was written by seasoned concurrency programmers. The distinguish holding the actor class from actor conception behind it. They know that dispatcher for an actor system is like task scheduler for an OS. So they quickly get to the point and describes various flavours and realization of the conception assumed be familiar to everyone.

但是对于新手来说,这并不容易.他不了解参与者系统环境中的 dispatcher模式.我尝试用Google搜索调度程序模式",结果显示它仅与参与者系统定义无关.

But that is not so easy for a newbie. He has no acquaintance of the dispatcher pattern in actor systems context. I tried to google "dispatcher pattern" and it showed only non-relevant to an actor system definitions.

我很容易找到双重派发,多次派发和其他OOP主题.我发现了与akka的路由器类似的东西消息调度程序.演员消息调度程序可能有不错的描述,但并不是那么容易找到.

I've found easily double dispatch, multi-dispatch and other OOP topics. I've found something similar to akka's routers message dispatcher. There is probably decent description for actor message dispatchers but it not so easy to find.

我希望我消除了误会.

这篇关于Akka参与者如何在基础线程上实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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