热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Scala中的多角色实现有何不同?-HowarethemultipleActorsimplementationinScaladifferent?

WiththereleaseofScala2.9.0,theTypesafeStackwasalsoannounced,whichcombinestheScalalan

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?

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

3 个解决方案

#1


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.

有几个地方等我有更多的时间再补上。

Design Philosophy

  • 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.

    产品分布简单、透明、性能高、重量轻、适应性强。

Versioning

                    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

Actor Model Support

                    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

Level of state isolation

If user defines public methods ontheir Actors, are they callable fromthe outside?

如果用户在他们的角色上定义了公共方法,他们是否可以从外部调用?

  • Scalaz Actors: n/a. Actor is a sealed trait.
  • Scalaz演员:n / a。行动者是一个封闭的特质。
  • Lift Actors: Yes
  • 提升演员:是的
  • Scala Actors: Yes
  • Scala演员:是的
  • Akka Actors: No, actor instance is shielded behind an ActorRef.
  • Akka Actors:不,actor实例被屏蔽在一个ActorRef后面。

Actor type

  • Scalaz Actors: Actor[A] extends A => ()
  • Scalaz Actors: Actor[A]扩展了A => ()
  • Lift Actors: LiftActor, SpecializeLiftActor[T]
  • 提升演员:LiftActor SpecializeLiftActor[T]
  • Scala Actors: Reactor[T], Actor extends Reactor[Any]
  • Scala Actor:反应堆[T], Actor扩展反应堆[Any]
  • Akka Actors: Actor[Any]
  • Akka演员:演员(任何)

Actor lifecycle management

                    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

Message send modes

                    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作文。

Message reply modes

TBD

TBD

                    Scalaz Actors   Lift Actors     Scala Actors    Akka Actorsreply-to-sender-in-messagereply-to-message

Message processing

Supports nested receives?

支持嵌套接收吗?

  • Scalaz Actors: --
  • Scalaz演员:
  • Lift Actors: Yes (with a little hand coding).
  • 升降机演员:是的(用手工编码)。
  • Scala Actors: Yes, both thread-based receive and event-based react.
  • Scala参与者:是的,基于线程的接收和基于事件的响应。
  • Akka Actors: No, nesting receives can lead to memory leaks and degraded performance over time.
  • 不,嵌套接收会导致内存泄漏和性能下降。

Message Execution Mechanism

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

Distribution/Remote Actors

                    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

Howtos

TBD

TBD

                    Scalaz Actors   Lift Actors     Scala Actors    Akka ActorsDefine an actorCreate an actor instanceStart an actor instanceStop an actor instance

#2


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。

#3


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上测试平均延迟和吞吐量的代码和结果。


推荐阅读
author-avatar
龙马爱梓喵_me
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有