]> johannes.truschnigg.info Git - sqm_lagthrottle/commitdiff
Implement/improve bw usage estimation
authorJohannes Truschnigg <johannes@truschnigg.info>
Tue, 15 Mar 2022 19:53:38 +0000 (20:53 +0100)
committerJohannes Truschnigg <johannes@truschnigg.info>
Tue, 15 Mar 2022 19:53:38 +0000 (20:53 +0100)
__lagdetect.awk

index 827264d5efaab7c32c413d953c44828be4d1a628..38a090d53c76a481cc85d65763f42f86960cae1f 100644 (file)
@@ -1,5 +1,6 @@
 #!/usr/bin/awk -f
 BEGIN {
+  CONVFMT="%.3f"
   print "# INIT=" systime()
   print "# THRESHOLD=" THRESHOLD
   print "# FUDGE=" FUDGE
@@ -10,7 +11,7 @@ BEGIN {
   print "# IFACE_TX=" IFACE_TX
   print "# STATS_RX=" STATS_RX
   print "# IFACE_RX=" IFACE_RX
-  split(PING_PEERS, pps, " ")
+  peer_count = split(PING_PEERS, pps, " ")
   for (pp in pps) {
     pn = pps[pp]
     print "# PEERS+=" pn
@@ -23,6 +24,7 @@ BEGIN {
     not_increasing_count[pn]=0 # number of consecutive cycles with no (fudged) latency increase
   }
   update_bw()
+  update_bw_min_delta = (0.02 * peer_count)
 }
 
 
@@ -52,7 +54,11 @@ BEGIN {
 
 function update_ts() {
   ts = get_time()
-  if( (ts - ts_old) < 0.1 ) {
+  ts_delta = ts - ts_old
+  if( ts_delta < update_bw_min_delta ) {
+    # Let caller know that not much time has passed since the last update,
+    # so maybe not waste time with useless calculations in the face of very
+    # little actual change.
     return 0
   }
   ts_old = ts
@@ -67,9 +73,10 @@ function get_time() {
   return ts[1]
 }
 
+
 function update_bw() {
   if (! (update_ts())) {
-    #print "too fast, skiping bw reads " ts - ts_old
+    #print "too fast, skiping bw updates " ts - ts_old
     return
   }
 
@@ -82,9 +89,11 @@ function update_bw() {
   getline rx < STATS_RX
   close(STATS_RX)
 
-  rxdelta=(rx - rx_old)
-  txdelta=(tx - tx_old)
-  #print "rx_delta=" rxdelta "  tx_delta=" txdelta
+  rx_delta=(rx - rx_old)
+  rx_rate=(rx_delta / (ts_delta))
+  tx_delta=(tx - tx_old)
+  tx_rate=(tx_delta / (ts_delta))
+  printf("# (Kbyte/s) rx_rate=%-12.2f tx_rate=%-12.2f ts_delta=%-1.2f\n", (rx_rate / 1024), (tx_rate / 1024), ts_delta)
 }