move util functions into respective modules
This commit is contained in:
1 parent
1c38d8ff48
commit
befccc0d6f
4 files changed
+11
-20
No files matched your search
+6
-3
@@ -1,5 +1,4 @@
|
||||
use crate::pinger::PingReply;
|
||||
use crate::utils::Utils;
|
||||
use crate::Config;
|
||||
use log::info;
|
||||
use std::collections::HashMap;
|
||||
@@ -22,6 +21,10 @@ pub struct Baseliner {
|
||||
pub stats_receiver: Receiver<PingReply>,
|
||||
}
|
||||
|
||||
fn ewma_factor(tick: f64, dur: f64) -> f64 {
|
||||
((0.5_f64).ln() / (dur / tick)).exp()
|
||||
}
|
||||
|
||||
impl Baseliner {
|
||||
pub fn run(&self) -> anyhow::Result<()> {
|
||||
/*
|
||||
@@ -32,8 +35,8 @@ impl Baseliner {
|
||||
* aren't bloat related, with less sensitivity (bigger numbers) we smooth through quick spikes
|
||||
* but take longer to respond to real bufferbloat
|
||||
*/
|
||||
let slow_factor = Utils::ewma_factor(self.config.tick_interval, 135.0);
|
||||
let fast_factor = Utils::ewma_factor(self.config.tick_interval, 0.4);
|
||||
let slow_factor = ewma_factor(self.config.tick_interval, 135.0);
|
||||
let fast_factor = ewma_factor(self.config.tick_interval, 0.4);
|
||||
|
||||
loop {
|
||||
let time_data = self.stats_receiver.recv()?;
|
||||
|
||||
@@ -12,7 +12,6 @@ mod pinger_icmp;
|
||||
mod pinger_icmp_ts;
|
||||
mod ratecontroller;
|
||||
mod reflector_selector;
|
||||
mod utils;
|
||||
|
||||
use crate::baseliner::{Baseliner, ReflectorStats};
|
||||
use ::log::debug;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::clock::Clock;
|
||||
use crate::netlink::{Netlink, NetlinkError, Qdisc};
|
||||
use crate::utils::Utils;
|
||||
use crate::{Config, ReflectorStats};
|
||||
use log::{debug, error, info, warn};
|
||||
use rand::seq::SliceRandom;
|
||||
@@ -120,7 +119,11 @@ impl Ratecontroller {
|
||||
if state.deltas.len() < 3 {
|
||||
state.next_rate = min_rate;
|
||||
} else {
|
||||
state.delta_stat = Utils::a_else_b(state.deltas[2], state.deltas[0]);
|
||||
state.delta_stat = if state.deltas[2] > 0.0 {
|
||||
state.deltas[2]
|
||||
} else {
|
||||
state.deltas[0]
|
||||
};
|
||||
|
||||
if state.delta_stat > 0.0 {
|
||||
/*
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
pub struct Utils {}
|
||||
|
||||
impl Utils {
|
||||
pub fn a_else_b(a: f64, b: f64) -> f64 {
|
||||
if a > 0.0 {
|
||||
a
|
||||
} else {
|
||||
b
|
||||
}
|
||||
}
|
||||
pub fn ewma_factor(tick: f64, dur: f64) -> f64 {
|
||||
((0.5_f64).ln() / (dur / tick)).exp()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user