Class MinLoadFactorTrafficLoadBalancer
- All Implemented Interfaces:
TrafficLoadBalancer<HttpServiceInstance,
UnboundExchange<?>>
An HTTP traffic load balancer that selects the service instance with the minimum load factor from a random subset of instances.
In order to select a service instance, the load balancer first selects getChoiceCount()
instances and calculates a score for each of them based on the following formula:
score = instance_weight * (1 - instance_load_factor) ^ bias
The getBias()
is used to increase the importance of the load factor: the greater it is, the more instances with lower load factor are selected.
The instance with the highest score is eventually then selected.
- Since:
- 1.12
- Author:
- Jeremy Kuhn
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A minimum load factor traffic load balancer factory. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default bias on load factor.static final int
The default choice count. -
Constructor Summary
ConstructorDescriptionCreates a minimum load factor traffic load balancer.MinLoadFactorTrafficLoadBalancer
(Collection<HttpServiceInstance> instances, int choiceCount, int bias) Creates a minimum load factor traffic load balancer. -
Method Summary
Modifier and TypeMethodDescriptionint
getBias()
Returns the load factor bias used to increase the importance of load factor when selecting an instance.int
Returns the number of service instances to consider when selecting an instance.next
(UnboundExchange<?> serviceRequest) Returns the next service instance to use to process the specified service request.
-
Field Details
-
DEFAULT_CHOICE_COUNT
public static final int DEFAULT_CHOICE_COUNTThe default choice count.- See Also:
-
DEFAULT_BIAS
public static final int DEFAULT_BIASThe default bias on load factor.- See Also:
-
-
Constructor Details
-
MinLoadFactorTrafficLoadBalancer
Creates a minimum load factor traffic load balancer.
- Parameters:
instances
- a collection of HTTP service instances
-
MinLoadFactorTrafficLoadBalancer
public MinLoadFactorTrafficLoadBalancer(Collection<HttpServiceInstance> instances, int choiceCount, int bias) Creates a minimum load factor traffic load balancer.
- Parameters:
instances
- a collection of HTTP service instanceschoiceCount
- the choice countbias
- the bias on load factor
-
-
Method Details
-
getChoiceCount
public int getChoiceCount()Returns the number of service instances to consider when selecting an instance.
- Returns:
- the choice count
-
getBias
public int getBias()Returns the load factor bias used to increase the importance of load factor when selecting an instance.
The greater it is, the more instances with lower load factor are selected.
- Returns:
- the load factor bias
-
next
Description copied from interface:TrafficLoadBalancer
Returns the next service instance to use to process the specified service request.
- Specified by:
next
in interfaceTrafficLoadBalancer<HttpServiceInstance,
UnboundExchange<?>> - Parameters:
serviceRequest
- a service request- Returns:
- a
Mono
emitting the next service instance
-