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 Summary
FieldsModifier and TypeFieldDescriptionstatic final LoadBalancerConsistent hashing load balancer with 4 virtual servers, falling back to a random load balancer.static final LoadBalancerLoad balancing policy that returns the first server.static final LoadBalancerLeast requests load balancer.static final LoadBalancerPower of two choices load balancer.static final LoadBalancerRandom load balancer.static final LoadBalancerSimple round-robin load balancer. -
Method Summary
Modifier and TypeMethodDescriptionstatic LoadBalancerconsistentHashing(int numberOfVirtualServers, LoadBalancer fallback) Sticky load balancer that uses consistent hashing based on a client provided routing key, defaulting to thefallbackload balancer when no routing key is provided.default InteractionMetrics<?> selector(List<? extends ServerEndpoint> listOfServers) Create a stateful endpoint selector.
-
Field Details
-
ROUND_ROBIN
Simple round-robin load balancer. -
LEAST_REQUESTS
Least requests load balancer. -
RANDOM
Random load balancer. -
POWER_OF_TWO_CHOICES
Power of two choices load balancer. -
CONSISTENT_HASHING
Consistent hashing load balancer with 4 virtual servers, falling back to a random load balancer. -
FIRST
Load balancing policy that returns the first server.
-
-
Method Details
-
newMetrics
- Returns:
- a new interaction metrics instance
-
consistentHashing
Sticky load balancer that uses consistent hashing based on a client provided routing key, defaulting to thefallbackload balancer when no routing key is provided.- Parameters:
numberOfVirtualServers- the number of virtual serversfallback- the fallback load balancer for non-sticky requests- Returns:
- the load balancer
-
selector
Create a stateful endpoint selector.- Parameters:
listOfServers- the list of servers- Returns:
- the selector
-