Class LeastRequestTrafficLoadBalancer
- All Implemented Interfaces:
TrafficLoadBalancer<HttpServiceInstance,
UnboundExchange<?>>
An HTTP traffic load balancer that selects the service instance with the least current active requests from a random subset of instances.
In order to select a service instance, the load balancer first selects getChoiceCount()
instances and calculates a score to each of them based on the following formula:
score = instance_weight / (instance_active_requests + 1) ^ bias
The getBias()
is used to increase the importance of active requests: the greater it is, the more instances with lower active requests count 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 Least request traffic load balancer factory. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default bias on active requests.static final int
The default choice count. -
Constructor Summary
ConstructorDescriptionLeastRequestTrafficLoadBalancer
(Collection<HttpServiceInstance> weightedInstances) Creates a least request traffic load balancer.LeastRequestTrafficLoadBalancer
(Collection<HttpServiceInstance> weightedInstances, int choiceCount, int bias) Creates a least request traffic load balancer with the specified choice count and active request bias. -
Method Summary
Modifier and TypeMethodDescriptionint
getBias()
Returns the active requests bias used to increase the importance of active requests 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 active requests.- See Also:
-
-
Constructor Details
-
LeastRequestTrafficLoadBalancer
Creates a least request traffic load balancer.
- Parameters:
weightedInstances
- a collection of HTTP service instances
-
LeastRequestTrafficLoadBalancer
public LeastRequestTrafficLoadBalancer(Collection<HttpServiceInstance> weightedInstances, int choiceCount, int bias) Creates a least request traffic load balancer with the specified choice count and active request bias.
- Parameters:
weightedInstances
- a collection of weighted instanceschoiceCount
- the choice countbias
- the bias on active requests
-
-
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 active requests bias used to increase the importance of active requests when selecting an instance.
The greater it is, the more instances with lower active requests count are selected.
- Returns:
- the active requests 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
-