-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
loadbalancer: add builder for the DefaultLoadBalancer #2749
loadbalancer: add builder for the DefaultLoadBalancer #2749
Conversation
/** | ||
* Definition of the selector mechanism used for load balancing. | ||
*/ | ||
public interface LoadBalancingPolicy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for going forward with this approach, this is more aligned with other use-cases, like configuring different HTTP protocol versions on client/server builder and makes it easier to manage externally via ServiceLoader providers if there is only one LB builder with only one provider.
Not now, but in the future we may need to add a "selector" as a method on LoadBalancingPolicy
to let users implement their own selectors. For now, +1 for keeping that detail pkg-private.
|
||
import java.time.Duration; | ||
|
||
public interface LoadBalancerBuilder<ResolvedAddress, C extends LoadBalancedConnection> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need an interface for a builder, vs a concrete class? Will we need this interface internally? Often times concrete builders may have different ways to configure themselves and may not needs the same options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, interface is helpful when we add support for ServiceLoader providers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@idelpivnitskiy, couldn't we do something like the RoundRobinLoadBalancers
strategy? We could make it a concrete class, make the constructor private, then funneling all builder(String id)
's through the providers that get first dibs to set defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a commit that seems along the lines of what @Scottmitch is suggesting. I like it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a simplistic approach that we use for cases, when we don't need a ServiceLoader provider, like RedirectConfigBuilder, ProxyConfigBuilder, H1ProtocolConfigBuilder, etc. For major objects, like client/server builder, DnsServiceDiscovererBuilder, LB builder it's extremely useful to have access through providers. Providers require them to be interfaces bcz users need to be able to wrap a builder. Wrapper monitors what users set on the builder explicitly and at the build time can modify or add if users missed something. See simple examples in HttpProvidersTest
.
+1 for this approach We discussed offline, just to keep everything in one place:
|
Thanks for the feedback everyone. This seems like the path we want to take so I'm rounding it out now. It's also going to be pretty big so I'm pulling smaller chunks out as smaller PR's for easier reviewing. |
@Test | ||
void hostDownDoesntCloseConnectionCloseLB() throws Exception { | ||
hostDownDoesntCloseConnection(false); | ||
} | ||
|
||
@Test | ||
void hostDownDoesntCloseConnectionCloseLBGracefully() throws Exception { | ||
hostDownDoesntCloseConnection(true); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests were moved to LingeringLoadBalancerTest
.
@Test | ||
void duplicateEventsAreIgnored() { | ||
assertThat(lb.usedAddresses(), is(empty())); | ||
|
||
sendServiceDiscoveryEvents(upEvent("address-1")); | ||
assertThat(lb.usedAddresses(), hasSize(1)); | ||
sendServiceDiscoveryEvents(upEvent("address-1")); | ||
assertThat(lb.usedAddresses(), hasSize(1)); | ||
|
||
sendServiceDiscoveryEvents(downEvent("address-1")); | ||
assertThat(lb.usedAddresses(), hasSize(0)); | ||
sendServiceDiscoveryEvents(downEvent("address-1")); | ||
assertThat(lb.usedAddresses(), hasSize(0)); | ||
} | ||
|
||
@Test | ||
void handleDiscoveryEvents() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests were all moved to EagerLoadBalancerTest
so they can be shared.
servicetalk-loadbalancer/src/main/java/io/servicetalk/loadbalancer/LoadBalancingPolicies.java
Outdated
Show resolved
Hide resolved
abstract class EagerLoadBalancerTest extends LoadBalancerTest { | ||
|
||
@Test | ||
void duplicateEventsAreIgnored() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests were moved from EagerRoundRobinLoadBalancerTest.java to here.
abstract class LingeringLoadBalancerTest extends LoadBalancerTest { | ||
|
||
@Test | ||
void hostDownDoesntCloseConnectionCloseLB() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests were moved from LingeringRoundRobinLoadBalancerTest.java.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Motivation:
We have a P2C selector but no easy way to use it.
Modifications: