简体   繁体   English

Scala 并发模型上下文中的 Clojure 期货

[英]Clojure futures in context of Scala's concurrency models

After being exposed to scala's Actors and Clojure's Futures, I feel like both languages have excellent support for multi core data processing.接触了scala的Actors和Clojure的Futures之后,感觉这两种语言对多核数据处理的支持都非常好。

However, I still have not been able to determine the real engineering differences between the concurrency features and pros/cons of the two models.但是,我仍然无法确定两种模型的并发特性和优缺点之间的真正工程差异。 Are these languages complimentary, or opposed in terms of their treatment of concurrent process abstractions?这些语言在处理并发过程抽象方面是互补的还是相反的?

Secondarily, regarding big data issues, it's not clear wether the scala community continues to support Hadoop explicitly (whereas the clojure community clearly does ).其次,关于大数据问题,scala 社区是否继续明确支持 Hadoop 尚不清楚(而 clojure 社区显然支持)。 How do Scala developers interface with the hadoop ecosystem? Scala 开发人员如何与 hadoop 生态系统交互?

Some solutions are well solved by agents/actors and some are not.代理/参与者可以很好地解决一些解决方案,而有些则没有。 This distinction is not really about languages more than how specific problems fit within general classes of solutions .这种区别实际上并不是关于语言,而是关于特定问题如何适合一般解决方案类别 This is a (very short) comparason of Actors/agents vs. References to try to clarify the point that the tool must fit the concurrency problem.这是 Actors/agents 与 References 的(非常简短的)比较,试图阐明该工具必须适合并发问题的观点。

Actors excel in distributed situation where no data needs to be concurrently modified . Actors 在不需要同时修改数据的分布式情况下表现出色。 If your problem can be expressed purely by passing messages then actors will do the trick.如果您的问题可以纯粹通过传递消息来表达,那么演员就可以解决问题。 Actors work poorly where they need to modify several related data structures at the same time. Actor 在需要同时修改多个相关数据结构的情况下效果不佳。 The canonical example of this being moving money between bank accounts.典型的例子是在银行账户之间转移资金。

Clojure's ref s are a great solution to the problem of many threads needing to modify the same thing at the same time . Clojure 的ref很好的解决了很多线程需要同时修改同一个东西的问题。 They excel at shared memory multi-processor systems like today's PCs and Servers.他们擅长共享内存多处理器系统,如当今的 PC 和服务器。 In addition to the Bank account example, Rich Hickey (the author of clojure) uses the example of a baseball game to explain why this is important.除了银行帐户示例之外,Rich Hickey(clojure 的作者)还使用棒球比赛的示例来解释为什么这很重要。 If you wanted to use actors to represent a baseball game then before you moved the ball, all the fans would have to send it a message asking it where it was... and if they wanted to watch a player catching the ball things get even more complex.如果你想用演员来代表一场棒球比赛,那么在你移动球之前,所有的球迷都必须向它发送一条消息,询问它在哪里……如果他们想看一个球员接球,事情就会变得平分秋色更复杂。

Clojure has cascalog which makes writing hadoop jobs look a lot like writing clojure. Clojure 有 cascalog,这使得编写 hadoop 作业看起来很像编写 clojure。

Actors provide a way of handling the potential interleaving and synchronization control that inevitably comes when trying to get multiple threads to work together. Actors 提供了一种处理潜在的交织和同步控制的方法,当试图让多个线程一起工作时不可避免地会出现这种情况。 Each actor has a queue of messages that it processes in order one at a time so as to avoid the need to include explicit locks.每个参与者都有一个消息队列,它一次一个地处理这些消息,以避免需要包含显式锁。 In this case a Future provides a way of waiting for a response from an actor.在这种情况下, Future 提供了一种等待参与者响应的方法。

As far as Hadoop is concerned, Twitter just released a library specifically for Hadoop called Scalding but as long as the library is written for the JVM, it should work with either language.就 Hadoop 而言,Twitter 刚刚发布了一个专门用于 Hadoop 的库,称为Scalding,但只要该库是为 JVM 编写的,它就应该适用于任何一种语言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM