]> johannes.truschnigg.info Git - sqm_lagthrottle/commitdiff
Implement OPTIMIZATION_PREFERENCE tunable
authorJohannes Truschnigg <johannes@truschnigg.info>
Sat, 19 Mar 2022 18:42:40 +0000 (19:42 +0100)
committerJohannes Truschnigg <johannes@truschnigg.info>
Sat, 19 Mar 2022 18:42:40 +0000 (19:42 +0100)
__lagdetect.awk
lagdetect.sh

index 7c390c4f494ff150e0b9816d7cc2a75a4cfcd7a0..452e71e4a2f6e7f0b6e0f42a7089660ff1983b67 100644 (file)
@@ -30,6 +30,7 @@ BEGIN {
   print "# THRESHOLD=" THRESHOLD
   print "# FUDGE=" FUDGE
   print "# DECISION=" DECISION
+  print "# PREFER=" PREFER
   print "# PINGSLOTS=" PINGSLOTS
   print "# BW_MAX_RX=" BW_MAX_RX
   print "# BW_MIN_RX=" BW_MIN_RX
@@ -50,8 +51,18 @@ BEGIN {
     not_increasing_count[pn] = 0 # number of consecutive cycles with no (fudged) latency increase
   }
   ts = get_time()
-  bw_step_rx_next = 1
   slice_bw_window_rx(BW_MIN_RX, BW_MAX_RX)
+  if (PREFER == "bandwidth") {
+    prefer_high_bw = 1
+    bw_step_rx_next = bw_maxindex_rx
+  } else if (PREFER == "latency") {
+    prefer_high_bw = 0
+    bw_step_rx_next = 1 + int(bw_maxindex_rx / 4)
+  } else {
+    print "FATAL: BOGUS PREFER SETTING: " PREFER
+    exit 1
+  }
+  set_bw(IFACE_RX, STEPS_RX[bw_step_rx_next])
   consec_timeouts = 0
   adjust_ts_delta = 0
   rx_rate_max = 100 # make something up
@@ -110,9 +121,6 @@ function slice_bw_window_rx(bw_lower_bound_rx, bw_upper_bound_rx) {
   }
   k--
   bw_maxindex_rx = k
-  bw_step_rx_next = k
-  bw_step_rx_cur = k
-  set_bw(IFACE_RX, STEPS_RX[bw_step_rx_next])
 }
 
 
@@ -255,6 +263,14 @@ 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)) {
+    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
+        adjust_old = ts
+       not_increasing_count[peername]++
+        print "=== " ts " NOOP skiping increase; rx rate too far from current cap of "  STEPS_RX[bw_step_rx_cur] "Kbps rx=" rx_rate " tx=" tx_rate
+       return
+      }
+    }
     if (not_increasing_count[peername] > (decision_pingslots_factor * PINGSLOTS)) {
       if (bw_step_rx_cur < bw_maxindex_rx) {
         bw_step_rx_next = bw_step_rx_cur + 1
index 54492b3663a82d308e2f0cb98d9a67c4a1e6980d..b2de69edb854ea953312676dff2d5600ec8929f0 100755 (executable)
@@ -34,9 +34,10 @@ STATS_RX='/sys/class/net/eth1/statistics/rx_bytes' # downstream bandwidth accoun
 IFACE_RX='ifb4eth1' # interface to apply downstream SQM to
 STATS_TX='/sys/class/net/eth1/statistics/tx_bytes' # upstream bandwidth accounting file for your SQM'd interface (presently not used)
 IFACE_TX='eth1' # interface to apply upstream SQM to (presently not used)
-BW_MIN_RX=10000 # your min. acceptable downstream bandwidth to shape to in Kbps
+BW_MIN_RX=4000 # your min. acceptable downstream bandwidth to shape to in Kbps
 BW_MAX_RX=30000 # your max. desired downstream bandwidth to shape to in Kbps
-TREND_DECISION="relaxed" # choose either "eager" or "relaxed" - the latter trades additional CPU load for quicker decision making
+TREND_DECISION="eager" # choose either "eager" or "relaxed" - the latter trades additional CPU load for quicker decision making
+OPTIMIZATION_PREFERENCE="latency" # try to optimize for either "latency" (i.e., minimze it) or increased "bandwidth"
 
 
 
@@ -86,7 +87,7 @@ return 1
 }
 
 
-for p in traceroute fping awk tc ip
+for p in fping awk tc ip
 do
   if ! type "${p}" >/dev/null
   then
@@ -190,13 +191,25 @@ do
 done
 
 
+case "${OPTIMIZATION_PREFERENCE}" in
+  latency)
+  ;;
+  bandwidth)
+  ;;
+  *)
+    printf 'FATAL: Invalid setting for OPTIMIZATION_PREFERENCE - choose either "bandwidth" or "latency".\n'
+    exit 1
+  ;;
+esac
+
+
 case "${TREND_DECISION}" in
   eager)
   ;;
   relaxed)
   ;;
   *)
-    printf 'FATAL: Interface "%s" does not seem to have cake SQM set up\n' "${i}"
+    printf 'FATAL: Invalid setting for TREND_DECISION - choose either "eager" or "relaxed".\n'
     exit 1
   ;;
 esac
@@ -215,6 +228,7 @@ fping --loop --retry=1 --size=1280 --period="${PING_INTERVAL}" --random ${PING_P
   -v BW_MAX_RX="${BW_MAX_RX}" \
   -v THRESHOLD="${THRESHOLD}" \
   -v DECISION="${TREND_DECISION}" \
+  -v PREFER="${OPTIMIZATION_PREFERENCE}" \
   -v PINGSLOTS="${PING_SLOTS_PER_PEER}" \
   -v FUDGE="${FUDGE_MS}" \
   -v PING_PEERS="${PING_PEERS}" \