Am Mittwoch, 5. Februar 2014 08:46:55 UTC+1 schrieb Roger Alsing:
>
> Lets say we have the following senario
>
> * we have an unbounded number of entities
> * each entity may only process one command at a time
> * each entity only process a few messages occasionally and then idle for 
> an undefined amount of time
>
> Spawning an actor for each entity would force us to keep atleast one actor 
> per entity in memory all the time. which is expensive since the will mostly 
> be idle.
>

How many entities are we talking about? An actor is pretty small, so 
usually having many of them in memory is not such a big deal, except you 
are running in a very constrained environment.
 

> What would be the most idiomatic Akka way to deal with this?
>
> Should we instead add an entity Id to each message, and have a custom 
> router that directs each message to a pool of actors and create an affinity 
> between the entity id and the pooled actor?
> e.g.
>
> someting like:
> var poolIndex = ((IHaveId)message).Id.GetHashCode() % poolSize;
>
> This way, I could direct every message for a specific entity to the same 
> underlying worker actor and thus prevent concurrency issues for this entity.
> The worker actor could also fetch the entity on demand and then release it 
> once the command completes.
>

You can use the Consistent Hashing router to achieve exactly 
that: http://doc.akka.io/docs/akka/2.2.3/scala/routing.html
 

> Are there other alternatives?
>

Do these entity actors have any state that needs to be kept in memory? If 
not, one option could also be to just spawn a new actor for every command, 
or to keep them alive for a while and then terminate them (using 
ReceiveTimeout e.g.). Of course, if they require state that needs to be 
gathered from somewhere, this is probably not a very good solution.

best

Carsten 

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: http://akka.io/faq/
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to