How can I check the number of the entry actors spawned off by akka ShardRegion?

81 views
Skip to first unread message

Yifei

unread,
Jul 20, 2015, 2:45:49 PM7/20/15
to akka...@googlegroups.com
Hello everyone,

I posted this question in SO but it seems like akka users are not active there. Here I repost the question and hope somebody please help me... Thanks

I am trying to setup an Akka cluster.


I have 3 hosts: host1, host2, host3


2 seed nodes: seed1 is on host1 and seed2 is on host2


2 ShardRegion nodes: SR1 is started on both host1 and host2


1 Query nodes is on host3, which will send 100 messages to the SR1


the idExtractor and shardResolver logic of SR1 are shown as follows:

val idExtractor: ShardRegion.IdExtractor = {
    case EntryEnvelope(id, payload) => (id.toString, payload)
    case msg @ Get(id)              => (id.toString, msg)
}

val shardResolver: ShardRegion.ShardResolver = msg => msg match {
    case EntryEnvelope(id, _) => (id % 10).toString
    case Get(id)              => (id % 10).toString
}


From my understanding, I think the message will be sharded to 10 shards, and both SR1@host1 and SR1@host2 hold 5 shards.


But after I sent 100 messages to the SR1, the logs looked like this:

[INFO] [07/20/2015 12:24:57.091] [MyAkkaCluster-akka.actor.default-dispatcher-70][akka.tcp://MyAkkaCluster@host2:13598/user/sharding/Counter1/97] Counter1 got event CounterChanged(1)

If akka.tcp://MyAkkaCluster@host2:13598/user/sharding/Counter1/xx means a new entry actor, I saw both SR1@host1 and SR1@host2 spawned off 50 different entry actors to process the message.


Is it the right way to check how many entry actors that a shardRegion spawn?

Jim Hazen

unread,
Jul 20, 2015, 3:16:24 PM7/20/15
to akka...@googlegroups.com
There will be a new actor activated for each unique messageId destination.  Messages will arrive at that actor for processing.  Actors are grouped into shards, which help manage those actors.  If you send 100 messages to unique destinations across your cluster, they'll be handled by 100 unique actors.  They'll be managed by 10 shards, across your ?? nodes.

So seeing the creation of 100 actors and not 10, is expected.

To get the number of actors managed by the shardRegion I assume you'd need to discover the actors representing the shard regions and then size() their children.  I believe there is an internal messaging protocol for doing this, but I don't have the docs in front of me.  You probably also find actors under the /user/sharding/ namespace using normal actor selection.

Yifei

unread,
Jul 20, 2015, 3:48:06 PM7/20/15
to akka...@googlegroups.com
Thanks Jim,

It helps a lot. 
Assuming I have 3 shardRegions running on 3 nodes with the same shard name. Can I know the relationship between a shard and a shardRegion? For example, can I know if shard#3 is under shardRegion@host2? 

Thanks,
Yifei

Jim Hazen

unread,
Jul 20, 2015, 3:57:54 PM7/20/15
to akka...@googlegroups.com
It might be possible to find out, however why is this important to you?  The point of Akka cluster sharding is that shard management, handler actor management and message routing, is all transparent.  I use this facility in my work and I don't know what nodes are handling what requests (sure I can track the logs and find out).  And I don't mind not knowing.  Akka does a lot of work behind the scenes to rebalance as nodes add/drop from the cluster.  From a client perspective, things just work.

Are you just curious about behavior, or have specific plans for this information?

--
>>>>>>>>>> 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 a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/e0fqWMFzZuY/unsubscribe.
To unsubscribe from this group and all its topics, 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.

Yifei

unread,
Jul 20, 2015, 5:19:03 PM7/20/15
to akka...@googlegroups.com
Thanks Jim,

I planned to use the information to monitor the load of the actors and shards. For example, to check if the actors are eating all the resources on this host, if I should scale up the shardregion

Also, do you know if I can make the actor run in single-thread mode? As a result, the new incoming request arrived in that actor will wait until the current process is done.

Jim Hazen

unread,
Jul 20, 2015, 5:35:10 PM7/20/15
to akka...@googlegroups.com
To increase capacity you'll be scaling out nodes, not shard regions.  Shards are logical managers/buckets, they help organize and support the actual processing actors, but it's those actors that are distributed.  You'll have one for each unique message destination, regardless of your number of shards.  If you're worried about resource utilization, you're likely best off using standard JVM monitors and monitoring the Java application as a whole for resource usage.  Do your metrics at that level and add hosts as required. 

Also, actors are already single-threaded, please see the Actor docs about how they work.  Messages sent to an actor will be handled by a single thread.  Within your receive block/method you can decide to use additional threads to farm out message processing work and increase actor throughput. 
Reply all
Reply to author
Forward
0 new messages