Package io.grpc.xds
Class WeightedRoundRobinLoadBalancer
java.lang.Object
io.grpc.LoadBalancer
io.grpc.util.MultiChildLoadBalancer
io.grpc.xds.WeightedRoundRobinLoadBalancer
final class WeightedRoundRobinLoadBalancer
extends io.grpc.util.MultiChildLoadBalancer
A
LoadBalancer
that provides weighted-round-robin load-balancing over the
EquivalentAddressGroup
s from the NameResolver
. The subchannel weights are
determined by backend metrics using ORCA.
To use WRR, users may configure through channel serviceConfig. Example config:
String wrrConfig = "{\"loadBalancingConfig\":" +
"[{\"weighted_round_robin\":{\"enableOobLoadReport\":true, " +
"\"blackoutPeriod\":\"10s\"," +
"\"oobReportingPeriod\":\"10s\"," +
"\"weightExpirationPeriod\":\"180s\"," +
"\"errorUtilizationPenalty\":\"1.0\"," +
"\"weightUpdatePeriod\":\"1s\"}}]}";
serviceConfig = (Map<String, ?>) JsonParser.parse(wrrConfig);
channel = ManagedChannelBuilder.forTarget("test:///lb.test.grpc.io")
.defaultServiceConfig(serviceConfig)
.build();
Users may also configure through xDS control plane via custom lb policy. But that is much more
complex to set up. Example config:
localityLbPolicies: - customPolicy: name: weighted_round_robin data: '{ "enableOobLoadReport": true }'See related documentation: https://cloud.google.com/service-mesh/legacy/load-balancing-apis/proxyless-configure-advanced-traffic-management#custom-lb-config
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
private final class
(package private) final class
(package private) static final class
(package private) static final class
(package private) 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 io.grpc.LoadBalancer.SubchannelPicker
private static final io.grpc.LongCounterMetricInstrument
private static final io.grpc.LongCounterMetricInstrument
private static final io.grpc.DoubleHistogramMetricInstrument
private final long
private String
private static final Logger
private static final io.grpc.LongCounterMetricInstrument
private final AtomicInteger
private final io.grpc.SynchronizationContext
private final io.grpc.Deadline.Ticker
private final ScheduledExecutorService
private final Runnable
private io.grpc.SynchronizationContext.ScheduledHandle
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
ConstructorsConstructorDescriptionWeightedRoundRobinLoadBalancer
(io.grpc.LoadBalancer.Helper helper, io.grpc.Deadline.Ticker ticker) WeightedRoundRobinLoadBalancer
(io.grpc.LoadBalancer.Helper helper, io.grpc.Deadline.Ticker ticker, Random random) -
Method Summary
Modifier and TypeMethodDescriptionio.grpc.Status
acceptResolvedAddresses
(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses) private void
protected io.grpc.util.MultiChildLoadBalancer.ChildLbState
createChildLbState
(Object key) private io.grpc.LoadBalancer.SubchannelPicker
createReadyPicker
(Collection<io.grpc.util.MultiChildLoadBalancer.ChildLbState> activeList) void
shutdown()
private void
updateBalancingState
(io.grpc.ConnectivityState state, io.grpc.LoadBalancer.SubchannelPicker picker) protected void
Updates picker with the list of active subchannels (state == READY).private void
Methods inherited from class io.grpc.util.MultiChildLoadBalancer
acceptResolvedAddressesInternal, aggregateState, createChildAddressesMap, getChildLbState, getChildLbStateEag, getChildLbStates, getHelper, getReadyChildren, handleNameResolutionError, shutdownRemoved
Methods inherited from class io.grpc.LoadBalancer
canHandleEmptyAddressListFromNameResolution, handleResolvedAddresses, handleSubchannelState, requestConnection
-
Field Details
-
RR_FALLBACK_COUNTER
private static final io.grpc.LongCounterMetricInstrument RR_FALLBACK_COUNTER -
ENDPOINT_WEIGHT_NOT_YET_USEABLE_COUNTER
private static final io.grpc.LongCounterMetricInstrument ENDPOINT_WEIGHT_NOT_YET_USEABLE_COUNTER -
ENDPOINT_WEIGHT_STALE_COUNTER
private static final io.grpc.LongCounterMetricInstrument ENDPOINT_WEIGHT_STALE_COUNTER -
ENDPOINT_WEIGHTS_HISTOGRAM
private static final io.grpc.DoubleHistogramMetricInstrument ENDPOINT_WEIGHTS_HISTOGRAM -
log
-
config
-
syncContext
private final io.grpc.SynchronizationContext syncContext -
timeService
-
weightUpdateTimer
private io.grpc.SynchronizationContext.ScheduledHandle weightUpdateTimer -
updateWeightTask
-
sequence
-
infTime
private final long infTime -
ticker
private final io.grpc.Deadline.Ticker ticker -
locality
-
currentPicker
private io.grpc.LoadBalancer.SubchannelPicker currentPicker
-
-
Constructor Details
-
WeightedRoundRobinLoadBalancer
public WeightedRoundRobinLoadBalancer(io.grpc.LoadBalancer.Helper helper, io.grpc.Deadline.Ticker ticker) -
WeightedRoundRobinLoadBalancer
WeightedRoundRobinLoadBalancer(io.grpc.LoadBalancer.Helper helper, io.grpc.Deadline.Ticker ticker, Random random)
-
-
Method Details
-
createChildLbState
- Overrides:
createChildLbState
in classio.grpc.util.MultiChildLoadBalancer
-
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).- Specified by:
updateOverallBalancingState
in classio.grpc.util.MultiChildLoadBalancer
-
createReadyPicker
private io.grpc.LoadBalancer.SubchannelPicker createReadyPicker(Collection<io.grpc.util.MultiChildLoadBalancer.ChildLbState> activeList) -
updateWeight
-
updateBalancingState
private void updateBalancingState(io.grpc.ConnectivityState state, io.grpc.LoadBalancer.SubchannelPicker picker) -
createAndApplyOrcaListeners
private void createAndApplyOrcaListeners() -
shutdown
public void shutdown()- Overrides:
shutdown
in classio.grpc.util.MultiChildLoadBalancer
-