Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lightway-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ workspace = true
[dependencies]
anyhow.workspace = true
async-trait.workspace = true
average = "0.16.0"
bytes.workspace = true
bytesize.workspace = true
clap.workspace = true
Expand Down
12 changes: 7 additions & 5 deletions lightway-server/src/ip_manager/ip_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,6 @@ mod tests {

#[test]
fn test_shuffle() {
use average::Mean;

let mut pool = get_ip_pool();
pool.shuffle_ips();

Expand All @@ -383,15 +381,19 @@ mod tests {
// chances of this coming out as less than 512 in practice are
// miniscule.
let mut previous = pool.allocate_ip().unwrap().to_bits();
let m: Mean = std::iter::from_fn(|| {
let (count, total_differences) = std::iter::from_fn(|| {
let ip = pool.allocate_ip()?.to_bits();

let delta = ip.abs_diff(previous);
previous = ip;
Some(delta as f64)
})
.collect();
assert_gt!(m.mean(), 512.0);
.fold((0, 0.0f64), |(mut count, mut total_differences), v| {
count += 1;
total_differences += v;
(count, total_differences)
});
assert_gt!(total_differences / count as f64, 512.0);
}
}

Expand Down
27 changes: 14 additions & 13 deletions lightway-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,25 @@ async fn metrics_debug() {
metrics_util::debugging::DebugValue::Gauge(value) => {
trace!("metric: {} {labels:?} = Guage({value:?})", name.as_str())
}
metrics_util::debugging::DebugValue::Histogram(values) => {
// TODO: https://docs.rs/average/latest/average/macro.concatenate.html for min/max and avg?

use average::{Estimate, Max, Mean, Min, concatenate};

concatenate!(Stats, [Min, min], [Mean, mean], [Max, max]);
let len = values.len();
let s: Stats = values.into_iter().map(|f| f.into_inner()).collect();

metrics_util::debugging::DebugValue::Histogram(values) if !values.is_empty() => {
let (sum, maximum, minimum) = values.iter().fold(
(0.0f64, f64::NEG_INFINITY, f64::INFINITY),
|(mut sum, maximum, minimum), v| {
let v = v.into_inner();
sum += v;
(sum, maximum.max(v), minimum.min(v))
},
);
trace!(
"metric: {} {labels:?} = Histogram({} samples min/avg/max {:.2}/{:.2}/{:.2})",
name.as_str(),
len,
s.min(),
s.mean(),
s.max(),
values.len(),
minimum,
sum / values.len() as f64,
maximum,
)
}
_ => (),
};
}
}
Expand Down