algo.LoadBalancer()
Description
Creates an instance of LoadBalancer.
Syntax
new algo.LoadBalancer([...targets])new algo.LoadBalancer([...targets],{algorithm, // 'round-robin' or 'least-load'key: (target) => getTargetKey(target),weight: (target) => getTargetWeight(target),capacity,sessionCache,})
Parameters
new algo.LoadBalancer(targets, options?)
targetsoptions?
An array of targets. Targets can be of any type and carry any information one might need.
Options including:
- algorithm - Can be 'round-robin' or 'least-load'. Defaults to 'round-robin'.
- key - A user-provided callback function that receives a target and returns a unique key representing it.
- weight - A user-provided callback function that receives a target and returns its weight.
- capacity - Maximum number of allocated resources allowed by each target, or a user-provided callback function that receives each target as parameter and returns their respective capacity.
- sessionCache - A user-provided Cache object for storing sticky sessions.
Return Value
A LoadBalancer object with the specified targets and options.