changed shortest prefix match to longest prefix match; update dockerfile
This commit is contained in:
@@ -33,8 +33,7 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
|||||||
|
|
||||||
# change to scratch and get comment the apk command for prod, i guess
|
# change to scratch and get comment the apk command for prod, i guess
|
||||||
FROM alpine:latest AS runtime
|
FROM alpine:latest AS runtime
|
||||||
# RUN apk add --no-cache ca-certificates curl netcat-openbsd bind-tools strace
|
RUN apk add --no-cache ca-certificates curl netcat-openbsd bind-tools strace
|
||||||
WORKDIR /enginewhy
|
WORKDIR /enginewhy
|
||||||
COPY --from=builder /enginewhy/target/x86_64-unknown-linux-musl/release/l4lb /usr/bin/l4lb
|
COPY --from=builder /enginewhy/target/x86_64-unknown-linux-musl/release/l4lb /usr/bin/l4lb
|
||||||
COPY config.yaml .
|
|
||||||
ENTRYPOINT ["l4lb"]
|
ENTRYPOINT ["l4lb"]
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
services:
|
services:
|
||||||
# two-arm load balancer
|
|
||||||
load-balancer:
|
load-balancer:
|
||||||
image: neoslhp/enginewhy-lb
|
image: neoslhp/enginewhy-lb
|
||||||
container_name: load-balancer
|
container_name: load-balancer
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use crate::backend::*;
|
|||||||
use crate::balancer::Balancer;
|
use crate::balancer::Balancer;
|
||||||
use crate::balancer::adaptive_weight::AdaptiveWeightBalancer;
|
use crate::balancer::adaptive_weight::AdaptiveWeightBalancer;
|
||||||
use crate::balancer::round_robin::RoundRobinBalancer;
|
use crate::balancer::round_robin::RoundRobinBalancer;
|
||||||
|
use crate::balancer::ip_hashing::SourceIPHash;
|
||||||
use crate::config::*;
|
use crate::config::*;
|
||||||
|
|
||||||
pub struct RoutingTable {
|
pub struct RoutingTable {
|
||||||
@@ -100,6 +101,7 @@ pub fn build_lb(
|
|||||||
|
|
||||||
let balancer: Box<dyn Balancer + Send> = match &rule.strategy {
|
let balancer: Box<dyn Balancer + Send> = match &rule.strategy {
|
||||||
LoadBalancerStrategy::RoundRobin => Box::new(RoundRobinBalancer::new(pool)),
|
LoadBalancerStrategy::RoundRobin => Box::new(RoundRobinBalancer::new(pool)),
|
||||||
|
LoadBalancerStrategy::SourceIPHash => Box::new(SourceIPHash::new(pool)),
|
||||||
LoadBalancerStrategy::Adaptive {
|
LoadBalancerStrategy::Adaptive {
|
||||||
coefficients,
|
coefficients,
|
||||||
alpha,
|
alpha,
|
||||||
@@ -119,7 +121,7 @@ pub fn build_lb(
|
|||||||
for table in listeners.values_mut() {
|
for table in listeners.values_mut() {
|
||||||
table
|
table
|
||||||
.entries
|
.entries
|
||||||
.sort_by(|(a, _), (b, _)| a.network_length().cmp(&b.network_length()));
|
.sort_by(|(a, _), (b, _)| b.network_length().cmp(&a.network_length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((listeners, healths))
|
Ok((listeners, healths))
|
||||||
|
|||||||
@@ -57,5 +57,6 @@ pub struct RuleConfig {
|
|||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub enum LoadBalancerStrategy {
|
pub enum LoadBalancerStrategy {
|
||||||
RoundRobin,
|
RoundRobin,
|
||||||
|
SourceIPHash,
|
||||||
Adaptive { coefficients: [f64; 4], alpha: f64 },
|
Adaptive { coefficients: [f64; 4], alpha: f64 },
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user