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

balance: Specialize the balancer for P2C #288

Merged
merged 18 commits into from
Jun 4, 2019
Merged
2 changes: 2 additions & 0 deletions tower-balance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ log = "0.4.1"
rand = "0.6.5"
tokio-timer = "0.2.4"
tower-discover = "0.1.0"
tower-layer = "0.1.0"
tower-load = { version = "0.1.0", path = "../tower-load" }
tower-service = "0.2.0"
tower-util = "0.1.0"
Expand All @@ -43,3 +44,4 @@ tokio-executor = "0.1.2"
tower = { version = "0.1", path = "../tower" }
tower-buffer = { version = "0.1", path = "../tower-buffer" }
tower-limit = { version = "0.1", path = "../tower-limit" }
tower-test = { version = "0.1.0", path = "../tower-test" }
24 changes: 11 additions & 13 deletions tower-balance/examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tower::{
use tower_balance as lb;
use tower_load as load;

const REQUESTS: usize = 50_000;
const REQUESTS: usize = 100_000;
const CONCURRENCY: usize = 500;
const DEFAULT_RTT: Duration = Duration::from_millis(30);
static ENDPOINT_CAPACITY: usize = CONCURRENCY;
Expand Down Expand Up @@ -55,24 +55,22 @@ fn main() {
let fut = future::lazy(move || {
let decay = Duration::from_secs(10);
let d = gen_disco();
let pe = lb::Balance::p2c(load::PeakEwmaDiscover::new(
let pe = lb::p2c::Balance::from_entropy(load::PeakEwmaDiscover::new(
d,
DEFAULT_RTT,
decay,
load::NoInstrument,
));
run("P2C+PeakEWMA", pe)
run("P2C+PeakEWMA...", pe)
});

let fut = fut.then(move |_| {
let d = gen_disco();
let ll = lb::Balance::p2c(load::PendingRequestsDiscover::new(d, load::NoInstrument));
run("P2C+LeastLoaded", ll)
});

let fut = fut.and_then(move |_| {
let rr = lb::Balance::round_robin(gen_disco());
run("RoundRobin", rr)
let ll = lb::p2c::Balance::from_entropy(load::PendingRequestsDiscover::new(
d,
load::NoInstrument,
));
run("P2C+LeastLoaded...", ll)
});

rt.spawn(fut);
Expand Down Expand Up @@ -133,14 +131,14 @@ fn gen_disco() -> impl Discover<
)
}

fn run<D, C>(name: &'static str, lb: lb::Balance<D, C>) -> impl Future<Item = (), Error = ()>
fn run<D>(name: &'static str, lb: lb::p2c::Balance<D>) -> impl Future<Item = (), Error = ()>
where
D: Discover + Send + 'static,
D::Error: Into<Error>,
D::Key: Send,
D::Service: Service<Req, Response = Rsp, Error = Error> + Send,
D::Service: Service<Req, Response = Rsp, Error = Error> + load::Load + Send,
<D::Service as Service<Req>>::Future: Send,
C: lb::Choose<D::Key, D::Service> + Send + 'static,
<D::Service as load::Load>::Metric: std::fmt::Debug,
{
println!("{}", name);

Expand Down
49 changes: 0 additions & 49 deletions tower-balance/src/choose/mod.rs

This file was deleted.

108 changes: 0 additions & 108 deletions tower-balance/src/choose/p2c.rs

This file was deleted.

23 changes: 0 additions & 23 deletions tower-balance/src/choose/round_robin.rs

This file was deleted.

11 changes: 7 additions & 4 deletions tower-balance/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
//! Error types

use std::fmt;

pub(crate) type Error = Box<dyn std::error::Error + Send + Sync>;

/// An error returned when the balancer's endpoint discovery stream fails.
#[derive(Debug)]
pub struct Balance(pub(crate) Error);
pub struct Discover(pub(crate) Error);

impl fmt::Display for Balance {
impl fmt::Display for Discover {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "load balancing discover error: {}", self.0)
write!(f, "load balancer discovery error: {}", self.0)
}
}

impl std::error::Error for Balance {
impl std::error::Error for Discover {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&*self.0)
}
Expand Down
23 changes: 0 additions & 23 deletions tower-balance/src/future.rs

This file was deleted.

Loading