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


推荐阅读
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
  • Vagrant虚拟化工具的安装和使用教程
    本文介绍了Vagrant虚拟化工具的安装和使用教程。首先介绍了安装virtualBox和Vagrant的步骤。然后详细说明了Vagrant的安装和使用方法,包括如何检查安装是否成功。最后介绍了下载虚拟机镜像的步骤,以及Vagrant镜像网站的相关信息。 ... [详细]
  • 本文整理了Java中org.apache.solr.common.SolrDocument.setField()方法的一些代码示例,展示了SolrDocum ... [详细]
  • 如何用UE4制作2D游戏文档——计算篇
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了如何用UE4制作2D游戏文档——计算篇相关的知识,希望对你有一定的参考价值。 ... [详细]
  • Google Play推出全新的应用内评价API,帮助开发者获取更多优质用户反馈。用户每天在Google Play上发表数百万条评论,这有助于开发者了解用户喜好和改进需求。开发者可以选择在适当的时间请求用户撰写评论,以获得全面而有用的反馈。全新应用内评价功能让用户无需返回应用详情页面即可发表评论,提升用户体验。 ... [详细]
  • Tomcat/Jetty为何选择扩展线程池而不是使用JDK原生线程池?
    本文探讨了Tomcat和Jetty选择扩展线程池而不是使用JDK原生线程池的原因。通过比较IO密集型任务和CPU密集型任务的特点,解释了为何Tomcat和Jetty需要扩展线程池来提高并发度和任务处理速度。同时,介绍了JDK原生线程池的工作流程。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 闭包一直是Java社区中争论不断的话题,很多语言都支持闭包这个语言特性,闭包定义了一个依赖于外部环境的自由变量的函数,这个函数能够访问外部环境的变量。本文以JavaScript的一个闭包为例,介绍了闭包的定义和特性。 ... [详细]
  • flowable工作流 流程变量_信也科技工作流平台的技术实践
    1背景随着公司业务发展及内部业务流程诉求的增长,目前信息化系统不能够很好满足期望,主要体现如下:目前OA流程引擎无法满足企业特定业务流程需求,且移动端体 ... [详细]
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • Python爬虫中使用正则表达式的方法和注意事项
    本文介绍了在Python爬虫中使用正则表达式的方法和注意事项。首先解释了爬虫的四个主要步骤,并强调了正则表达式在数据处理中的重要性。然后详细介绍了正则表达式的概念和用法,包括检索、替换和过滤文本的功能。同时提到了re模块是Python内置的用于处理正则表达式的模块,并给出了使用正则表达式时需要注意的特殊字符转义和原始字符串的用法。通过本文的学习,读者可以掌握在Python爬虫中使用正则表达式的技巧和方法。 ... [详细]
  • 【shell】网络处理:判断IP是否在网段、两个ip是否同网段、IP地址范围、网段包含关系
    本文介绍了使用shell脚本判断IP是否在同一网段、判断IP地址是否在某个范围内、计算IP地址范围、判断网段之间的包含关系的方法和原理。通过对IP和掩码进行与计算,可以判断两个IP是否在同一网段。同时,还提供了一段用于验证IP地址的正则表达式和判断特殊IP地址的方法。 ... [详细]
  • 解决github访问慢的问题的方法集锦
    本文总结了国内用户在访问github网站时可能遇到的加载慢的问题,并提供了解决方法,其中包括修改hosts文件来加速访问。 ... [详细]
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社区 版权所有