随着Scala 2.9.0的发布,Typesafe Stack也被宣布,它结合了Scala语言和Akka框架。现在,虽然Scala在其标准库中有演员,但Akka使用自己的实现。而且,如果我们寻找其他实现,我们也会发现Lift和Scalaz也有实现!
那么,这些实现之间有什么区别?
答案 0 :(得分:95)
这个答案不是我的。 It was produced由Viktor Klang(Akka成名)在David Pollak(电梯名望),Jason Zaugg(Scalaz成名),Philipp Haller(Scala Actors成名)的帮助下。
我在这里所做的就是格式化它(如果Stack Overflow支持表格会更容易)。
如果我有更多时间,我会在以后填写几个地方。
Scalaz Actors
最小的复杂性。最大的通用性,模块性和可扩展性。
举起演员
最小的复杂性,JVM的垃圾收集,而不是担心显式的生命周期,错误处理行为与其他Scala& Java程序,轻量级/小内存占用,邮箱,静态类似于Scala Actors和Erlang actor,性能卓越。
Scala Actors
在Scala中提供完整的Erlang actor模型,轻量级/小内存占用。
Akka Actors
简单,透明,可分发,高性能,轻量级,适应性强。
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
如果用户定义公共方法 他们的演员,他们可以赎罪 在外面?
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
(2)任何函数f都成为这样一个角色:
val a = f.promise
val replyFuture = a(message)
(3)逆变函子:actor comap f
。还有Promise
中的Kleisli作文。
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
答案 1 :(得分:23)
scala.actors 是第一次在Scala中实现Erlang风格的并发性的重要尝试,它激发了其他库设计人员在更好(在某些情况下)和更高性能的实现方面的启发。最大的问题(至少对我而言)是,与Erlang进程不同,补充了 OTP (允许构建容错系统), scala.actors 仅提供良好的基础,必须用于构建更高级别框架的一组稳定原语 - 在一天结束时,您必须编写自己的主管,演员目录,有限状态机等等。演员。
这里 Akka 来救援,为基于演员的开发提供全功能的堆栈:更多惯用的演员,协调的高级抽象集(负载均衡器,演员)池,等)和构建容错系统(主管,从 OTP 等移植),易于配置的调度程序(调度程序)等。对不起,如果我听起来很粗鲁,但我认为, 2.9.0 + 中没有合并 - 我宁愿期望 Akka 演员逐渐取代stdlib实现。< / p>
<强> Scalaz 即可。通常我在所有项目的依赖项列表中都有这个库,当出于某种原因,我不能使用 Akka ,非阻塞 Scalaz Promises (与所有的善良,如sequence
)与标准演员相结合,正在挽救这一天。但我从未使用 Scalaz 演员代替 scala.actors 或 Akka 。
答案 2 :(得分:2)