Scala中多个Actor的实现有何不同? [英] How are the multiple Actors implementation in Scala different?

查看:64
本文介绍了Scala中多个Actor的实现有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着Scala 2.9.0的发布,还宣布了Typesafe Stack,它结合了Scala语言和Akka框架。现在,尽管Scala在其标准库中有参与者,但Akka使用其自己的实现。而且,如果我们寻找其他实现,我们还会发现Lift和Scalaz也有实现!

With the release of Scala 2.9.0, the Typesafe Stack was also announced, which combines the Scala language with the Akka framework. Now, though Scala has actors in its standard library, Akka uses its own implementation. And, if we look for other implementations, we'll also find that Lift and Scalaz have implementations too!

那么,这些实现之间有什么区别?

So, what is the difference between these implementations?

推荐答案

这个答案不是我的。 它是由大卫·波拉克(David Pollak)制作(阿卡名望) (是Lift的成名),Jason Zaugg(是Scalaz的成名),Philipp Haller(是Scala Actors的成名)。

This answer isn't really mine. It was produced by Viktor Klang (of Akka fame) with the help of David Pollak (of Lift fame), Jason Zaugg (of Scalaz fame), Philipp Haller (of Scala Actors fame).

我在这里所做的就是格式化它(如果堆栈溢出支持的表会更容易)。

All I'm doing here is formatting it (which would be easier if Stack Overflow supported tables).

当我有更多时间时,我会在后面填写一些地方。

There are a few places I'll fill later when I have more time.


  • Scalaz演员

  • Scalaz Actors

最小复杂。最大的通用性,模块化和可扩展性。

Minimal complexity. Maximal generality, modularity and extensibility.

升降器

最小的复杂度,JVM的垃圾回收,而不用担心显式的生命周期,与其他Scala& amp;一致的错误处理行为Java程序,轻量级/小内存占用,邮箱,静态类似于Scala Actors和Erlang actors,高性能。

Minimal complexity, Garbage Collection by JVM rather than worrying about an explicit lifecycle, error handling behavior consistent with other Scala & Java programs, lightweight/small memory footprint, mailbox, statically similar to Scala Actors and Erlang actors, high performance.

Scala Actors

Scala Actors

在Scala中提供完整的Erlang actor模型,轻巧/小内存占用。

Provide the full Erlang actor model in Scala, lightweight/small memory footprint.

Akka演员

简单透明的分布,高性能,轻便和高度适应性。 p>

Simple and transparently distributable, high performance, lightweight and highly adaptable.


                    Scalaz Actors   Lift Actors     Scala Actors    Akka Actors
Current stable ver. 5               2.1             2.9.0           0.10
Minimum Scala ver.  2.8             2.7.7                           2.8
Minimum Java ver.                   1.5             1.5             1.6



演员模型支持



Actor Model Support


                    Scalaz Actors   Lift Actors     Scala Actors    Akka Actors
Spawn new actors    Yes             Yes             Yes             Yes
inside of actor
Send messages to    Yes             Yes             Yes             Yes
known actor 
Change behavior     Actors are      Yes             Yes: nested     Yes:
for next message    immutable                       react/receive   become/unbecome
Supervision         Not provided    No              Actor: Yes,     Yes
(link/trapExit)                                     Reactor: No



状态隔离级别



如果用户在其Actor的
上定义了公共方法,

Level of state isolation

If user defines public methods on their Actors, are they callable from the outside?


  • Scalaz演员:n / a。演员是密封的特质。

  • 举足轻重的演员:是

  • scala演员:是

  • 阿卡演员:不,演员实例被屏蔽在ActorRef后面。

  • Scalaz Actors: n/a. Actor is a sealed trait.
  • Lift Actors: Yes
  • Scala Actors: Yes
  • Akka Actors: No, actor instance is shielded behind an ActorRef.

  • Scalaz演员:演员[A]扩展了A => ()

  • 升降演员:升降演员 SpecializeLiftActor [T]

  • Scala Actor: Reactor [T] Actor扩展Reactor [Any]

  • Akka演员: Actor [Any]

  • Scalaz Actors: Actor[A] extends A => ()
  • Lift Actors: LiftActor, SpecializeLiftActor[T]
  • Scala Actors: Reactor[T], Actor extends Reactor[Any]
  • Akka Actors: Actor[Any]

                    Scalaz Actors   Lift Actors     Scala Actors    Akka Actors
Manual start        No              No              Yes             Yes
Manual stop         No              No              No              Yes
Restart-on-failure  n/a             Yes             Yes             Configurable per actor instance
Restart semantics                   n/a             Rerun actor     Restore actor to stable state by re-allocating it and
                                                    behavior        throw away the old instance
Restart configurability             n/a             n/a             X times, X times within Y time
Lifecycle hooks provided            No lifecycle    act             preStart, postStop, preRestart, postRestart



消息发送模式



Message send modes


                    Scalaz Actors   Lift Actors     Scala Actors    Akka Actors
Fire-forget         a ! message     actor ! msg     actor ! msg     actorRef ! msg
                    a(message)
Send-receive-reply  (see 1)         actor !? msg    actor !? msg    actorRef !! msg
                                    actor !! msg
Send-receive-future (see 2)                         actor !! msg    actorRef !!! msg
Send-result-of-     promise(message).                               future.onComplete( f => to ! f.result )
future              to(actor)
Compose actor with  actor comap f   No              No              No
function            (see 3)

(1)任何函数f都会成为这样的参与者:

(1) Any function f becomes such an actor:

val a: Msg => Promise[Rep] = f.promise
val reply: Rep = a(msg).get

(2)任何函数f都会成为这样的参与者:

(2) Any function f becomes such an actor:

val a = f.promise
val replyFuture = a(message)

(3)逆函子: actor comap f 。也是 Promise 中的Kleisli组成。

(3) Contravariant functor: actor comap f. Also Kleisli composition in Promise.

TBD


                    Scalaz Actors   Lift Actors     Scala Actors    Akka Actors
reply-to-sender-in-message
reply-to-message



消息处理



是否支持嵌套接收?

Message processing

Supports nested receives?


  • Scalaz演员:-

  • 升降演员:是(带有一点手工编码)。

  • Scala Actor:是的,基于线程的接收和基于事件的反应。

  • Akka Actors:否,嵌套接收会导致内存泄漏和降级性能。

  • Scalaz Actors: --
  • Lift Actors: Yes (with a little hand coding).
  • Scala Actors: Yes, both thread-based receive and event-based react.
  • Akka Actors: No, nesting receives can lead to memory leaks and degraded performance over time.

TBD


                    Scalaz Actors   Lift Actors     Scala Actors    Akka Actors
Name for Execution Mechanism
Execution Mechanism is
configurable
Execution Mechanism can be
specified on a per-actor basis
Lifecycle of Execution Mechanism
must be explicitly managed
Thread-per-actor execution
mechanism
Event-driven execution mechanism
Mailbox type
Supports transient mailboxes
Supports persistent mailboxes



分发/远程执行者



Distribution/Remote Actors


                    Scalaz Actors   Lift Actors     Scala Actors    Akka Actors
Transparent remote  n/a             No              Yes             Yes
actors
Transport protocol  n/a             n/a             Java            Akka Remote Protocol
                                                    serialization   (Protobuf on top of TCP)
                                                    on top of TCP
Dynamic clustering  n/a             n/a             n/a             In commercial offering



操作方法



TBD

Howtos

TBD


                    Scalaz Actors   Lift Actors     Scala Actors    Akka Actors
Define an actor
Create an actor instance
Start an actor instance
Stop an actor instance

这篇关于Scala中多个Actor的实现有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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