You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Akka exposes a small set of ops-oriented commands on ShardRegion that let operators / dashboards inspect and influence shard state:
StartEntity(entityId) — explicitly activate an entity. Use case: pre-warm hot entities at startup, or recover an entity that was passivated but whose data needs to be live before the next request.
GetShardStats — ask one region for its per-shard stats (entity count per shard). Use case: per-node monitoring dashboard.
GetClusterShardingStats — ask the coordinator for cluster-wide per-shard stats (which shards live where, how many entities each holds). Use case: cluster-wide dashboard, capacity planning.
actor-ts has the internal state these would expose — ShardRegion knows its entities-per-shard, ShardCoordinator knows the cluster-wide allocation map. There's no public command surface to query them. Operators have to add custom message types per app + plumb them through.
Promoting these to first-class, documented public commands closes a small but real ops gap.
// src/cluster/sharding/ShardCommands.ts (new file)/** Explicitly activate an entity. No reply. Fire-and-forget. */exportclassStartEntity{constructor(publicreadonlyentityId: string){}}/** Ask one ShardRegion for its per-shard entity counts. */exportclassGetShardRegionStats{// marker — no fields}exportclassShardRegionStats{constructor(/** Map<shardId, entity count in that shard on this region>. */publicreadonlyshards: ReadonlyMap<number,number>,/** Failed shards (allocation pending or in-flight failure). */publicreadonlyfailedShards: ReadonlyMap<number,string>,){}}/** Ask the coordinator for cluster-wide per-region stats. */exportclassGetClusterShardingStats{constructor(publicreadonlytimeoutMs: number=5_000){}}exportclassClusterShardingStats{constructor(/** Map<region-address-string, ShardRegionStats>. */publicreadonlyregions: ReadonlyMap<string,ShardRegionStats>,){}}
ShardRegion: existing onReceive chain gets new arms for StartEntity, GetShardRegionStats. Already tracks entities-per-shard internally; new code wraps it up as ShardRegionStats.
ShardCoordinator: existing coordinator tracks the allocation map (region → shards). For GetClusterShardingStats, the coordinator broadcasts GetShardRegionStats to every region, collects responses with a timeout, returns aggregated ClusterShardingStats.
Entity-level introspection (GetEntityStats(entityId) returning mailbox-depth, message count): out of scope; that's a deeper observability item (track separately if demand).
Restart-all-entities command: out of scope; users can passivate-all then trigger natural re-activation.
StartEntity reply: Akka returns no reply (fire-and-forget). Some apps want confirmation. Add optional replyTo: ActorRef<EntityStarted> field? Recommend: stay no-reply for parity; users that want confirmation can ask the entity itself afterward.
ShardRegionStats.failedShards: include shards stuck in allocation-pending state? Useful for ops; adds a small extra map. Recommend: yes.
GetClusterShardingStats timeout: what happens if some regions don't respond within timeoutMs? Return partial results with a missingRegions set, or fail entirely? Recommend partial + missing set.
Persistence interaction with StartEntity: starting an entity loads its persistence state — same as any other message. Document this explicitly so users don't expect it to be free.
Test plan
StartEntity activates — region with 0 entities; tell StartEntity('foo'); verify entity actor exists in region's child set.
StartEntity on already-active is no-op — second tell doesn't double-activate; no error.
GetShardRegionStats accurate — region with entities in shards 1, 2, 5; ask returns map {1: N1, 2: N2, 5: N5}.
GetShardRegionStats empty region — region with no entities; ask returns empty map.
GetClusterShardingStats aggregates — 3 regions each with entities; ask coordinator; returns merged stats with all 3 regions present.
GetClusterShardingStats partial on timeout — 1 of 3 regions unresponsive; ask returns 2 regions + 1 missing.
HTTP endpoint — GET /actor-ts/cluster/sharding/Counter/stats returns JSON with expected shape.
Regression — existing sharding tests pass.
Acceptance criteria
StartEntity, GetShardRegionStats, ShardRegionStats, GetClusterShardingStats, ClusterShardingStats exported from src/cluster/sharding/.
ShardRegion.onReceive handles the new commands.
ShardCoordinator.onReceive handles GetClusterShardingStats with the fan-out + aggregate flow.
HTTP endpoint GET /actor-ts/cluster/sharding/{typeName}/stats.
Size / Priority
StartEntity,GetShardStats,GetClusterShardingStats).Rationale
Akka exposes a small set of ops-oriented commands on
ShardRegionthat let operators / dashboards inspect and influence shard state:StartEntity(entityId)— explicitly activate an entity. Use case: pre-warm hot entities at startup, or recover an entity that was passivated but whose data needs to be live before the next request.GetShardStats— ask one region for its per-shard stats (entity count per shard). Use case: per-node monitoring dashboard.GetClusterShardingStats— ask the coordinator for cluster-wide per-shard stats (which shards live where, how many entities each holds). Use case: cluster-wide dashboard, capacity planning.actor-ts has the internal state these would expose —
ShardRegionknows its entities-per-shard,ShardCoordinatorknows the cluster-wide allocation map. There's no public command surface to query them. Operators have to add custom message types per app + plumb them through.Promoting these to first-class, documented public commands closes a small but real ops gap.
Reference: what Akka does
Design sketch — actor-ts equivalents
Usage:
Integration with existing actor-ts subsystems
ShardRegion: existingonReceivechain gets new arms forStartEntity,GetShardRegionStats. Already tracks entities-per-shard internally; new code wraps it up asShardRegionStats.ShardCoordinator: existing coordinator tracks the allocation map (region → shards). ForGetClusterShardingStats, the coordinator broadcastsGetShardRegionStatsto every region, collects responses with a timeout, returns aggregatedClusterShardingStats.GET /actor-ts/cluster/sharding/{typeName}/statsreturnsClusterShardingStatsas JSON.Out of scope / non-goals
GetEntityStats(entityId)returning mailbox-depth, message count): out of scope; that's a deeper observability item (track separately if demand).MoveShard(shardId, targetRegion)): out of scope; that's the manual rebalance API in [Feature] External shard allocation + manual rebalance API #150.Open design questions
StartEntityreply: Akka returns no reply (fire-and-forget). Some apps want confirmation. Add optionalreplyTo: ActorRef<EntityStarted>field? Recommend: stay no-reply for parity; users that want confirmation can ask the entity itself afterward.ShardRegionStats.failedShards: include shards stuck in allocation-pending state? Useful for ops; adds a small extra map. Recommend: yes.GetClusterShardingStatstimeout: what happens if some regions don't respond withintimeoutMs? Return partial results with amissingRegionsset, or fail entirely? Recommend partial + missing set.StartEntity: starting an entity loads its persistence state — same as any other message. Document this explicitly so users don't expect it to be free.Test plan
StartEntityactivates — region with 0 entities; tellStartEntity('foo'); verify entity actor exists in region's child set.StartEntityon already-active is no-op — second tell doesn't double-activate; no error.GetShardRegionStatsaccurate — region with entities in shards 1, 2, 5; ask returns map{1: N1, 2: N2, 5: N5}.GetShardRegionStatsempty region — region with no entities; ask returns empty map.GetClusterShardingStatsaggregates — 3 regions each with entities; ask coordinator; returns merged stats with all 3 regions present.GetClusterShardingStatspartial on timeout — 1 of 3 regions unresponsive; ask returns 2 regions + 1 missing.GET /actor-ts/cluster/sharding/Counter/statsreturns JSON with expected shape.Acceptance criteria
StartEntity,GetShardRegionStats,ShardRegionStats,GetClusterShardingStats,ClusterShardingStatsexported fromsrc/cluster/sharding/.ShardRegion.onReceivehandles the new commands.ShardCoordinator.onReceivehandlesGetClusterShardingStatswith the fan-out + aggregate flow.GET /actor-ts/cluster/sharding/{typeName}/stats.