Akka的Actor和Scala的Actor模型有什么区别

发布于 2025-01-07 09:50:34 字数 65 浏览 2 评论 0原文

我发现还有一个Akka Actor模型,所以我想知道Akka的Actor模型和Scala的Actor模型有什么区别?

I found there is also an Akka actor model, so I am wondering what's the difference between the Akka's Actor and Scala's Actor model?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冬天旳寂寞 2025-01-14 09:50:34

嗯,没有。只有 Actor 模型,Akka Actor 和 Scala Actor 是该模型的两个实现

All Actor 模型表示您的并发原语是 Actor,它可以:

  • 接收消息并根据消息的内容决定下一步做什么,包括:

  • 向他们知道的任何参与者发送消息

  • 创建新的参与者

并提供某些保证,例如:

  • 任何参与者只会处理一条消息一次

  • 参与者X发送到参与者Y的消息将按照发送的顺序到达

Scala 和 Akka Actor 在这个级别上没有区别。

有关它们功能的差异,请参阅不同的 Scala Actor 实现概述。对我来说,最重要的一点是 Akka 支持 Supervisor 和 ActorRegistry。

Well, there isn't. There is just Actor model, and Akka actors and Scala actors are two implementations of that model.

All Actor model says that your concurrency primitives are actors, which can:

  • receive a message and decide what to do next depending on the content of the message, including:

  • send messages to any actors they know about

  • create new actors

and provides certain guarantees, e.g.:

  • any actor will only handle a single message at a time

  • messages sent by actor X to actor Y will arrive in the order thay were sent

There is no difference between Scala and Akka actors on this level.

For differences in what they can do, see Different Scala Actor Implementations Overview. The biggest one, for me, is that Akka supports supervisors and ActorRegistry.

静谧 2025-01-14 09:50:34

历史上也有答案。 Scala 的创建者认为应该有一个 Actor 框架。 Jonas Bonér 尝试过,但并不完全满意,所以他开始开发一个新的——后来演变成了 Akka。然而,Scala 人认为它比他们自己的更好 - 因此在 Jfokus 2011 上他们宣布 Akka 将成为 Scala 的标准 Actor 框架。然而,这种迁移需要一些时间。

There is also a historical answer. The creators of Scala thought there should be an actor framework. Jonas Bonér tried it out, but was not completely satisfied so he started working on a new - which evolved into Akka. However, the Scala people thought it was better than their own - so at Jfokus 2011 they announced that Akka was to become the standard actor framework of Scala. However, that migration will take some time.

你怎么敢 2025-01-14 09:50:34

这在一定程度上取决于您对“模型”的含义 - 您可以参考“执行模型”或“编程模型”(也许还有其他模型)。

对于执行模型,基本上有两种:基于线程或基于事件。 Scala 标准 actor 库包含两者。基于线程的方法为每个参与者使用一个线程,而基于事件的方法使用线程池。前者更直观理解,后者更高效。 Akka 建立在基于事件的模型之上。

对于编程模型,scala标准库和Akka有很大的区别。在scala标准库中,你基本上实现了“run”方法 - 如果你想等待传入消息,你会让自己进入等待状态(通过调用“receive”或“react”)。因此,编程模型遵循“线程隐喻”。然而,在 Akka 中,编程隐喻是您实现一些生命周期方法 - 但“运行”方法是在框架内部编写的。事实上,这种编程模型与基于事件的执行模型一起工作也更好。

如果您对我写的 scala 标准 actor 的不同执行模型和编程模型感兴趣 a 很少 帖子 问题。

This depends a little on what you mean with "model" - you can either refer to the "execution model" or the "programming model" (and perhaps other models as well).

For execution models, there are basically two: thread-based or event-based. The Scala standard actor library contains both. The thread-based uses one thread for each actor, whereas the event-based uses a thread-pool. The former is more intuitive to understand, the latter is more efficient. Akka is built on the event-based model.

For programming model, there is a big difference between the scala standard library and Akka. In the scala standard library, you basically implement the "run" method - and if you want to wait for an incoming message, you get yourself into a waiting state (by calling "receive" or "react"). So, the programming model follow the "thread-metaphor". However, in Akka, the programming metaphor is that you implement a few life-cycle methods - but the "run"-method is written inside the framework. It actually turns out that this programming model works a lot better with the event-based execution model as well.

If you are interested in the different execution models and programming models of scala standard actors I have written a few posts on the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文