-
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
RFC: Option 1: config different LB selections policies by inheritance from a base builder #2750
Closed
bryce-anderson
wants to merge
1
commit into
apple:main
from
bryce-anderson:bl_anderson/lb_config_option1
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
servicetalk-loadbalancer/src/main/java/io/servicetalk/loadbalancer/LoadBalancerBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright © 2023 Apple Inc. and the ServiceTalk project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.servicetalk.loadbalancer; | ||
|
||
import io.servicetalk.client.api.LoadBalancedConnection; | ||
import io.servicetalk.client.api.LoadBalancer; | ||
import io.servicetalk.client.api.LoadBalancerFactory; | ||
import io.servicetalk.client.api.ServiceDiscoverer; | ||
import io.servicetalk.concurrent.api.Executor; | ||
|
||
import java.time.Duration; | ||
|
||
public interface LoadBalancerBuilder<ResolvedAddress, C extends LoadBalancedConnection, | ||
T extends LoadBalancerBuilder<ResolvedAddress, C, T>> { | ||
|
||
/** | ||
* This {@link LoadBalancer} may monitor hosts to which connection establishment has failed | ||
* using health checks that run in the background. The health check tries to establish a new connection | ||
* and if it succeeds, the host is returned to the load balancing pool. As long as the connection | ||
* establishment fails, the host is not considered for opening new connections for processed requests. | ||
* If an {@link Executor} is not provided using this method, a default shared instance is used | ||
* for all {@link LoadBalancer LoadBalancers} created by this factory. | ||
* <p> | ||
* {@link #healthCheckFailedConnectionsThreshold(int)} can be used to disable this mechanism and always | ||
* consider all hosts for establishing new connections. | ||
* | ||
* @param backgroundExecutor {@link Executor} on which to schedule health checking. | ||
* @return {@code this}. | ||
* @see #healthCheckFailedConnectionsThreshold(int) | ||
*/ | ||
T backgroundExecutor(Executor backgroundExecutor); | ||
|
||
/** | ||
* Configure an interval for health checking a host that failed to open connections. If no interval is provided | ||
* using this method, a default value will be used. | ||
* <p> | ||
* {@link #healthCheckFailedConnectionsThreshold(int)} can be used to disable the health checking mechanism | ||
* and always consider all hosts for establishing new connections. | ||
* | ||
* @param interval interval at which a background health check will be scheduled. | ||
* @param jitter the amount of jitter to apply to each retry {@code interval}. | ||
* @return {@code this}. | ||
* @see #healthCheckFailedConnectionsThreshold(int) | ||
*/ | ||
T healthCheckInterval(Duration interval, Duration jitter); | ||
|
||
/** | ||
* Configure an interval for re-subscribing to the original events stream in case all existing hosts become | ||
* unhealthy. | ||
* <p> | ||
* In situations when there is a latency between {@link ServiceDiscoverer} propagating the updated state and all | ||
* known hosts become unhealthy, which could happen due to intermediate caching layers, re-subscribe to the | ||
* events stream can help to exit from a dead state. | ||
* <p> | ||
* {@link #healthCheckFailedConnectionsThreshold(int)} can be used to disable the health checking mechanism | ||
* and always consider all hosts for establishing new connections. | ||
* | ||
* @param interval interval at which re-subscribes will be scheduled. | ||
* @param jitter the amount of jitter to apply to each re-subscribe {@code interval}. | ||
* @return {@code this}. | ||
* @see #healthCheckFailedConnectionsThreshold(int) | ||
*/ | ||
T healthCheckResubscribeInterval(Duration interval, Duration jitter); | ||
|
||
/** | ||
* Configure a threshold for consecutive connection failures to a host. When the {@link LoadBalancer} | ||
* consecutively fails to open connections in the amount greater or equal to the specified value, | ||
* the host will be marked as unhealthy and connection establishment will take place in the background | ||
* repeatedly until a connection is established. During that time, the host will not take part in | ||
* load balancing selection. | ||
* <p> | ||
* Use a negative value of the argument to disable health checking. | ||
* | ||
* @param threshold number of consecutive connection failures to consider a host unhealthy and eligible for | ||
* background health checking. Use negative value to disable the health checking mechanism. | ||
* @return {@code this}. | ||
* @see #backgroundExecutor(Executor) | ||
*/ | ||
T healthCheckFailedConnectionsThreshold(int threshold); | ||
|
||
/** | ||
* Builds the {@link LoadBalancerFactory} configured by this builder. | ||
* | ||
* @return a new instance of {@link LoadBalancerFactory} with settings from this builder. | ||
*/ | ||
LoadBalancerFactory<ResolvedAddress, C> build(); | ||
} |
28 changes: 28 additions & 0 deletions
28
...cetalk-loadbalancer/src/main/java/io/servicetalk/loadbalancer/P2CLoadBalancerBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright © 2023 Apple Inc. and the ServiceTalk project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.servicetalk.loadbalancer; | ||
|
||
import io.servicetalk.client.api.LoadBalancedConnection; | ||
|
||
public interface P2CLoadBalancerBuilder<ResolvedAddress, C extends LoadBalancedConnection> { | ||
|
||
/** | ||
* Configure the maximum number of selections attempts before switching to the configured panic selection mode. | ||
* @param maxEffort maximum number of selections attempts before switching to the configured panic selection mode. | ||
* @return {@code this} | ||
*/ | ||
P2CLoadBalancerBuilder<ResolvedAddress, C> maxEffort(int maxEffort); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
💯 agreed, this is the least preferred approach. The main reason is that every
LoadBalancerBuilder
will have to also have a ServiceLoaded provider. With growing number of providers, it makes it harder to control the behavior that way.