Passivation
Actors can be passivated when they are idle after some period of time. Passivated actors(including descendants) are removed from the actor system to free-up resources. When cluster mode is enabled, passivated actors are removed from the entire cluster.
Passivation is crucial in large-scale or distributed systems to:
Avoid memory/resource leaks.
Clean up unused actors.
Keep actor lifecycles predictable.
Balance load over time.
GoAkt introduces a flexible and pluggable actor passivation mechanism through the WithPassivationStrategy
option. This gives developers fine-grained control over how and when inactive or overloaded actors are automatically passivated to free up system resources.
Strategies
GoAkt comes with the following passivation strategies:
Time-Based Passivation: This strategy automatically passivates (i.e., stops) an actor if it has not received any messages within a configurable time duration. This is the default strategy with
two minutes
duration.Message Count-Based Passivation: This strategy passivates an actor after processing a specific number of messages.
Runtime Control
Passivation can be dynamically paused or resumed at runtime using built-in system messages:
PausePassivation: Temporarily disable passivation for an actor
ResumePassivation: Re-enable passivation for an actor
This feature is useful for workflows that require uninterrupted actor activity for a period of time (e.g., during long transactions or event replay).
Eviction
Aside the actor-based passivation, GoAkt comes with a system passivation feature based-upon some eviction algorithm to free up resources. The following eviction policies are supported:
LRU
- Least Recently Used passivates actors that have not been accessed for the longest time when the number of active actors exceeds the specified limit. This policy is effective for scenarios where older, unused actors are likely to remain idle.LFU
- Least Frequently Used passivates actors that have been used the least number of times when the number of active actors exceeds the specified limit. This policy is suitable when you want to retain actors that are consistently in use, even if they were accessed a while ago.MRU
- Most Recently Used passivates actors that were accessed most recently when the number of active actors exceeds the specified limit. While less common for general resource management, MRU can be useful in specific scenarios where fresh data is prioritized, and older, less volatile data can be evicted.
To set any of this eviction policy, one needs to use the ActorSystem
option WithEvictionStrategy
during its instantiation.
Last updated