Inverse how priorities work

This commit is contained in:
Alex 2021-12-08 22:29:08 +01:00
parent 7dbf848de3
commit 62c745898d
No known key found for this signature in database
GPG key ID: EDABF9711E244EB1
2 changed files with 7 additions and 8 deletions

View file

@ -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),
)
});

View file

@ -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),
})
}