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!
随着Scala 2.9.0的发布,Typesafe栈也被宣布,它结合了Scala语言和Akka框架。现在,尽管Scala的标准库中有参与者,Akka使用了自己的实现。而且,如果我们寻找其他的实现,我们也会发现Lift和Scalaz也有实现!
So, what is the difference between these implementations?
那么,这些实现之间有什么区别呢?
95
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).
这个答案不是我的。它是由维克多·巴朗(Akka fame)在大卫·波拉克的帮助下制作而成的,他的名字是《名利场》(the Lift fame),杰森·佐格(《Scalaz 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 Actors
Scalaz演员
Minimal complexity. Maximal generality, modularity and extensibility.
最小的复杂度。最大通用性、模块化和可扩展性。
Lift 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.
最小化的复杂性,JVM的垃圾收集,而不是担心显式的生命周期,与其他Scala和Java程序一致的错误处理行为,轻量级/小内存占用,邮箱,静态地类似于Scala actor和Erlang actor,高性能。
Scala Actors
Scala的演员
Provide the full Erlang actor model in Scala, lightweight/small memory footprint.
在Scala中提供完整的Erlang actor模型,轻量级/小内存占用。
Akka Actors
Akka演员
Simple and transparently distributable, high performance, lightweight and highly adaptable.
产品分布简单、透明、性能高、重量轻、适应性强。
Scalaz Actors Lift Actors Scala Actors Akka ActorsCurrent stable ver. 5 2.1 2.9.0 0.10Minimum Scala ver. 2.8 2.7.7 2.8Minimum Java ver. 1.5 1.5 1.6
Scalaz Actors Lift Actors Scala Actors Akka ActorsSpawn new actors Yes Yes Yes Yesinside of actorSend messages to Yes Yes Yes Yesknown actor Change behavior Actors are Yes Yes: nested Yes:for next message immutable react/receive become/unbecomeSupervision Not provided No Actor: Yes, Yes(link/trapExit) Reactor: No
If user defines public methods ontheir Actors, are they callable fromthe outside?
如果用户在他们的角色上定义了公共方法,他们是否可以从外部调用?
Actor[A] extends A => ()
LiftActor
, SpecializeLiftActor[T]
Reactor[T]
, Actor extends Reactor[Any]
Actor[Any]
Scalaz Actors Lift Actors Scala Actors Akka ActorsManual start No No Yes YesManual stop No No No YesRestart-on-failure n/a Yes Yes Configurable per actor instanceRestart semantics n/a Rerun actor Restore actor to stable state by re-allocating it and behavior throw away the old instanceRestart configurability n/a n/a X times, X times within Y timeLifecycle hooks provided No lifecycle act preStart, postStop, preRestart, postRestart
Scalaz Actors Lift Actors Scala Actors Akka ActorsFire-forget a ! message actor ! msg actor ! msg actorRef ! msg a(message)Send-receive-reply (see 1) actor !? msg actor !? msg actorRef !! msg actor !! msgSend-receive-future (see 2) actor !! msg actorRef !!! msgSend-result-of- promise(message). future.onComplete( f => to ! f.result )future to(actor)Compose actor with actor comap f No No Nofunction (see 3)
(1) Any function f becomes such an actor:
(1)任何函数f成为这样的一个参与者:
val a: Msg => Promise[Rep] = f.promiseval reply: Rep = a(msg).get
(2) Any function f becomes such an actor:
(2)函数f成为这样的行动者:
val a = f.promiseval replyFuture = a(message)
(3) Contravariant functor: actor comap f
. Also Kleisli composition in Promise
.
(3)逆变函子:演员comap f.也是《应许》中的Kleisli作文。
TBD
TBD
Scalaz Actors Lift Actors Scala Actors Akka Actorsreply-to-sender-in-messagereply-to-message
Supports nested receives?
支持嵌套接收吗?
TBD
TBD
Scalaz Actors Lift Actors Scala Actors Akka ActorsName for Execution MechanismExecution Mechanism isconfigurableExecution Mechanism can bespecified on a per-actor basisLifecycle of Execution Mechanismmust be explicitly managedThread-per-actor executionmechanismEvent-driven execution mechanismMailbox typeSupports transient mailboxesSupports persistent mailboxes
Scalaz Actors Lift Actors Scala Actors Akka ActorsTransparent remote n/a No Yes YesactorsTransport protocol n/a n/a Java Akka Remote Protocol serialization (Protobuf on top of TCP) on top of TCPDynamic clustering n/a n/a n/a In commercial offering
TBD
TBD
Scalaz Actors Lift Actors Scala Actors Akka ActorsDefine an actorCreate an actor instanceStart an actor instanceStop an actor instance
23
scala.actors was the first serious attempt to implement Erlang-style concurrency in Scala that has inspired other library designers for making a better (in some cases) and more performant implementations. The biggest problem (at least for me), is that unlike Erlang processes, complemented with OTP (that allows for building fault-tolerant systems), scala.actors only offer a good foundation, a set of stable primitives that must be used for building a more high-level frameworks - at the end of the day, you’ll have to write your own supervisors, catalogs of actors, finite state machines, etc. on top of actors.
scala。actor是第一个在Scala中实现erlangstyle并发的认真尝试,这激发了其他库设计人员改进(在某些情况下)和提高性能的实现。最大的问题(至少对我来说)是与Erlang进程不同的是,scala与OTP(允许构建容错系统)互补。actor只提供一个良好的基础,一组稳定的原语,必须用于构建更高级的框架——到最后,您必须在actor之上编写自己的管理人员、actor目录、有限状态机等。
And here Akka comes to the rescue, offering a full-featured stack for actor-based development: more idiomatic actors, set of high-level abstractions for coordination (load balancers, actor pools, etc.) and building fault-tolerant systems (supervisors, ported from OTP, etc.), easily configurable schedulers (dispatchers), and so on. Sorry, if I sound rude, but I think, there will be no merge in 2.9.0+ - I’d rather expect Akka actors to gradually replace stdlib implementation.
Akka提供了一个功能齐全的基于角色的开发堆栈:更惯用的角色、协调的高级抽象集(负载平衡器、actor池等)和构建容错系统(监控器、从OTP移植的系统等)、容易配置的调度器(调度程序)等等。对不起,如果我听起来很粗鲁,但是我认为2.9.0+中不会有merge——我宁愿期望Akka actor逐渐取代stdlib实现。
Scalaz. Normally I have this library in the list of dependencies of all my projects, and when, for some reason, I can’t use Akka, non-blocking Scalaz Promises (with all the goodness, like sequence
) combined with the standard actors are saving the day. I never used Scalaz actors as a replacement for scala.actors or Akka, however.
Scalaz。通常,我在所有项目的依赖项列表中都有这个库,而且由于某种原因,我不能使用Akka、无阻塞的Scalaz承诺(尽管有很多好处,比如序列)和标准的参与者结合在一起,节省了时间。我从未使用过Scalaz演员来替代scala。然而,演员或Akka。
2
Actors: Scala 2.10 vs Akka 2.3 vs Lift 2.6 vs Scalaz 7.1
演员:Scala 2.10 vs Akka 2.3 vs Lift 2.6 vs Scalaz 7.1
Test code & results for average latency and throughput on JVM 1.8.0_x.
在JVM 1.8.0_x上测试平均延迟和吞吐量的代码和结果。