随着Scala 2.9.0的发布,Typesafe Stack也被宣布,它结合了Scala语言和Akka框架.现在,虽然Scala在其标准库中有演员,但Akka使用自己的实现.而且,如果我们寻找其他实现,我们也会发现Lift和Scalaz也有实现!
那么,这些实现之间有什么区别?
Dan*_*ral 95
这个答案不是我的.它由Viktor Klang(Akka成名)在David Pollak(电梯名望),Jason Zaugg(Scalaz成名),Philipp Haller(Scala Actors成名)的帮助下制作.
我在这里所做的就是格式化它(如果Stack Overflow支持表格会更容易).
当我有更多时间时,我会稍后填写几个地方.
Scalaz演员
最小的复杂性.最大的通用性,模块性和可扩展性.
举起演员
最小的复杂性,JVM的垃圾收集,而不是担心明确的生命周期,与其他Scala和Java程序一致的错误处理行为,轻量/小内存占用,邮箱,静态类似于Scala Actors和Erlang actor,高性能.
斯卡拉演员
在Scala中提供完整的Erlang actor模型,轻量级/小内存占用.
Akka演员
简单,透明,可分配,高性能,轻量级和高适应性.
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
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
如果用户在其Actors上定义公共方法,它们是否可以从外部调用?
Actor[A] extends A => ()
LiftActor
,SpecializeLiftActor[T]
Reactor[T]
,Actor extends Reactor[Any]
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
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都成为这样一个角色:
val a: Msg => Promise[Rep] = f.promise
val reply: Rep = a(msg).get
Run Code Online (Sandbox Code Playgroud)
(2)任何函数f都成为这样一个角色:
val a = f.promise
val replyFuture = a(message)
Run Code Online (Sandbox Code Playgroud)
(3)逆变函子:actor comap f
.也是Kleisli的成分Promise
.
TBD
Scalaz Actors Lift Actors Scala Actors Akka Actors reply-to-sender-in-message reply-to-message
支持嵌套接收?
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
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
Scalaz Actors Lift Actors Scala Actors Akka Actors Define an actor Create an actor instance Start an actor instance Stop an actor instance
Vas*_*iuk 23
scala.actors是第一个在Scala中实现Erlang风格的并发性的重要尝试,它激发了其他库设计者在更好(在某些情况下)和更高性能的实现.最大的问题(至少对我而言)是,与Erlang进程不同,补充了OTP(允许构建容错系统),scala.actors只提供了一个良好的基础,一组必须用于构建的稳定基元更高层次的框架 - 在一天结束时,你必须在演员之上编写自己的主管,演员目录,有限状态机等.
在这里,Akka开始拯救,为基于演员的开发提供了一个功能齐全的堆栈:更多惯用的角色,一套用于协调的高级抽象(负载平衡器,演员池等)和构建容错系统(主管) ,从OTP移植等),易于配置的调度程序(调度程序)等.对不起,如果我听起来很粗鲁,但我认为,2.9.0+中不会合并- 我宁愿期待Akka演员逐渐取代stdlib实现.
斯卡拉兹.通常我在所有项目的依赖项列表中都有这个库,当由于某种原因,我无法使用Akka时,非阻塞的Scalaz Promises(具有所有优点,如果sequence
)与标准actor一起保存天.但是,我从未使用Scalaz actor代替scala.actors或Akka.