哪些设计决策会支持Scala的Actors而不是JMS? [英] What design decisions would favour Scala's Actors instead of JMS?

查看:71
本文介绍了哪些设计决策会支持Scala的Actors而不是JMS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Scala Actors而不是JMS有什么区别?

What are the differences using Scala Actors instead of JMS?

例如从性能和可伸缩性的角度来看,与JMS相比,Scala Actor模型添加了什么?在哪些情况下使用Actors而不是JMS更有意义,即Actors解决了JMS无法解决的问题?

For example from a performance and scalability perspective, what does the Scala Actor model add compared to JMS? In which cases does it make more sense to use Actors rather than JMS, i.e. what problems does Actors address that JMS cannot cover?

推荐答案

JMS和Scala演员具有理论上的相似性,但并不认为它们必然在架构上解决相同的问题。 Actors旨在成为共享内存并发的轻量级替代方法,其中种族和死锁通常难以意外创建。 JMS是一个复杂的API,旨在跨越直接消息传递,发布/订阅,事务,EJB集成等。

JMS and Scala actors share a theoretical similarity but don't think of them as necessarily solving the same problems architecturally. Actors are meant to be a lightweight alternative to shared-memory concurrency where races and deadlocks are generally harder to accidentally create. JMS is a sophisticated API that's meant to span direct messaging, publish/subscribe, transactions, EJB integration, etc.

与演员相当的最接近的JMS将是消息驱动的由非持久性非事务性非发布/子队列支持的bean。我将其称为简单的JMS bean。

The closest JMS equivalent to an actor would be a message driven bean that is backed by a non-persistent, non-transactional, non-pub/sub queue. I'll call that a "simple JMS bean".

现在,提出您的问题。

性能是很难谈论,因为JMS是一个规范而不是一个实现。在使用简单的JMS bean时,我希望性能大致相似,并且可能在时间和内存方面对演员有一点优势。当您向JMS添加功能时,例如pub / sub,事务等,性能自然会进一步下降,但是你会尝试将苹果与橙子进行比较。

Performance is a hard thing to talk about since JMS is a specification rather than an implementation. None-the-less when using simple JMS bean I'd expect performance to be roughly similar with perhaps a bit of an edge to the actor in time and memory. As you add capabilities to JMS such as pub/sub, transactions, etc performance will naturally degrade even further but then you're trying to compare apples to oranges.

至于可扩展性,简单的JMS bean应该与actor完全一样地扩展。将事务添加到JMS组合中会自然地损害可伸缩性,具体取决于事务的范围。

As for scalability, simple JMS beans should scale pretty much exactly the same way as actors. Adding transactions into the JMS mix will naturally hurt scalability by an amount depending on the scope of the transactions.

更广泛的问题是演员做什么,JMS不能。好吧,没有内置的pub子或事务,似乎演员从JMS中减去 - 而且广义上这是真的。但事情就是这样:演员需要这么少的代码,我可以愉快地使用它们来实现非常精细的并发性。在普通的Java代码中,我可能会说我不想搞砸JMS及其依赖项或它需要的代码等等,所以我只会生成一个线程,使用一个锁,并共享一个数据结构。对于Scala演员,我更有可能说我只是掀起演员并继续前进。

The broader question of what do actors do that JMS can't. Well, without built-in pub sub or transactions it would seem that actors subtract from JMS - and broadly that's true. But here's the thing: actors require so little code that I can happily use them for very fine grained concurrency. In ordinary Java code I might say "I don't feel like screwing with JMS and its dependencies or the code it requires etc so I'll just spawn a thread, use a lock, and share a data structure." With Scala actors I'm much more likely to say "I'll just whip up an actor and move on."

在设计方面也存在哲学上的差异。 Actor有一个简单的内置管理层次结构概念。演员通常用于让它崩溃设计。如果一个演员因某种原因去世,那么另一个演员负责决定该怎么做,比如重新启动那个演员,杀死一堆演员并重新启动所有演员,或者杀死一堆演员本身以便其他一些演员可以处理问题。这种事情可以附加到JMS上,但它不是API的核心,必须以某种方式在外部进行管理。

There's also a philosophical difference in design. Actors have a simple, built in concept of supervisor hierarchies. Actors are usually used in a "let it crash" design. If an actor dies for some reason then another actor is responsible for deciding what to do about it such as restarting that actor, killing a bunch of actors and restarting all of them, or killing a bunch of actors and itself so that some otther actor can deal with the problem. That kind of thing can appended onto JMS, but it's not core to the API and must be managed externally somehow.

顺便说一句,对于一个Scala actor库来说,移动更多进入JMS所涵盖的领域,请参阅 Akka 。 Akka还为许多常见的actor层次结构策略带来了声明性方法。

By the way, for a Scala actor library that moves more into the realms that JMS covers see Akka. Akka also brings a declarative approach to many common actor hierarchy strategies.

这篇关于哪些设计决策会支持Scala的Actors而不是JMS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆