Per-actor passivation
Per-actor passivation is configured per actor at spawn. The passivation manager tracks each actor and stops it when its strategy triggers. Only actors with a passivation strategy (other thanLongLivedStrategy) are tracked.
Strategies
| Strategy | Constructor | Trigger |
|---|---|---|
| TimeBasedStrategy | passivation.NewTimeBasedStrategy(timeout) | No message within the configured duration |
| MessagesCountBasedStrategy | passivation.NewMessageCountBasedStrategy(maxMessages) | Actor has processed at least maxMessages since the strategy was registered |
| LongLivedStrategy | passivation.NewLongLivedStrategy() | Never passivate (opt-out) |
Usage
WithLongLived() to opt out:
When to use
- Grains and virtual actors (default for many grains)
- Actors with large per-instance state
- High churn of short-lived entities
When to avoid
- Long-lived services that must stay up
- Actors that handle infrequent but critical messages
System eviction
System eviction is a node-wide mechanism that limits the total number of active actors. When the count exceeds the configured limit, the framework passivates actors according to an eviction policy (LRU, LFU, or MRU). This is independent of per-actor passivationβsystem eviction can stop any user actor, including those withLongLivedStrategy.
Eviction policies
| Policy | Description |
|---|---|
| LRU | Least Recently Used β passivate actors with the oldest LatestActivityTime |
| LFU | Least Frequently Used β passivate actors with the lowest ProcessedCount |
| MRU | Most Recently Used β passivate actors with the newest LatestActivityTime |
Configuration
| Parameter | Purpose |
|---|---|
| limit | Maximum number of active actors before eviction runs. Must be > 0. |
| policy | actor.LRU, actor.LFU, or actor.MRU |
| percentage | Percentage of actors to passivate when over limit (0β100). Clamped automatically. |
| interval | How often the eviction engine runs (e.g. 5*time.Second) |
Behavior
- The eviction loop runs at the configured interval.
- When
NumActors() > limit, actors are selected by policy and passivated viaShutdown. - The number of actors to evict is the greater of: (total β limit) and (percentage Γ total / 100).
- System actors (reserved names) are excluded. Only user actors are eligible for eviction.
When to use
- Memory or resource constraints on a node
- Bounding actor count regardless of per-actor strategy
- Coarse-grained capacity management
Comparison
| Aspect | Per-actor passivation | System eviction |
|---|---|---|
| Scope | Per actor | Node-wide |
| Trigger | Idle timeout or message count | Total actors > limit |
| Config | WithPassivationStrategy(strat) at spawn | WithEvictionStrategy(strat, interval) at system creation |
| LongLived | Opts out of per-actor passivation | Does not opt out; can still be evicted |