Akka cluster: stopping actor doesn't remove sharding entry

284 views
Skip to first unread message

Eduardo Fernandes

unread,
Jul 22, 2014, 4:39:32 PM7/22/14
to akka...@googlegroups.com
Hi.

First of all thanks for your time on this.

I'm using Akka version 2.3.4 (Java).

I've stopped an actor 

        getContext().stop(getSelf());

and when I look at the rebalance() method in my AllocationStrategy I still see the entry in the sharding region corresponding to the stopped actor. I'm using a consistent hash scheme so the actor has a one to one correspondence to a particular sharding entry.

I expected that after the stop() method the cluster should remove the entry from the list. Is this the expected behaviour?

The problem is that if we created a lot of actors (corresponding to a particular sharding value) we got many useless (?) entries in the maps processed by the allocation strategy. I'm writing a start/stop routing for the cluster so I'd like to use the info in the sharding strategy to produce a list with only the active objects in the cluster.

The alternative is that I manage a list of active entries by myself, of course, using a kind of pub/sub actor.

Many thanks again for your help.

Edu.


Akka Team

unread,
Jul 23, 2014, 5:13:46 AM7/23/14
to Akka User List
Hi Eduardo,

Shards are assumed to be a fixed and relatively few in numbers (like a few hundreds). They are the unit of rebalancing and do not get removed even if there are no active entries in them at a certain time. This is usually not a problem if the number of shards are a few, but if you map all your entries with shardId == entryId then obviously all entries will live on a separate shard -- this use case is not optimized so far.

-Endre


--
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Akka Team
Typesafe - The software stack for applications that scale
Blog: letitcrash.com
Twitter: @akkateam

Eduardo Fernandes

unread,
Jul 23, 2014, 9:41:00 AM7/23/14
to akka...@googlegroups.com
Many thanks for your help Endre.

Completely understood from shard perspective. I'll check if the entry disappear if the actor is stopped (which is not the case for the sharding).

Regards.

Eduardo Fernandes

unread,
Jul 23, 2014, 6:42:36 PM7/23/14
to akka...@googlegroups.com
Ok. Entries are managed as expected. After looking at the code I understand what you mean.

Thanks a lot for your help.

Regards.

Akka Team

unread,
Jul 24, 2014, 4:20:19 AM7/24/14
to Akka User List
Hi Eduardo,

Just to add more information, since the persistence support for sharding allows persisted entries to be passivated (the actor is stopped to save memory, but is restored from disk when needed) in which case the ShardRegion -> shardId association still needs to be maintained although no actors might be running in that shard. In fact this table is persisted by the ShardCoordinator so if the node hosting it fails it can be reliably restored in a new node.

-Endre


--
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Eduardo Fernandes

unread,
Jul 24, 2014, 5:27:44 AM7/24/14
to akka...@googlegroups.com
Yes, we are using passivation. Tx. 

There is a way of retrieve the entries id's from the shardings? 
There is a member called entries in the sharding region class but I don't know if I have access to it. 

Tx again. 


You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/ravs9P4Nz7A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

Akka Team

unread,
Jul 24, 2014, 7:00:01 AM7/24/14
to Akka User List
Hi Eduardo,

There is no explicit table maintained for individual entries. Sharding maintains the table what ShardRegions are responsible for what ShardIds, but we don't have a list of all entities inside the ShardId -- since these relationships can be calculated by the IdExtractor and ShardResolver functions.

I.e. if you want to send a message to a specific ID:
 - the shard ID is calculated using the ShardResolver function
 - using the internal tables we find out which ShardRegion hosts that ShardId
 - the message is forwarded to that ShardRegion
 - the ShardRegion forwards the message to the actor corresponding to the given Id (reactivating from disk if needed). This step does not need any tables

-Endre

-Endre

Eduardo Fernandes

unread,
Jul 24, 2014, 7:29:35 AM7/24/14
to akka...@googlegroups.com
Quite clear Endre, as always.

Many thanks again for your time!

Best regards from Spain.
Reply all
Reply to author
Forward
0 new messages