Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Network Health
sbws
Commits
cc343eb8
Commit
cc343eb8
authored
Mar 01, 2021
by
juga
Browse files
fix: scaling: round bandwidth filtered
because Torflow does it.
parent
83e07312
Changes
3
Hide whitespace changes
Inline
Side-by-side
docs/source/torflow_aggr.rst
View file @
cc343eb8
...
@@ -203,6 +203,18 @@ From Torflow's `README.spec.txt`_ (section 1.6)::
...
@@ -203,6 +203,18 @@ From Torflow's `README.spec.txt`_ (section 1.6)::
In the code, `SQLSupport.py`_, ``strm_bw`` is ``sbw`` and
In the code, `SQLSupport.py`_, ``strm_bw`` is ``sbw`` and
``filt_bw`` is ``filt_sbws``::
``filt_bw`` is ``filt_sbws``::
for s in rs.router.streams:
if isinstance(s, ClosedStream):
tot_bytes += s.tot_bytes()
tot_duration += s.end_time - s.start_time
tot_bw += s.bandwidth()
s_cnt += 1
# FIXME: Hrmm.. do we want to do weighted avg or pure avg here?
# If files are all the same size, it shouldn't matter..
if s_cnt > 0:
rs.sbw = tot_bw/s_cnt
else: rs.sbw = None
for rs in RouterStats.query.filter(stats_clause).\
for rs in RouterStats.query.filter(stats_clause).\
options(eagerload_all('router.streams.circuit.routers')).all():
options(eagerload_all('router.streams.circuit.routers')).all():
tot_sbw = 0
tot_sbw = 0
...
@@ -224,6 +236,19 @@ In the code, `SQLSupport.py`_, ``strm_bw`` is ``sbw`` and
...
@@ -224,6 +236,19 @@ In the code, `SQLSupport.py`_, ``strm_bw`` is ``sbw`` and
if sbw_cnt: rs.filt_sbw = tot_sbw/sbw_cnt
if sbw_cnt: rs.filt_sbw = tot_sbw/sbw_cnt
else: rs.filt_sbw = None
else: rs.filt_sbw = None
When it is written to the file, it seem to write "None" string when
``filt_sbw`` or ``strm_bw`` are None. That would give an exception when
calculating the network average. So it never happen?::
def cvt(a,b,c=1):
if type(a) == float: return int(round(a/c,b))
elif type(a) == int: return a
elif type(a) == type(None): return "None"
else: return type(a)
f.write(" strm_bw="+str(cvt(s.sbw,0)))
f.write(" filt_bw="+str(cvt(s.filt_sbw,0)))
This is also expressed in pseudocode in the `bandwidth file spec`_, section B.4
This is also expressed in pseudocode in the `bandwidth file spec`_, section B.4
step 1.
step 1.
...
...
sbws/lib/scaling.py
View file @
cc343eb8
...
@@ -16,8 +16,10 @@ def bw_filt(bw_measurements):
...
@@ -16,8 +16,10 @@ def bw_filt(bw_measurements):
"""
"""
mu
=
1
mu
=
1
if
bw_measurements
:
if
bw_measurements
:
mu
=
mean
(
bw_measurements
)
# Torflow is rounding to an integer, so is `bw_mean_from_results` in
# `v3bwfile.py`
mu
=
round
(
mean
(
bw_measurements
))
bws_gte_mean
=
list
(
filter
(
lambda
bw
:
bw
>=
mu
,
bw_measurements
))
bws_gte_mean
=
list
(
filter
(
lambda
bw
:
bw
>=
mu
,
bw_measurements
))
if
bws_gte_mean
:
if
bws_gte_mean
:
return
mean
(
bws_gte_mean
)
return
round
(
mean
(
bws_gte_mean
)
)
return
1
return
1
tests/unit/lib/test_scaling.py
View file @
cc343eb8
"""Unit tests for scaling.py."""
"""Unit tests for scaling.py."""
from
statistics
import
mean
from
sbws.lib
import
scaling
from
sbws.lib
import
scaling
...
@@ -10,4 +11,30 @@ def test_bw_filt():
...
@@ -10,4 +11,30 @@ def test_bw_filt():
]
]
fb
=
scaling
.
bw_filt
(
bw_measurements
)
fb
=
scaling
.
bw_filt
(
bw_measurements
)
# This is greater than the mean, that is 61422.73714139576
# This is greater than the mean, that is 61422.73714139576
assert
fb
==
83505.81986994506
assert
fb
==
83506
# When there are no measurements what can not be the case for successful
# results.
bw_measurements
=
[]
assert
1
==
scaling
.
bw_filt
(
bw_measurements
)
bw_measurements
=
[
1
,
0
]
# Because rounded to int
assert
0
==
round
(
mean
(
bw_measurements
))
# So the filtered bw will be also 0
assert
0
==
scaling
.
bw_filt
(
bw_measurements
)
bw_measurements
=
[
1
,
2
,
3
]
# Because rounded to int
assert
2
==
round
(
mean
(
bw_measurements
))
assert
2
==
scaling
.
bw_filt
(
bw_measurements
)
bw_measurements
=
[
10
,
0
]
assert
5
==
round
(
mean
(
bw_measurements
))
# Because the value 10 is bigger than the mean
assert
10
==
scaling
.
bw_filt
(
bw_measurements
)
bw_measurements
=
[
0
,
10
,
20
]
assert
10
==
round
(
mean
(
bw_measurements
))
# Because 10 and 20 are bigger or equal than the mean
assert
15
==
scaling
.
bw_filt
(
bw_measurements
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment