Clustered-wide synchronizing actor creation

76 views
Skip to first unread message

Ngoc Dao

unread,
Jan 9, 2013, 1:28:49 PM1/9/13
to Akka User List
I want to create clustered SockJS server with Akka.

SockJS has the idea of id. How do I do the below with Akka?
1. Lookup if there's an actor named xxx in the Akka cluster
2. If not, create it and name it xxx
3. Otherwise, just get the actor

Andrew Headrick

unread,
Jan 9, 2013, 2:15:54 PM1/9/13
to akka...@googlegroups.com
If I understand you want a single actor instance in a cluster of akka servers?

If this is true, Akka does not provide this out of the box ( until 2.2, I think ) and it is something you have to add yourself. This can be a difficult problem, depending on the guarantees you need regarding, consistency, balancing, failover etc. I have very stringent requirements and have to make sure that there is only one instance of an actor in the cluster at a given time and if the actor or node dies it can be moved to another node. It was not a simple problem to solve. If your requirements are not as stringent, creating an actor based on a consistent hash of some key ( hash(key) :Node ) can be a fairly straight forward way of accomplishing the task. However this has issues if the cluster changes. 

In order to solve the problem of a 'get or create' senario you will need a singleton actor that creates & keeps references to actors to which you only want a single instance of. Instead of using the normal context.actorFor method for actor resolution you can ask the singleton actor for a child actor ref or forward messages to the child through the parent. In this way the parent takes care of the 'get or create' semantics. In addition the parent can listen on the dead letter queue for messages intended for the child, recreate the child and forward the dead message to the child.

Hope this helps,
Andrew

Ngoc Dao

unread,
Jan 9, 2013, 9:14:28 PM1/9/13
to Akka User List
> If I understand you want a single actor instance in a cluster of akka
servers?

Yes, that's true.

> In order to solve the problem of a 'get or create' senario you will need a singleton actor

Yes, I think that's the only solution at this Akka version. The
problem with this solution is what to do when the machine that
contains that actor dies.

I'm thinking of using Hazelcast with its distributed lock feature
together with Akka:
http://www.hazelcast.com/docs/2.4/manual/multi_html/ch02s07.html

Patrik Nordwall

unread,
Jan 10, 2013, 2:36:52 AM1/10/13
to akka...@googlegroups.com
On Thu, Jan 10, 2013 at 3:14 AM, Ngoc Dao <ngocda...@gmail.com> wrote:
> If I understand you want a single actor instance in a cluster of akka
servers?

Yes, that's true.

This looks like the single most requested feature of Akka Cluster so far.
It will fit in nicely with our plans for how to distribute the actor tree in the cluster, but that is not in place yet.
It is partly described in the documentation (and samples) how to implement that by listening for leader change events, but the corner cases are not handled. It would be nice if we can make it easier to implement this with current membership support. I can't promise anything.

/Patrik
 

> In order to solve the problem of a 'get or create' senario you will need a singleton actor

Yes, I think that's the only solution at this Akka version. The
problem with this solution is what to do when the machine that
contains that actor dies.

I'm thinking of using Hazelcast with its distributed lock feature
together with Akka:
http://www.hazelcast.com/docs/2.4/manual/multi_html/ch02s07.html

--
>>>>>>>>>>      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 post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user?hl=en.





--

Patrik Nordwall
Typesafe The software stack for applications that scale
Twitter: @patriknw

Patrik Nordwall

unread,
Jan 10, 2013, 4:31:34 AM1/10/13
to akka...@googlegroups.com
We think this is important and will try to squeeze in some kind of pattern (with implementation) for the requested feature.

Does that cover what you need? This has been discussed in several threads so I'm not only thinking about the specific question here.

Regards,
Patrik

Ngoc Dao

unread,
Jan 10, 2013, 7:27:30 PM1/10/13
to akka...@googlegroups.com
> Does that cover what you need?

Yes. Lots of thanks Patrik.

Andrew Headrick

unread,
Jan 10, 2013, 8:07:27 PM1/10/13
to akka...@googlegroups.com
I have created two implementations of this on akka 2.0.4. If I get some time this weekend Ill try to write up a description.

-A

Patrik Nordwall

unread,
Jan 11, 2013, 2:23:02 AM1/11/13
to akka...@googlegroups.com
On Fri, Jan 11, 2013 at 2:07 AM, Andrew Headrick <andrew....@gmail.com> wrote:
I have created two implementations of this on akka 2.0.4. If I get some time this weekend Ill try to write up a description.

That would be great.
/Patrik
 

-A


On Thursday, January 10, 2013 4:27:30 PM UTC-8, Ngoc Dao wrote:
> Does that cover what you need?

Yes. Lots of thanks Patrik.

--
>>>>>>>>>> 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 post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user?hl=en.
 
 
Reply all
Reply to author
Forward
0 new messages