Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka for simulations

I'm new to akka and the actor-pattern, therefore I'm not sure if it fit my needs.

I want to create a simulation with akka and millions of entities (think as domain objects - later actors) that can influence each other. So thinking as simulation with a more-or-less "fuzzy" result, we have an array with entities, where each of these entities has a speed, but is thwarted by the entities in front of the actual entity. When the simulation starts, each entity should move n-fields, or, if thwarted by others, less fields. We have multiple iterations, and in the end we have a new order. This is repeated for some rounds until we want to see a "snapshot" of the leading entities (which are then possibly removed before the next round starts).

So I don't understand if I can create this with akka, because:

Is it possible to have global list with the position of each actor, so they know at which position they are and which are in front of them? As far as I understand, this violates the encapsulation of the actors. I can put the position of the actor in the actor itself, but how can I see/notify the actors around this actor? Beside of this, the global list will create synchronization problems and impacts the performance, which is the exactly opposite of the desired behaviour (and is complementary to akka/the actor-pattern)

What did I missed? Do I have to search for another design approach? Thanks for suggestions.

Update: working with the eventbus and classifiers doesn't seem an option, too. Refering to the documentation:

"hence it is not well-suited to use cases in which subscriptions change with very high frequency"

like image 921
Dag Avatar asked Mar 20 '12 17:03

Dag


1 Answers

The actor model is a very good fit for your scenario. Actors communicate by sending messages, so each actor can send messages to his neighbors containing his position. Of course, each actor cannot know about every other actor in the system (not efficiently anyway) so you will have to also devise a scheme though which each actor knows which are his neighbors.

As for getting a snapshot of the system, simply have a central actor that is known by everybody and knows everybody.

It seems like you're just getting started with actors. Read a bit more - the akka site is a good resource - and come back and refine your question, if needed.

Your problem sounds like an n-body simulation sort of thing, so looking into that might help also.

like image 50
cos Avatar answered Sep 28 '22 13:09

cos