Class LeastRequestTrafficLoadBalancer

java.lang.Object
io.inverno.mod.discovery.http.LeastRequestTrafficLoadBalancer
All Implemented Interfaces:
TrafficLoadBalancer<HttpServiceInstance,UnboundExchange<?>>

public class LeastRequestTrafficLoadBalancer extends Object implements 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
  • Field Details

    • DEFAULT_CHOICE_COUNT

      public static final int DEFAULT_CHOICE_COUNT
      The default choice count.
      See Also:
    • DEFAULT_BIAS

      public static final int DEFAULT_BIAS
      The default bias on active requests.
      See Also:
  • Constructor Details

    • LeastRequestTrafficLoadBalancer

      public LeastRequestTrafficLoadBalancer(Collection<HttpServiceInstance> weightedInstances)

      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 instances
      choiceCount - the choice count
      bias - 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

      public Mono<HttpServiceInstance> next(UnboundExchange<?> serviceRequest)
      Description copied from interface: TrafficLoadBalancer

      Returns the next service instance to use to process the specified service request.

      Specified by:
      next in interface TrafficLoadBalancer<HttpServiceInstance,UnboundExchange<?>>
      Parameters:
      serviceRequest - a service request
      Returns:
      a Mono emitting the next service instance