Interface LoadBalancer


@Unstable public interface LoadBalancer
A load balancer.

A load balancer is stateless besides the configuration part. Effective load balancing can be achieved with selector(List) which creates a stateful ServerSelector implementing the load balancing algorithm.

Author:
Julien Viet
  • Field Details

    • ROUND_ROBIN

      static final LoadBalancer ROUND_ROBIN
      Simple round-robin load balancer.
    • LEAST_REQUESTS

      static final LoadBalancer LEAST_REQUESTS
      Least requests load balancer.
    • RANDOM

      static final LoadBalancer RANDOM
      Random load balancer.
    • POWER_OF_TWO_CHOICES

      static final LoadBalancer POWER_OF_TWO_CHOICES
      Power of two choices load balancer.
    • CONSISTENT_HASHING

      static final LoadBalancer CONSISTENT_HASHING
      Consistent hashing load balancer with 4 virtual servers, falling back to a random load balancer.
    • FIRST

      static final LoadBalancer FIRST
      Load balancing policy that returns the first server.
  • Method Details

    • newMetrics

      default InteractionMetrics<?> newMetrics()
      Returns:
      a new interaction metrics instance
    • consistentHashing

      static LoadBalancer consistentHashing(int numberOfVirtualServers, LoadBalancer fallback)
      Sticky load balancer that uses consistent hashing based on a client provided routing key, defaulting to the fallback load balancer when no routing key is provided.
      Parameters:
      numberOfVirtualServers - the number of virtual servers
      fallback - the fallback load balancer for non-sticky requests
      Returns:
      the load balancer
    • selector

      ServerSelector selector(List<? extends ServerEndpoint> listOfServers)
      Create a stateful endpoint selector.
      Parameters:
      listOfServers - the list of servers
      Returns:
      the selector