Class MinLoadFactorTrafficLoadBalancer

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

public class MinLoadFactorTrafficLoadBalancer extends Object implements 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
  • 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 load factor.
      See Also:
  • Constructor Details

    • MinLoadFactorTrafficLoadBalancer

      public MinLoadFactorTrafficLoadBalancer(Collection<HttpServiceInstance> instances)

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

      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