Handle initialization for first ratecontroller run better

This commit is contained in:
Nils Andreas Svee committed 2022-10-29 22:34:52 +02:00
1 parent 13ba3eaffe
commit d5823634ca
2 files changed
+17 -12

No files matched your search

+3 -1
View File
@@ -170,6 +170,8 @@ fn main() -> anyhow::Result<()> {
owd_recent, owd_recent,
reflector_peers_lock, reflector_peers_lock,
reselect_sender, reselect_sender,
dl_direction,
ul_direction,
)?; )?;
debug!( debug!(
@@ -184,7 +186,7 @@ fn main() -> anyhow::Result<()> {
let ratecontroller_handle = thread::Builder::new() let ratecontroller_handle = thread::Builder::new()
.name("ratecontroller".to_string()) .name("ratecontroller".to_string())
.spawn(move || ratecontroller.run(dl_direction, ul_direction))?; .spawn(move || ratecontroller.run())?;
threads.push(ratecontroller_handle); threads.push(ratecontroller_handle);
+14 -11
View File
@@ -86,13 +86,14 @@ struct State {
pub struct Ratecontroller { pub struct Ratecontroller {
config: Config, config: Config,
down_direction: StatsDirection,
owd_baseline: Arc<Mutex<HashMap<IpAddr, ReflectorStats>>>, owd_baseline: Arc<Mutex<HashMap<IpAddr, ReflectorStats>>>,
owd_recent: Arc<Mutex<HashMap<IpAddr, ReflectorStats>>>, owd_recent: Arc<Mutex<HashMap<IpAddr, ReflectorStats>>>,
reflectors_lock: Arc<RwLock<Vec<IpAddr>>>, reflectors_lock: Arc<RwLock<Vec<IpAddr>>>,
reselect_trigger: Sender<bool>, reselect_trigger: Sender<bool>,
state_dl: State, state_dl: State,
state_ul: State, state_ul: State,
up_direction: StatsDirection,
} }
impl Ratecontroller { impl Ratecontroller {
@@ -228,6 +229,8 @@ impl Ratecontroller {
owd_recent: Arc<Mutex<HashMap<IpAddr, ReflectorStats>>>, owd_recent: Arc<Mutex<HashMap<IpAddr, ReflectorStats>>>,
reflectors_lock: Arc<RwLock<Vec<IpAddr>>>, reflectors_lock: Arc<RwLock<Vec<IpAddr>>>,
reselect_trigger: Sender<bool>, reselect_trigger: Sender<bool>,
down_direction: StatsDirection,
up_direction: StatsDirection,
) -> anyhow::Result<Self> { ) -> anyhow::Result<Self> {
let dl_qdisc = Netlink::qdisc_from_ifname(config.download_interface.as_str())?; let dl_qdisc = Netlink::qdisc_from_ifname(config.download_interface.as_str())?;
let dl_safe_rates = let dl_safe_rates =
@@ -236,8 +239,11 @@ impl Ratecontroller {
let ul_safe_rates = let ul_safe_rates =
generate_initial_speeds(config.upload_base_kbits, config.speed_hist_size); generate_initial_speeds(config.upload_base_kbits, config.speed_hist_size);
let (cur_rx, cur_tx) = get_interface_stats(&config, down_direction, up_direction)?;
Ok(Self { Ok(Self {
config, config,
down_direction,
owd_baseline, owd_baseline,
owd_recent, owd_recent,
reflectors_lock, reflectors_lock,
@@ -252,8 +258,8 @@ impl Ratecontroller {
now_t: 0.0, now_t: 0.0,
nrate: 0, nrate: 0,
qdisc: dl_qdisc, qdisc: dl_qdisc,
previous_bytes: 0, previous_bytes: cur_rx,
previous_bytes_t: 0.0, prev_t: Instant::now(),
safe_rates: dl_safe_rates, safe_rates: dl_safe_rates,
utilisation: 0.0, utilisation: 0.0,
}, },
@@ -267,19 +273,16 @@ impl Ratecontroller {
now_t: 0.0, now_t: 0.0,
nrate: 0, nrate: 0,
qdisc: ul_qdisc, qdisc: ul_qdisc,
previous_bytes: 0, previous_bytes: cur_tx,
previous_bytes_t: 0.0, prev_t: Instant::now(),
safe_rates: ul_safe_rates, safe_rates: ul_safe_rates,
utilisation: 0.0, utilisation: 0.0,
}, },
up_direction,
}) })
} }
pub fn run( pub fn run(&mut self) -> anyhow::Result<()> {
&mut self,
down_direction: StatsDirection,
up_direction: StatsDirection,
) -> anyhow::Result<()> {
let sleep_time = Duration::from_secs_f64(self.config.min_change_interval); let sleep_time = Duration::from_secs_f64(self.config.min_change_interval);
let time = Time::new(ClockId::Monotonic); let time = Time::new(ClockId::Monotonic);
@@ -345,7 +348,7 @@ impl Ratecontroller {
// change speeds here // change speeds here
(self.state_dl.current_bytes, self.state_ul.current_bytes) = (self.state_dl.current_bytes, self.state_ul.current_bytes) =
get_interface_stats(&self.config, down_direction, up_direction)?; get_interface_stats(&self.config, self.down_direction, self.up_direction)?;
if self.state_dl.current_bytes == -1 || self.state_ul.current_bytes == -1 { if self.state_dl.current_bytes == -1 || self.state_ul.current_bytes == -1 {
warn!( warn!(
"One or both Netlink stats could not be read. Skipping rate control algorithm"); "One or both Netlink stats could not be read. Skipping rate control algorithm");