Skip to content

LeastShardAllocationStrategy

Defined in: src/cluster/sharding/AllocationStrategy.ts:70

Pick the candidate currently hosting the fewest shards, breaking ties by address order. Over time this converges to a balanced distribution even if the candidate set has changed repeatedly.

Minimum difference between the most- and least-loaded nodes before any shards are moved. Avoids thrashing.

Cap on how many shards move in a single rebalance round.

new LeastShardAllocationStrategy(rebalanceThreshold?, maxSimultaneousRebalance?): LeastShardAllocationStrategy

Defined in: src/cluster/sharding/AllocationStrategy.ts:71

number = 1

number = 3

LeastShardAllocationStrategy

readonly maxSimultaneousRebalance: number = 3

Defined in: src/cluster/sharding/AllocationStrategy.ts:73


readonly rebalanceThreshold: number = 1

Defined in: src/cluster/sharding/AllocationStrategy.ts:72

allocate(_shardId, candidates, currentShards): NodeAddress

Defined in: src/cluster/sharding/AllocationStrategy.ts:76

Pick an owner for a newly-discovered shard.

number

readonly NodeAddress[]

ReadonlyMap<string, ReadonlySet<number>>

NodeAddress

AllocationStrategy.allocate


rebalance(currentShards, candidates, rebalanceInProgress): Set<number>

Defined in: src/cluster/sharding/AllocationStrategy.ts:93

Return a set of shard ids that should be re-homed. The coordinator will send HandOff for each and then allocate() a new home once the handoff completes.

ReadonlyMap<string, ReadonlySet<number>>

readonly NodeAddress[]

ReadonlySet<number>

Set<number>

AllocationStrategy.rebalance