Class PowerOfTwoChoicesLoadBalancer
- java.lang.Object
-
- io.smallrye.stork.loadbalancer.poweroftwochoices.PowerOfTwoChoicesLoadBalancer
-
- All Implemented Interfaces:
LoadBalancer
public class PowerOfTwoChoicesLoadBalancer extends Object implements LoadBalancer
Select two random destinations and then select the one with the least assigned requests. This avoids the overhead of least-requests and the worst case for random where it selects a busy destination.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedPowerOfTwoChoicesLoadBalancer(boolean useSecureRandom)Creates a new instance of PowerOfTwoChoicesLoadBalancer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanrequiresStrictRecording()ServiceInstanceselectServiceInstance(Collection<ServiceInstance> serviceInstances)
-
-
-
Constructor Detail
-
PowerOfTwoChoicesLoadBalancer
protected PowerOfTwoChoicesLoadBalancer(boolean useSecureRandom)
Creates a new instance of PowerOfTwoChoicesLoadBalancer.- Parameters:
useSecureRandom-trueto use aSecureRandominstead of a regularRandom
-
-
Method Detail
-
selectServiceInstance
public ServiceInstance selectServiceInstance(Collection<ServiceInstance> serviceInstances)
- Specified by:
selectServiceInstancein interfaceLoadBalancer
-
requiresStrictRecording
public boolean requiresStrictRecording()
- Specified by:
requiresStrictRecordingin interfaceLoadBalancer
-
-