retry: Add generic backoff utilities#685
Merged
LucioFranco merged 10 commits intomasterfrom Aug 30, 2022
Merged
Conversation
This adds a new `Backoff` trait and a `ExponentialBackoff` implementation borrwoed from `linkerd2-proxy`. This provides the initial building blocks for a more fully batteries included retry policy.
seanmonstar
reviewed
Aug 19, 2022
hawkw
reviewed
Aug 19, 2022
tower/src/retry/backoff.rs
Outdated
Comment on lines
1
to
16
| //! This module contains generic backoff utlities to be used with the retry | ||
| //! layer. | ||
| //! | ||
| //! The [`Backoff`] trait is a generic way to represent backoffs that can use | ||
| //! any timer type. | ||
| //! | ||
| //! [`ExponentialBackoff`] implements [`Backoff`] and provides a batteries | ||
| //! included exponential backoff and jitter strategy. | ||
|
|
||
| use rand::Rng; | ||
| use rand::{rngs::SmallRng, thread_rng, SeedableRng}; | ||
| use std::fmt::Display; | ||
| use std::future::Future; | ||
| use std::time::Duration; | ||
| use tokio::time; | ||
|
|
Member
There was a problem hiding this comment.
the doc comment either for the module or the Backoff trait should probably at least mention what the term "backoff" means, for readers who've never seen it before?
Co-authored-by: Sean McArthur <[email protected]>
Co-authored-by: Eliza Weisman <[email protected]>
Co-authored-by: Eliza Weisman <[email protected]>
LucioFranco
added a commit
that referenced
this pull request
Aug 23, 2022
This adds new PRNG utilities that only use libstd and not the external `rand` crate. This change's motivation are that in tower middleware that need PRNG don't need the complexity and vast utilities of the `rand` crate. This adds a `Rng` trait which abstracts the simple PRNG features tower needs. This also provides a `HasherRng` which uses the `RandomState` type from libstd to generate random `u64` values. In addition, there is an internal only `sample_inplace` which is used within the balance p2c middleware to randomly pick a ready service. This implementation is crate private since its quite specific to the balance implementation. The goal of this in addition to the balance middlware getting `rand` removed is for the upcoming `Retry` changes. The `next_f64` will be used in the jitter portion of the backoff utilities in #685.
Merged
LucioFranco
added a commit
that referenced
this pull request
Aug 25, 2022
This adds new PRNG utilities that only use libstd and not the external `rand` crate. This change's motivation are that in tower middleware that need PRNG don't need the complexity and vast utilities of the `rand` crate. This adds a `Rng` trait which abstracts the simple PRNG features tower needs. This also provides a `HasherRng` which uses the `RandomState` type from libstd to generate random `u64` values. In addition, there is an internal only `sample_inplace` which is used within the balance p2c middleware to randomly pick a ready service. This implementation is crate private since its quite specific to the balance implementation. The goal of this in addition to the balance middlware getting `rand` removed is for the upcoming `Retry` changes. The `next_f64` will be used in the jitter portion of the backoff utilities in #685. Co-authored-by: Eliza Weisman <[email protected]>
19 tasks
Member
Author
|
I think this is ready for another round of reviews! |
seanmonstar
approved these changes
Aug 30, 2022
Collaborator
seanmonstar
left a comment
There was a problem hiding this comment.
I think this looks good!
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This adds a new
Backofftrait and aExponentialBackoffimplementation borrwoed from
linkerd2-proxy. This provides the initialbuilding blocks for a more fully batteries included retry policy.
cc @rcoh