From: Johannes Truschnigg Date: Tue, 15 Mar 2022 19:53:38 +0000 (+0100) Subject: Implement/improve bw usage estimation X-Git-Url: https://johannes.truschnigg.info/gitweb/?a=commitdiff_plain;h=e25e0f039fc9b3404c8e3426ba863d2480f25c55;p=sqm_lagthrottle Implement/improve bw usage estimation --- diff --git a/__lagdetect.awk b/__lagdetect.awk index 827264d..38a090d 100644 --- a/__lagdetect.awk +++ b/__lagdetect.awk @@ -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) }