From 62c745898d35287577caa0bd384cc7bc39f6b4ec Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 8 Dec 2021 22:29:08 +0100 Subject: Inverse how priorities work --- src/https.rs | 9 ++++----- src/proxy_config.rs | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/https.rs b/src/https.rs index 7d64e44..e1db42e 100644 --- a/src/https.rs +++ b/src/https.rs @@ -100,15 +100,14 @@ async fn handle( .map(|prefix| path.starts_with(prefix)) .unwrap_or(true) }) - .min_by_key(|ent| { + .max_by_key(|ent| { ( ent.priority, - -(ent - .path_prefix + ent.path_prefix .as_ref() .map(|x| x.len() as i32) - .unwrap_or(0)), - ent.calls.load(Ordering::SeqCst), + .unwrap_or(0), + -ent.calls.load(Ordering::SeqCst), ) }); diff --git a/src/proxy_config.rs b/src/proxy_config.rs index 399b52a..8a64f53 100644 --- a/src/proxy_config.rs +++ b/src/proxy_config.rs @@ -50,7 +50,7 @@ pub struct ProxyEntry { // Counts the number of times this proxy server has been called to // This implements a round-robin load balancer if there are multiple // entries for the same host and same path prefix. - pub calls: atomic::AtomicU64, + pub calls: atomic::AtomicI64, } impl std::fmt::Display for ProxyEntry { @@ -69,7 +69,7 @@ impl std::fmt::Display for ProxyEntry { if !self.add_headers.is_empty() { write!(f, " +Headers: {:?}", self.add_headers)?; } - Ok(()) + write!(f, " ({})", self.calls.load(atomic::Ordering::Relaxed)) } } @@ -125,7 +125,7 @@ fn parse_tricot_tag( path_prefix, priority, add_headers: add_headers.to_vec(), - calls: atomic::AtomicU64::from(0), + calls: atomic::AtomicI64::from(0), }) } -- cgit v1.2.3