]> johannes.truschnigg.info Git - sqm_lagthrottle/commitdiff
Require two delayed peers before shifting bw down
authorJohannes Truschnigg <johannes@truschnigg.info>
Sun, 20 Mar 2022 15:15:42 +0000 (16:15 +0100)
committerJohannes Truschnigg <johannes@truschnigg.info>
Sun, 20 Mar 2022 15:15:42 +0000 (16:15 +0100)
__sqm_lagthrottle.awk

index a98aae943b64a3135ffb80613707273e1756011a..bfefcb05379f9f644117405b98051105096ada48 100644 (file)
@@ -118,7 +118,7 @@ BEGIN {
 # Compute a sensible number of steps between the MIN and MAX bandwidth
 # boundaries configured.
 # XXX TODO impl. tunable for acting more fine-grained?
-function slice_bw_window_rx(bw_lower_bound_rx, bw_upper_bound_rx) {
+function slice_bw_window_rx(bw_lower_bound_rx, bw_upper_bound_rx,    k) {
   bw_bound_delta_rx = (bw_upper_bound_rx - bw_lower_bound_rx)
   bw_steps_rx = 1 + int((log(bw_bound_delta_rx) / log(10)) ^ bw_slice_exponent)
   print "# STEPS_RX=" bw_steps_rx
@@ -145,7 +145,7 @@ function update_ts() {
 }
 
 
-function get_time() {
+function get_time(    upt) {
   getline upt < "/proc/uptime"
   close("/proc/uptime")
   split(upt, ts, " ")
@@ -192,7 +192,7 @@ function update_bw() {
 
 # Called after parsing each latency record in the fping stream.
 function process_record(pn, bytes, lat) {
-  # If fing happens to pass in a latency record with a peername that was not
+  # If fping happens to pass in a latency record with a peername that was not
   # announced upon startup, we exit here. Should never happen, but provides
   # SOME protection against fping changing record format in a potential future
   # version.
@@ -252,6 +252,12 @@ function adjust_sqm(peername, latency) {
   thresh_fudged = (FUDGE + (ping_avgs[peername] * THRESHOLD))
   if (last2avg > thresh_fudged) {
     if (latency > ping_prev[peername] && latency > ping_pprev[peername]) {
+      peers_delayed[peername]=1
+      if (len_arr(peers_delayed) > 1) { # more than one peer appears slower than usual
+      } else {
+        # print "# " ts " NOOP first/only delayed peer detected, assuming fluke"
+       return
+      }
       if (prefer_high_bw == 0) {
           _low_step = max(0, int((bw_step_rx_cur / 2) - 2))
           bw_step_rx_next = _low_step
@@ -275,6 +281,7 @@ function adjust_sqm(peername, latency) {
     }
     not_increasing_count[peername] = 0
   } else if (latency < (ping_prev[peername] + FUDGE / 2) && latency < (ping_pprev[peername] + FUDGE / 2) && ping_prev[peername] < (ping_pprev[peername] + FUDGE/2)) {
+    delete peers_delayed[peername]
     if (prefer_high_bw == 0) { # no preference for high bw caps configured
       if (rx_rate < (0.9 * STEPS_RX[bw_step_rx_cur])) { # line not loaded close to current cap, so skip increasing bw
        not_increasing_count[peername]++
@@ -331,7 +338,7 @@ function update_pingstats(peername, latency) {
 
 
 # Simple helper function to compute the average over a peer's PINGSLOTS.
-function update_ping_avgs(peername) {
+function update_ping_avgs(peername,    ping_sum, k) {
   ping_sum = 0
   for (k = 0; k <= PINGSLOTS; ++k) {
     ps = peername ":" k
@@ -349,7 +356,7 @@ function set_bw(dev, kbit) {
 }
 
 
-function max (a, b) {
+function max(    a, b) {
   if (a > b) {
     return a
   }
@@ -357,6 +364,13 @@ function max (a, b) {
 }
 
 
+function len_arr(arrvar,    i, ec) {
+  ec = 0
+  for(i in arrvar) ec++
+  return ec
+}
+
+
 END {
   print "# " ts " BYE"
   # Usually not reached.