Package io.grpc.xds
Class LeastRequestLoadBalancer
java.lang.Object
io.grpc.LoadBalancer
io.grpc.util.MultiChildLoadBalancer
io.grpc.xds.LeastRequestLoadBalancer
final class LeastRequestLoadBalancer
extends io.grpc.util.MultiChildLoadBalancer
A
LoadBalancer
that provides least request load balancing based on
outstanding request counters.
It works by sampling a number of subchannels and picking the one with the
fewest amount of outstanding requests.
The default sampling amount of two is also known as
the "power of two choices" (P2C).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
(package private) static final class
protected class
private static final class
(package private) static final class
Nested classes/interfaces inherited from class io.grpc.util.MultiChildLoadBalancer
io.grpc.util.MultiChildLoadBalancer.AcceptResolvedAddrRetVal, io.grpc.util.MultiChildLoadBalancer.ChildLbState, io.grpc.util.MultiChildLoadBalancer.Endpoint
Nested classes/interfaces inherited from class io.grpc.LoadBalancer
io.grpc.LoadBalancer.CreateSubchannelArgs, io.grpc.LoadBalancer.ErrorPicker, io.grpc.LoadBalancer.Factory, io.grpc.LoadBalancer.FixedResultPicker, io.grpc.LoadBalancer.Helper, io.grpc.LoadBalancer.PickDetailsConsumer, io.grpc.LoadBalancer.PickResult, io.grpc.LoadBalancer.PickSubchannelArgs, io.grpc.LoadBalancer.ResolvedAddresses, io.grpc.LoadBalancer.Subchannel, io.grpc.LoadBalancer.SubchannelPicker, io.grpc.LoadBalancer.SubchannelStateListener
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private io.grpc.LoadBalancer.SubchannelPicker
private final ThreadSafeRandom
Fields inherited from class io.grpc.util.MultiChildLoadBalancer
currentConnectivityState, pickFirstLbProvider, resolvingAddresses
Fields inherited from class io.grpc.LoadBalancer
ATTR_HEALTH_CHECKING_CONFIG, DISABLE_SUBCHANNEL_RECONNECT_KEY, EMPTY_PICKER, HAS_HEALTH_PRODUCER_LISTENER_KEY, HEALTH_CONSUMER_LISTENER_ARG_KEY, IS_PETIOLE_POLICY
-
Constructor Summary
ConstructorsConstructorDescriptionLeastRequestLoadBalancer
(io.grpc.LoadBalancer.Helper helper) LeastRequestLoadBalancer
(io.grpc.LoadBalancer.Helper helper, ThreadSafeRandom random) -
Method Summary
Modifier and TypeMethodDescriptionio.grpc.Status
acceptResolvedAddresses
(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses) protected io.grpc.util.MultiChildLoadBalancer.ChildLbState
createChildLbState
(Object key) private static AtomicInteger
getInFlights
(io.grpc.util.MultiChildLoadBalancer.ChildLbState childLbState) (package private) void
setResolvingAddresses
(boolean newValue) This should ONLY be used by tests.private void
updateBalancingState
(io.grpc.ConnectivityState state, io.grpc.LoadBalancer.SubchannelPicker picker) protected void
Updates picker with the list of active subchannels (state == READY).Methods inherited from class io.grpc.util.MultiChildLoadBalancer
acceptResolvedAddressesInternal, aggregateState, createChildAddressesMap, getChildLbState, getChildLbStateEag, getChildLbStates, getHelper, getReadyChildren, handleNameResolutionError, shutdown, shutdownRemoved
Methods inherited from class io.grpc.LoadBalancer
canHandleEmptyAddressListFromNameResolution, handleResolvedAddresses, handleSubchannelState, requestConnection
-
Field Details
-
random
-
currentPicker
private io.grpc.LoadBalancer.SubchannelPicker currentPicker -
choiceCount
private int choiceCount
-
-
Constructor Details
-
LeastRequestLoadBalancer
LeastRequestLoadBalancer(io.grpc.LoadBalancer.Helper helper) -
LeastRequestLoadBalancer
LeastRequestLoadBalancer(io.grpc.LoadBalancer.Helper helper, ThreadSafeRandom random)
-
-
Method Details
-
acceptResolvedAddresses
public io.grpc.Status acceptResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses) - Overrides:
acceptResolvedAddresses
in classio.grpc.util.MultiChildLoadBalancer
-
updateOverallBalancingState
protected void updateOverallBalancingState()Updates picker with the list of active subchannels (state == READY).If no active subchannels exist, but some are in TRANSIENT_FAILURE then returns a picker with all of the children in TF so that the application code will get an error from a varying random one when it tries to get a subchannel.
- Specified by:
updateOverallBalancingState
in classio.grpc.util.MultiChildLoadBalancer
-
createChildLbState
- Overrides:
createChildLbState
in classio.grpc.util.MultiChildLoadBalancer
-
updateBalancingState
private void updateBalancingState(io.grpc.ConnectivityState state, io.grpc.LoadBalancer.SubchannelPicker picker) -
setResolvingAddresses
void setResolvingAddresses(boolean newValue) This should ONLY be used by tests. -
getInFlights
private static AtomicInteger getInFlights(io.grpc.util.MultiChildLoadBalancer.ChildLbState childLbState)
-