changed shortest prefix match to longest prefix match; update dockerfile

This commit is contained in:
psun256
2025-12-10 22:51:57 -05:00
parent 36026049f9
commit 2e1446d300
4 changed files with 5 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ use crate::backend::*;
use crate::balancer::Balancer;
use crate::balancer::adaptive_weight::AdaptiveWeightBalancer;
use crate::balancer::round_robin::RoundRobinBalancer;
use crate::balancer::ip_hashing::SourceIPHash;
use crate::config::*;
pub struct RoutingTable {
@@ -100,6 +101,7 @@ pub fn build_lb(
let balancer: Box<dyn Balancer + Send> = match &rule.strategy {
LoadBalancerStrategy::RoundRobin => Box::new(RoundRobinBalancer::new(pool)),
LoadBalancerStrategy::SourceIPHash => Box::new(SourceIPHash::new(pool)),
LoadBalancerStrategy::Adaptive {
coefficients,
alpha,
@@ -119,7 +121,7 @@ pub fn build_lb(
for table in listeners.values_mut() {
table
.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))

View File

@@ -57,5 +57,6 @@ pub struct RuleConfig {
#[serde(tag = "type")]
pub enum LoadBalancerStrategy {
RoundRobin,
SourceIPHash,
Adaptive { coefficients: [f64; 4], alpha: f64 },
}