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.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new LeastShardAllocationStrategy(
rebalanceThreshold?,maxSimultaneousRebalance?):LeastShardAllocationStrategy
Defined in: src/cluster/sharding/AllocationStrategy.ts:71
Parameters
Section titled “Parameters”rebalanceThreshold?
Section titled “rebalanceThreshold?”number = 1
maxSimultaneousRebalance?
Section titled “maxSimultaneousRebalance?”number = 3
Returns
Section titled “Returns”LeastShardAllocationStrategy
Properties
Section titled “Properties”maxSimultaneousRebalance
Section titled “maxSimultaneousRebalance”
readonlymaxSimultaneousRebalance:number=3
Defined in: src/cluster/sharding/AllocationStrategy.ts:73
rebalanceThreshold
Section titled “rebalanceThreshold”
readonlyrebalanceThreshold:number=1
Defined in: src/cluster/sharding/AllocationStrategy.ts:72
Methods
Section titled “Methods”allocate()
Section titled “allocate()”allocate(
_shardId,candidates,currentShards):NodeAddress
Defined in: src/cluster/sharding/AllocationStrategy.ts:76
Pick an owner for a newly-discovered shard.
Parameters
Section titled “Parameters”_shardId
Section titled “_shardId”number
candidates
Section titled “candidates”readonly NodeAddress[]
currentShards
Section titled “currentShards”ReadonlyMap<string, ReadonlySet<number>>
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”rebalance()
Section titled “rebalance()”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.
Parameters
Section titled “Parameters”currentShards
Section titled “currentShards”ReadonlyMap<string, ReadonlySet<number>>
candidates
Section titled “candidates”readonly NodeAddress[]
rebalanceInProgress
Section titled “rebalanceInProgress”ReadonlySet<number>
Returns
Section titled “Returns”Set<number>