scala/akka/stm 设计用于大型共享状态?
我是 Scala 和 Akka 的新手,正在考虑使用它来解决问题。假设我有一个计算引擎(用于搜索解决方案)。我想通过为每个节点上的每个 cpu 提供其自己的引擎实例来并行化跨 cpu 和跨节点的搜索。
引擎输入由少量标量输入和一个非常大的哈希表组成。每个引擎实例将使用其标量输入对哈希表进行一些小的本地更改,计算优点,然后丢弃其更改(它们不需要由任何其他引擎实例提交/查看)。优度值将返回给某个协调员,协调员将在结果中进行选择。
我正在阅读一些有关 STM TransactionalMap 作为共享状态工具的内容。这看起来很理想,但我确实没有看到任何使用它作为共享状态的完整示例。
问题:
- actor/stm 模型似乎适合这个问题吗?
- 您能展示一个如何分配共享状态的具体示例吗? (Ref[TransactionalMap[,]] 是作为消息吗?
- 与在不同节点之间分发共享状态相比,在节点内分发共享状态有什么不同吗?
,好奇心想知道
Allan
I am new to Scala and Akka and am considering using it to solve a problem. Suppose I have a calculation engine (that searches for a solution). I'd like to parallelize that search both across cpus and across nodes by giving each cpu on each node its own engine instance.
The engine inputs consist of a small number of scalar inputs and a very large hash table. Each engine instance would use its scalar inputs to make some small local change to the hash table, calculate a goodness, then discard its changes (they do not need to be committed/seen by any other engine instance). The goodness value would be returned to some coordinator that would choose among the results.
I was reading some about the STM TransactionalMap as a vehicle for shared state. This seems ideal, but I don't really see any complete examples using it as shared state.
Questions:
- Does the actor/stm model seem right for this problem?
- Can you show a specific example of how to distribute the shared state? (is it Ref[TransactionalMap[,]] as a message?
- Is there anything different about distributing the shared state within a node as opposed to across different nodes?
Inquiring Minds Want to Know,
Allan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就处理共享内存而言,STM 听起来并不适合这里,因为您不希望将引擎实例中所做的更改提交到哈希表的共享副本。
相反,不可变的 HashMap 可能是更合适。映射中不变的元素可以由引擎实例共享,只有每个映射中的差异占用额外的内存空间。
演员模型非常适合您想做的事情。为您想要的每个引擎实例设置一个参与者,并向其传递一条包含标量值和哈希图的消息。然后让它将结果返回给协调器。
In terms of handling shared memory it doesn't sound like STM would be the right fit here because you don't want the changes made in engine instances to commit to the shared copy of the hash table.
Instead, an immutable HashMap might be a better fit. The elements that do not change in the map can be shared by the engine instances with only the differences in each map taking additional memory space.
The actor model would fit very well what you want to do. Set up one actor for each engine instance you want and pass it a message with the scalar values and the hashmap. Then have it return the results to the coordinator.