scalaakkashardingpekko

Per EntityType Active Entity Limit in Cluster Sharding Passivation


I have a clustered system that has a number of different entity types with different memory and computation complexity characteristics and would like to use active-entity-limit in my Passivation Strategy to use different limits for each type, since some could easily support thousands per shard region, while others should only support 100s.

I can't find any way to do this with the existing PassivationStrategySettings, nor can I find any documentation on how to define my own Passivation Strategy programmatically. Is there a place to hook into the ShardRegion to effect this type of behavior?


Solution

  • You can use ClusterShardingSettings.PassivationStrategySettings.apply(Config) to load passivation config from an arbitrary config, for example picked up from some path you defined in your application.conf using something along the lines of system.settings.config.getConfig("my-app.passivation-for-a"), then set it on the cluster sharding settings using ClusterShardingSettings#withPassivationStrategy.