[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [sbws/master] chg: v3bwfile: Calculate filtered bandwidth
commit c030731ec25adeff750c8c00415b87521a10d581
Author: juga0 <juga@xxxxxxxxxx>
Date: Sat May 16 17:55:50 2020 +0000
chg: v3bwfile: Calculate filtered bandwidth
for each relay, calculate the filtered mean for all relays and
calculate the filtered ratio for each relay.
---
sbws/lib/v3bwfile.py | 14 +++++++++++---
tests/unit/lib/test_scaling.py | 13 +++++++++++++
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index 245ffa6..9a303be 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -15,6 +15,7 @@ from sbws.globals import (SPEC_VERSION, BW_LINE_SIZE, SBWS_SCALE_CONSTANT,
TORFLOW_SCALING, SBWS_SCALING, TORFLOW_BW_MARGIN,
TORFLOW_OBS_LAST, TORFLOW_OBS_MEAN,
PROP276_ROUND_DIG, MIN_REPORT, MAX_BW_DIFF_PERC)
+from sbws.lib import scaling
from sbws.lib.resultdump import ResultSuccess, _ResultType
from sbws.util.filelock import DirectoryLock
from sbws.util.timestamp import (now_isodt_str, unixts_to_isodt_str,
@@ -631,8 +632,10 @@ class V3BWLine(object):
assert node_id.startswith('$')
self.node_id = node_id
self.bw = bw
+ # For now, we do not want to add ``bw_filt`` to the bandwidth file,
+ # therefore it is set here but not added to ``BWLINE_KEYS_V1``.
[setattr(self, k, v) for k, v in kwargs.items()
- if k in BWLINE_KEYS_V1]
+ if k in BWLINE_KEYS_V1 + ["bw_filt"]]
def __str__(self):
return self.bw_strv1
@@ -762,7 +765,11 @@ class V3BWLine(object):
if rtt:
kwargs['rtt'] = rtt
bw = cls.bw_median_from_results(results_recent)
+ # XXX: all the class functions could use the bw_measurements instead of
+ # obtaining them each time or use a class Measurements.
+ bw_measurements = scaling.bw_measurements_from_results(results_recent)
kwargs['bw_mean'] = cls.bw_mean_from_results(results_recent)
+ kwargs['bw_filt'] = scaling.bw_filt(bw_measurements)
kwargs['bw_median'] = cls.bw_median_from_results(
results_recent)
kwargs['desc_bw_avg'] = \
@@ -1311,7 +1318,8 @@ class V3BWFile(object):
# mean (Torflow's strm_avg)
mu = mean([l.bw_mean for l in bw_lines])
# filtered mean (Torflow's filt_avg)
- muf = mean([max(l.bw_mean, mu) for l in bw_lines])
+ muf = mean([l.bw_filt for l in bw_lines])
+
# bw sum (Torflow's tot_net_bw or tot_sbw)
sum_bw = sum([l.bw_mean for l in bw_lines])
# Torflow's clipping
@@ -1369,7 +1377,7 @@ class V3BWFile(object):
min_bandwidth = min(desc_bw, l.consensus_bandwidth)
# Torflow's scaling
ratio_stream = l.bw_mean / mu
- ratio_stream_filtered = max(l.bw_mean, mu) / muf
+ ratio_stream_filtered = l.bw_filt / muf
ratio = max(ratio_stream, ratio_stream_filtered)
bw_scaled = ratio * min_bandwidth
# round and convert to KB
diff --git a/tests/unit/lib/test_scaling.py b/tests/unit/lib/test_scaling.py
new file mode 100644
index 0000000..06fb71b
--- /dev/null
+++ b/tests/unit/lib/test_scaling.py
@@ -0,0 +1,13 @@
+"""Unit tests for scaling.py."""
+
+from sbws.lib import scaling
+
+
+def test_bw_filt():
+ bw_measurements = [
+ 96700.00922329757, 70311.63051659254, 45531.743347556374,
+ 38913.97025485627, 55656.332364676025
+ ]
+ fb = scaling.bw_filt(bw_measurements)
+ # This is greater than the mean, that is 61422.73714139576
+ assert fb == 83505.81986994506
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits