AKKA如何为单个actor提供并发性? [英] How AKKA provides concurrency for a single actor?

查看:454
本文介绍了AKKA如何为单个actor提供并发性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已读过



Akka确保每个actor的实例都运行在自己的轻量级线程中,并且其消息一次处理一个。

如果这是AKKA actors按顺序处理其消息的情况,那么AKKA如何为单个Actor提供并发性。



请帮助。

解决方案

Actors是计算的独立代理,每个执行严格依次,但许多actors可以并发执行。你可以查看一个Actor作为线程,它只花费正常线程的0.1%,并且还有一个地址可以发送消息 - 你当然可以在你自己的线程中管理一个队列,并将其用于消息传递但你必须自己实现所有这些。



如果Akka或者Actor Model在这里停止,那么它的确不是很有用。诀窍是给Actors提供稳定的地址(ActorRef),使它们能够通过网络在集群中跨机器边界进行通信。它也允许他们被监督原理的故障处理 - 当正常的线程抛出异常,它只是终止,没有做任何修复它。



这是整个包的封装(通过隐藏ActorRef的所有内容提供),位置透明的基于消息的通信,以及支持故障处理,使Actor模型非常适合表达分布式系统。而且今天有一个分布式系统的许多CPU核心甚至最小的设备。


I have read that

"Akka ensures that each instance of an actor runs in its own lightweight thread and its messages are processed one at a time."

If this is the case that AKKA actors processes its messages sequentially then how AKKA provides concurrency for a single Actor.

Please help.

解决方案

Actors are independent agents of computation, each one is executed strictly sequentially but many actors can be executed concurrently. You can view an Actor as a Thread that costs only about 0.1% of what a normal thread costs and that also has an address to which you can send messages—you can of course manage a queue in your own Thread and use that for message passing but you’d have to implement all that yourself.

If Akka—or the Actor Model—stopped here, then it would indeed not be very useful. The trick is that giving stable addresses (ActorRef) to the Actors enables them to communicate even across machine boundaries, over a network, in a cluster. It also allows them to be supervised for principled failure handling—when a normal Thread throws an exception it simply terminates and nothing is done to fix it.

It is this whole package of encapsulation (provided by hiding everything behind ActorRef), message-based communication that is location transparent, and support for failure handling that makes the Actor Model a perfect fit for expressing distributed systems. And today there is a distributed system of many CPU cores within even the smallest devices.

这篇关于AKKA如何为单个actor提供并发性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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