Struct Hedge

pub struct Hedge<S, P>(/* private field */);

A middleware that pre-emptively retries requests which have been outstanding for longer than a given latency percentile. If either of the original future or the retry future completes, that value is used.

Implementations

impl<S, P> Hedge<S, P>

fn new<Request>(service: S, policy: P, min_data_points: u64, latency_percentile: f32, period: Duration) -> Hedge<S, P>
where
    S: Service<Request> + Clone,
    S::Error: Into<BoxError>,
    P: Policy<Request> + Clone,

Create a new hedge middleware.

fn new_with_mock_latencies<Request>(service: S, policy: P, min_data_points: u64, latency_percentile: f32, period: Duration, latencies_ms: &[u64]) -> Hedge<S, P>
where
    S: Service<Request> + Clone,
    S::Error: Into<BoxError>,
    P: Policy<Request> + Clone,

A hedge middleware with a prepopulated latency histogram. This is usedful for integration tests.

Trait Implementations

impl<S, P, Request> Service<Request> for Hedge<S, P> where S: Service<Request> + Clone, S::Error: Into<BoxError>, P: Policy<Request> + Clone,

type Response = <S as Service<Request>>::Response;
type Error = Box<dyn Error + Sync + Send>;
type Future = Future<Select<SelectPolicy<P>, Latency<Arc<Mutex<RotatingHistogram>>, S>, Delay<DelayPolicy, AsyncFilter<Latency<Arc<Mutex<RotatingHistogram>>, S>, PolicyPredicate<P>>>>, Request>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
fn call(&mut self, request: Request) -> Self::Future

impl<S: Debug, P: Debug> Debug for Hedge<S, P>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Auto Trait Implementations

impl<S, P> Freeze for Hedge<S, P> where Select<SelectPolicy<P>, Latency<Arc<Mutex<RotatingHistogram>>, S>, Delay<DelayPolicy, AsyncFilter<Latency<Arc<Mutex<RotatingHistogram>>, S>, PolicyPredicate<P>>>>: Freeze,

impl<S, P> RefUnwindSafe for Hedge<S, P> where Select<SelectPolicy<P>, Latency<Arc<Mutex<RotatingHistogram>>, S>, Delay<DelayPolicy, AsyncFilter<Latency<Arc<Mutex<RotatingHistogram>>, S>, PolicyPredicate<P>>>>: RefUnwindSafe,

impl<S, P> Send for Hedge<S, P> where Select<SelectPolicy<P>, Latency<Arc<Mutex<RotatingHistogram>>, S>, Delay<DelayPolicy, AsyncFilter<Latency<Arc<Mutex<RotatingHistogram>>, S>, PolicyPredicate<P>>>>: Send,

impl<S, P> Sync for Hedge<S, P> where Select<SelectPolicy<P>, Latency<Arc<Mutex<RotatingHistogram>>, S>, Delay<DelayPolicy, AsyncFilter<Latency<Arc<Mutex<RotatingHistogram>>, S>, PolicyPredicate<P>>>>: Sync,

impl<S, P> Unpin for Hedge<S, P> where Select<SelectPolicy<P>, Latency<Arc<Mutex<RotatingHistogram>>, S>, Delay<DelayPolicy, AsyncFilter<Latency<Arc<Mutex<RotatingHistogram>>, S>, PolicyPredicate<P>>>>: Unpin,

impl<S, P> UnsafeUnpin for Hedge<S, P> where Select<SelectPolicy<P>, Latency<Arc<Mutex<RotatingHistogram>>, S>, Delay<DelayPolicy, AsyncFilter<Latency<Arc<Mutex<RotatingHistogram>>, S>, PolicyPredicate<P>>>>: UnsafeUnpin,

impl<S, P> UnwindSafe for Hedge<S, P> where Select<SelectPolicy<P>, Latency<Arc<Mutex<RotatingHistogram>>, S>, Delay<DelayPolicy, AsyncFilter<Latency<Arc<Mutex<RotatingHistogram>>, S>, PolicyPredicate<P>>>>: UnwindSafe,

Blanket Implementations

impl<C, Target> MakeConnection<Target> for Hedge<S, P> where C: Service<Target>, <C as Service<Target>>::Response: AsyncRead + AsyncWrite,

type Connection = <C as Service<Target>>::Response;
type Error = <C as Service<Target>>::Error;
type Future = <C as Service<Target>>::Future;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), <C as MakeConnection<Target>>::Error>>
fn make_connection(&mut self, target: Target) -> <C as MakeConnection<Target>>::Future

impl<M, S, Target, Request> MakeService<Target, Request> for Hedge<S, P> where M: Service<Target, Response = S>, S: Service<Request>,

type Response = <S as Service<Request>>::Response;
type Error = <S as Service<Request>>::Error;
type Service = S;
type MakeError = <M as Service<Target>>::Error;
type Future = <M as Service<Target>>::Future;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), <M as MakeService<Target, Request>>::MakeError>>
fn make_service(&mut self, target: Target) -> <M as MakeService<Target, Request>>::Future

impl<T> Any for Hedge<S, P> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Hedge<S, P> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Hedge<S, P> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for Hedge<S, P>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Instrument for Hedge<S, P>

impl<T> WithSubscriber for Hedge<S, P>

impl<T, Request> ServiceExt<Request> for Hedge<S, P> where T: Service<Request> + ?Sized,

impl<T, U> Into<U> for Hedge<S, P> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Hedge<S, P> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Hedge<S, P> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>