Hi Idris,

On 25 September 2014 at 19:26:25, Idris Mokhtarzada ([email protected]) wrote:

Hi,

I'm just starting to tinker with Akka, so forgive my ignorance.  I'm having 
trouble determining when I should be creating new actors every time vs. 
re-using actors and maybe running them in round-robin pools or something.  
Below is my use case.. any advice would be very helpful.

This is a Spring MVC webapp, and I'm using Akka to traverse a tree which is 
associated with some user data.  These trees have 4 different node types 
(including the root), so I have the following actor classes defined:
Root: 1 actor class for the "root" node.. this basically calls the "Children" 
actor below
Children: 1 actor class to process the children of internal nodes
Leaf: 1 actor class to process the leaf nodes
As I traverse the tree, each actor is generating some HTML and sending back to 
the parent.  At the Children nodes, these are concatenated together and sent 
back to the parent.
The advantage I'd like to gain with Akka is I'd like to be able to scale 
processing of the leaf nodes horizontally, to multiple threads, and possibly 
multiple servers.

Currently, at every node in the tree, I'm calling context.actorOf(...) to get 
the child actors.  My question is whether I should be doing that, or whether 
it's better to call context.actorOf(...) only ONCE per actor TYPE, and then 
setup a routing pool to scale.  More generally, when do you want to create new 
actors vs. re-use actors from a pool?  Any help on this topic would be greatly 
appreciated.


I'm not sure that I follow you when you say that you at ever node in the tree 
call context.actorOf to get the children. Are you dynamically constructing the 
actors in the the tree as you walk it, or do you mean that create the actors 
that construct the HTML?

In general, it's very cheap to create an actor to do some temporary work (i.e. 
aggregating the HTML from sub nodes). The main actors remain responsive, and 
since the children can send things directly to the temporary aggregating actor, 
you don't need to keep track of multiple simultaneous aggregations in a single 
actor.

If your code uses multiple actors and fan out at tree node points, you should 
already be using multiple threads. When it comes to scaling to multiple 
servers, you need to start thinking about partitioning your tree across 
multiple systems, and then the parent/child relationships might not be a god 
fit.

B/

Thanks!
Idris
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> 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/d/optout.

-- 
Björn Antonsson
Typesafe – Reactive Apps on the JVM
twitter: @bantonsson

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      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/d/optout.

Reply via email to