-
Notifications
You must be signed in to change notification settings - Fork 262
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
balance: Specialize the balancer for P2C #288
Conversation
As described in tower-rs#286, `Balance` had a few problems: - it is responsible for driving all inner services to readiness, making its `poll_ready` O(n) and not O(1); - the `choose` abstraction was a hinderance. If a round-robin balancer is needed it can be implemented separately without much duplicate code; and - endpoint errors were considered fatal to the balancer. This changes replaces `Balance` with `P2CBalance` and removes the `choose` module. Endpoint service failures now cause the service to be removed from the balancer gracefully. Endpoint selection is now effectively constant time, though it biases for availability in the case when random selection does not yield an available endpoint. `tower-test` had to be updated so that a mocked service could fail after advertising readiness.
The balance layer now operates over MakeP2CBalance, which composes over layers that produce Discover instances.
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.
This change looks good to me. I commented mainly on some style nits.
Per offline discussion, @carllerche suggested some potential improvements that I have written up in #292. We're going to merge this for the time being and revisit #292 before balance is released to crates. |
tower-rs/tower#288 changed the Balance implementation substantially so that it is no longer responsible for driving services to readiness. Instead, a new layer, `spawn_ready` is inserted around endpoint stack to ensure that readiness is driven on a background task. In support of this change, the `pending` layer was removed from the enpdoint stack and, instead, the discovery system is now responsible for driving pending services to be materialized.
I just realized that this does introduce a requirement for inner services to implement |
@jonhoo yeah, that is a notable change... I think it would be pretty easy to introduce a |
@jonhoo though, note the |
tower-rs/tower#288 and tower-rs/tower#293 changed the Balance implementation substantially. Now, a new layer, `spawn_ready` is inserted around endpoint stack to ensure that readiness is driven on a background task. In support of this change, the `pending` layer was removed from the endpoint stack and, instead, the discovery system is now responsible for driving pending services to be materialized.
tower-rs/tower#288 and tower-rs/tower#293 changed the Balance implementation substantially. Now, a new layer, `spawn_ready` is inserted around endpoint stack to ensure that readiness is driven on a background task. In support of this change, the `pending` layer was removed from the endpoint stack and, instead, the discovery system is now responsible for driving pending services to be materialized.
As described in #286,
Balance
had a few problems:its
poll_ready
O(n) and not O(1);choose
abstraction was a hinderance. If a round-robin balanceris needed it can be implemented separately without much duplicate
code; and
This changes replaces
Balance
withp2c::Balance
and removes thechoose
module.Endpoint service failures now cause the service to be removed from the
balancer gracefully.
Endpoint selection is now effectively constant time, though it biases
for availability in the case when random selection does not yield an
available endpoint.
tower-test
had to be updated so that a mocked service could fail afteradvertising readiness.