Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it mandatory to have a master actor in Akka?

Tags:

scala

akka

actor

I am trying to learn a bit about akka actors (in scala) and I came up with this question that I couldn't find an answer to.

Do you necessarily need to create a master actor and from there create the workers with a workerRouter? Or can you just skip this step and go directly to create workers with a workerRouter from your Main object?

Let me know if you need any code, but I'm basically following the HelloWorld for akka.

like image 834
KKO Avatar asked Jan 08 '23 20:01

KKO


1 Answers

Strictly speaking: yes. In terms of bussiness logic: no.

Akka's actors, are by design, hierarchical . That means, any actors you create will always have a "parent"/"master", if not one defined yourself, then the /user guardian actor .

However, note that this hierarchical relationship, from Akka's system point of view, concerns the actor lifecycle and child supervision. It does not care about how you wire the actors up with your messages and/or any custom lifecycle handling.

So, from the point of view of your application, you can have your worker actors run as peers with some some sort of consensus scheme. They will of course have system parent (/user if you won't define one yourself), but as long as you don't care about supervision - and if you're just starting to learn Akka you might not - everything will work fine.

Finally, note that there can be many schemes for working in a "worker pool" setup. For example, this article on work pulling might give you some inspiration on the possible solutions to such problems.

like image 108
mikołak Avatar answered Jan 28 '23 16:01

mikołak