You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add LoadBalancer for generalizing EndpointSelector (#5779)
Motivation:
A load-balancing strategy such as round robin can be used in `EndpointSelector` and elsewhere. For example, in the event loop scheduler, requests can be distributed using round robin to determine which event loop to use.
This PR is preliminary work to resolve#5289 and #5537
Modifications:
- `LoadBalancer<T, C>` is the root interface all load balancers should implement.
- `T` is the type of a candidate selected by strategies.
- `C` is the type of context that is used when selecting a candidate.
- `UpdatableLoadBalancer<T, C>` is a stateful load balancer to which new endpoints are updated. `RampingUpLoadBalancer` is the only implementation for `UpdatableLoadBalancer`. Other load balances will be re-created when new endpoints are added because they can always be reconstructed for the same results.
- `Weighted` is a new API that represents the weight of an object.
- If an object is `Weighted`, a weight function is not necessary when creating weighted-based load balancers.
- `Endpoint` now implements `Weighted`.
- `EndpointSelectionStategy` uses `DefaultEndpointSelector` to create a `LoadBalancer<Endpoint, ClientRequestContext>` internally and delegates the selection logic to it.
- Each `EndpointSelectionStategy` implements `LoadBalancerFactory` to update the existing `LoadBalancer` or create a new `LoadBalancer` when endpoints are updated.
- The following implementations are migrated from `**Strategy`. Except for `RampingUpLoadBalancer` which has some minor changes, most of the logic was ported as is.
- `RampingUpLoadBalancer`
- `Weight` prefix is dropped for simplicity. There may be no problem conveying the behavior.
- Refactored to use a lock to guarantee thread-safety and sequential access.
- A `RampingUpLoadBalancer` is now created from a list of candidates. If an executor is used to build the initial state, null is returned right after it is created.
- `AbstractRampingUpLoadBalancerBuilder` is added to share common code for `RampingUpLoadBalancerBuilder` and `WeightRampingUpStrategyBuilder`
- Fixed xDS implementations to use the new API when implementing load balancing strategies.
- Deprecation) `EndpointWeightTransition` in favor of `WeightTransition`
Result:
- You can now create `LoadBalancer` using various load balancing strategies to select an element from a list of candidates.
```java
List<Endpoint> candidates = ...;
LoadBalancer.ofRoundRobin(candidates);
LoadBalancer.ofWeightedRoundRobin(candidates);
LoadBalancer.ofSticky(candidates, contextHasher);
LoadBalancer.ofWeightedRandom(candidates);
LoadBalancer.ofRampingUp(candidates);
```
0 commit comments