pub struct Balance<D: Discover, Req> { /* private fields */ }Expand description
Distributes requests across inner services using the Power of Two Choices.
As described in the Finagle Guide:
The algorithm randomly picks two services from the set of ready endpoints and selects the least loaded of the two. By repeatedly using this strategy, we can expect a manageable upper bound on the maximum load of any server.
The maximum load variance between any two servers is bound by
ln(ln(n))wherenis the number of servers in the cluster.
Note that Balance requires that the Discover you use is Unpin in order to implement
Service. This is because it needs to be accessed from Service::poll_ready, which takes
&mut self. You can achieve this easily by wrapping your Discover in Box::pin before you
construct the Balance instance. For more details, see #319.
Implementations§
Trait Implementations§
Source§impl<D, Req> Service<Req> for Balance<D, Req>
impl<D, Req> Service<Req> for Balance<D, Req>
Source§type Response = <<D as Discover>::Service as Service<Req>>::Response
type Response = <<D as Discover>::Service as Service<Req>>::Response
Source§type Future = MapErr<<<D as Discover>::Service as Service<Req>>::Future, fn(<<D as Discover>::Service as Service<Req>>::Error) -> Box<dyn Error + Sync + Send>>
type Future = MapErr<<<D as Discover>::Service as Service<Req>>::Future, fn(<<D as Discover>::Service as Service<Req>>::Error) -> Box<dyn Error + Sync + Send>>
Auto Trait Implementations§
impl<D, Req> !Freeze for Balance<D, Req>
impl<D, Req> !RefUnwindSafe for Balance<D, Req>
impl<D, Req> Send for Balance<D, Req>
impl<D, Req> Sync for Balance<D, Req>
impl<D, Req> Unpin for Balance<D, Req>
impl<D, Req> UnsafeUnpin for Balance<D, Req>where
D: UnsafeUnpin,
impl<D, Req> !UnwindSafe for Balance<D, Req>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<M, S, Target, Request> MakeService<Target, Request> for M
impl<M, S, Target, Request> MakeService<Target, Request> for M
Source§fn poll_ready(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), <M as MakeService<Target, Request>>::MakeError>>
fn poll_ready( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<(), <M as MakeService<Target, Request>>::MakeError>>
Ready when the factory is able to create more services. Read more