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 classprotected classprivate static final class(package private) static final classNested classes/interfaces inherited from class io.grpc.util.MultiChildLoadBalancer
io.grpc.util.MultiChildLoadBalancer.AcceptResolvedAddrRetVal, io.grpc.util.MultiChildLoadBalancer.ChildLbState, io.grpc.util.MultiChildLoadBalancer.EndpointNested 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 intprivate io.grpc.LoadBalancer.SubchannelPickerprivate final ThreadSafeRandomFields inherited from class io.grpc.util.MultiChildLoadBalancer
currentConnectivityState, pickFirstLbProvider, resolvingAddressesFields 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.StatusacceptResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses) protected io.grpc.util.MultiChildLoadBalancer.ChildLbStatecreateChildLbState(Object key) private static AtomicIntegergetInFlights(io.grpc.util.MultiChildLoadBalancer.ChildLbState childLbState) (package private) voidsetResolvingAddresses(boolean newValue) This should ONLY be used by tests.private voidupdateBalancingState(io.grpc.ConnectivityState state, io.grpc.LoadBalancer.SubchannelPicker picker) protected voidUpdates 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, shutdownRemovedMethods 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:
acceptResolvedAddressesin 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:
updateOverallBalancingStatein classio.grpc.util.MultiChildLoadBalancer
-
createChildLbState
- Overrides:
createChildLbStatein 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)
-