Package io.grpc.xds

Class 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 Classes 
      Modifier and Type Class Description
      (package private) static class  LeastRequestLoadBalancer.EmptyPicker  
      (package private) static class  LeastRequestLoadBalancer.LeastRequestConfig  
      protected class  LeastRequestLoadBalancer.LeastRequestLbState  
      private static class  LeastRequestLoadBalancer.OutstandingRequestsTracingFactory  
      (package private) static class  LeastRequestLoadBalancer.ReadyPicker  
      • 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

      Fields 
      Modifier and Type Field Description
      private int choiceCount  
      private io.grpc.LoadBalancer.SubchannelPicker currentPicker  
      private ThreadSafeRandom random  
      • 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
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      io.grpc.Status acceptResolvedAddresses​(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses)  
      protected io.grpc.util.MultiChildLoadBalancer.ChildLbState createChildLbState​(java.lang.Object key)  
      private static java.util.concurrent.atomic.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 updateOverallBalancingState()
      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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • currentPicker

        private io.grpc.LoadBalancer.SubchannelPicker currentPicker
      • choiceCount

        private int choiceCount
    • Constructor Detail

      • LeastRequestLoadBalancer

        LeastRequestLoadBalancer​(io.grpc.LoadBalancer.Helper helper)
      • LeastRequestLoadBalancer

        LeastRequestLoadBalancer​(io.grpc.LoadBalancer.Helper helper,
                                 ThreadSafeRandom random)
    • Method Detail

      • acceptResolvedAddresses

        public io.grpc.Status acceptResolvedAddresses​(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses)
        Overrides:
        acceptResolvedAddresses in class io.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 class io.grpc.util.MultiChildLoadBalancer
      • createChildLbState

        protected io.grpc.util.MultiChildLoadBalancer.ChildLbState createChildLbState​(java.lang.Object key)
        Overrides:
        createChildLbState in class io.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 java.util.concurrent.atomic.AtomicInteger getInFlights​(io.grpc.util.MultiChildLoadBalancer.ChildLbState childLbState)