Skip to content
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 an observer pattern to DefaultLoadBalancer #2770

Merged

Conversation

bryce-anderson
Copy link
Contributor

@bryce-anderson bryce-anderson commented Dec 5, 2023

Motivation:

With a more interesting load balancer we're going to want
more visibility into what is happening.

Modifications:

Add an observer interface to thread to the load balancer.
This interface has a sub-interface for host concerns and we
can add more sub-interfaces as we continue to break parts
down.

import java.util.function.Function;
import javax.annotation.Nullable;

class TestConnectionFactory implements
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was extracted from LoadBalancerTest.

import static io.servicetalk.concurrent.api.Single.failed;
import static java.util.concurrent.TimeUnit.SECONDS;

class UnhealthyHostConnectionFactory {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was extracted from LoadBalancerTest.

@bryce-anderson bryce-anderson marked this pull request as ready for review December 8, 2023 22:43
Comment on lines +155 to +158
// TODO: do we need to signal closed for this host? Why isn't it closed? The
// closing should probably be re-worked to funnel closing behavior through one place
// and also define what being closed means: just the host isn't used anymore for new
// requests/connections or does it also mean that all connections have closed?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a bug but not one that I want to address here. I think there will be a bit more massaging in DefaultHost now that we have SequentialExecutor and can probably extract the outlier detector and let it synchronously read host state so long as it's within the executor.

* An observer that provides visibility into a {@link io.servicetalk.client.api.LoadBalancer}
* @param <ResolvedAddress> the type of the resolved address.
*/
interface LoadBalancerObserver<ResolvedAddress> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep it private until we are a bit more confident, although that is kind of a chicken and egg problem. Can we tag it with the @UnstableApi annotation or something or is that a no-go?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typical way so-far was the experimental package. We can have such a package and move it out when we are ready.

*/
void noActiveHostsAvailable(int hostSetSize, NoActiveHostException exn);

interface HostObserver<ResolvedAddress> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also define selectivity factors here, regardless if the current implementation uses them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate? I think you're considering something like "score changed" or something like that but I want to be sure. If that is the case, I'd slightly prefer to just add them when we have an example since.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, i was thinking something like selectionOddsChanged(host, odds)
Defining odds in a meaningful consumable form, sounds interesting. Example, we could introduce rational groups (low, normal, high) and use them to categorize the hosts.
Happy to do in a later revision.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that will be interesting but let's add it later when we have data to feed it.

@bryce-anderson bryce-anderson merged commit 82ad584 into apple:main Dec 13, 2023
15 checks passed
@bryce-anderson bryce-anderson deleted the bl_anderson/load_balancer_observer branch December 13, 2023 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants