Scala / akka / stm for a great general condition?

I am new to Scala and Akka, and I am considering using it to solve the problem. Suppose I have a calculation mechanism (which is looking for a solution). I would like to parallelize this search both through the processor and through the nodes, providing each processor on each node with its own engine instance.

Motor inputs consist of a small number of scalar inputs and a very large hash table. Each engine instance uses its own scalar inputs to make a small local change to the hash table, calculates the kindness, then discards the changes (they should not be committed / noticed by any other engine instance). The value of kindness will be returned to some coordinator who will choose among the results.

I read some about the STM TransactionalMap as a general state vehicle. This seems perfect, but I really don't see any complete examples using it as a shared state.

Questions:

  • Is the actor / stm model suitable for this problem?
  • Can you show a concrete example of how to distribute the general condition? (is this [TransactionalMap [,]] message as a message?
  • Is there anything else in the distribution of the general state in a node, and not on different nodes?

Inquisitional minds want to know

Allan

+6
source share
1 answer

As for shared memory processing, it doesn't look like STM would be appropriate here because you do not want changes made to kernel instances to be passed to the shared copy of the hash table.

Instead, an immutable HashMap might be better. Elements that do not change on the map can be shared instances of the engine, taking into account the differences in each map with additional memory.

The actor model is perfect for you, what you want to do. Configure one actor for each kernel instance that you want, and pass it a message with scalar values ​​and a hashmap. Then return the results to the coordinator.

+1
source

Source: https://habr.com/ru/post/894113/


All Articles