Skip to content

Cluster Sharding LRU passivation policy #82

@pathosDev

Description

@pathosDev

`ClusterSharding` (#35) supports explicit `Passivate` — an entity sends itself a passivation message to gracefully evict from memory. Akka also offers an automatic policy: when a shard reaches `maxEntities`, the least-recently-used entity is auto-passivated.

Useful for workloads where the entity set is unbounded (e.g. user-id-keyed entities for millions of users) and you want a memory cap per node.

Scope:

  • New shard config: `maxEntities: number` (default unlimited). When set, an LRU eviction policy is enabled.
  • Each entity tracks last-active-timestamp (mailbox dequeue updates it).
  • When new entity is created and the count would exceed `maxEntities`, the oldest is sent the same passivation message users send manually.
  • After passivation completes, room is freed for the new one.

Out of scope: size-based eviction (eviction by entity-state byte-count) — different mechanism, can be follow-up.

Tests:

  • Spawn N+5 entities with `maxEntities=N`; verify oldest 5 were passivated.
  • Send a message to a passivated entity → it's recreated from journal/snapshot.

Estimate: 2-3 days.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions