Akka cluster sharding base on traffic of shards

Akka cluster sharding-coordinator uses LeastShardAllocationStrategy to decide. but the problem is some times all memebers not equal , i mean some members will have more traffic than others , so if akka distribute them equally through the nodes , some nodes will be under more traffics .

I found that we could implement ShardAllocationStrategy manually, but it only keep track of the shardRegion actorRefs and shardIds .

My question is how we could have more meaningful state (e.g. weight of each shardId) there to decide base on weight of shards?

You could for example back you custom shard allocation strategy with an actor, using ask to get the future response values for the strategy interface, and keep arbitrary state in it.

That would allow you to interact with other actors in the cluster etc. to make more informed choices around where you have the strategy allocate new shards.

Figuring out how to grab specific metrics you want to base it on could perhaps be tricky but there is some sharding inspection messages you could use, check out GetShardRegionStats and GetShardRegionState.

1 Like