Skip to content
Snippets Groups Projects
Unverified Commit 0c5415d4 authored by juga's avatar juga Committed by GitHub
Browse files

Merge pull request #255 from juga0/ticket27337_round_bw

Ticket27337 round bw
parents 1603c888 d09dc0e5
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Implement Torflow scaling (#27108)
- Create methods to easy graph generation and obtain statistics
to compare with current torflow results.(#27688)
- Implement rounding bw in bandwidth files to 2 insignificant digits(#27337)
### Fixed
......
from sbws.globals import (fail_hard, SBWS_SCALE_CONSTANT, TORFLOW_SCALING,
SBWS_SCALING, TORFLOW_BW_MARGIN)
SBWS_SCALING, TORFLOW_BW_MARGIN, TORFLOW_ROUND_DIG)
from sbws.lib.v3bwfile import V3BWFile
from sbws.lib.resultdump import load_recent_results_in_datadir
from argparse import ArgumentDefaultsHelpFormatter
......@@ -44,6 +44,10 @@ def gen_parser(sub):
type=float,
help="Cap maximum bw when scaling as Torflow. "
"(Default: 0.05)")
p.add_argument('-r', '--torflow-round-digs', default=TORFLOW_ROUND_DIG,
type=int,
help="Number of most significant digits to round bw "
"when scaling as Torflow. (Default: 3)")
def main(args, conf):
......@@ -77,7 +81,8 @@ def main(args, conf):
state_fpath = conf.getpath('paths', 'state_fname')
bw_file = V3BWFile.from_results(results, state_fpath, args.scale_constant,
scaling_method,
torflow_cap=args.torflow_bw_margin)
torflow_cap=args.torflow_bw_margin,
torflow_round_digs=args.torflow_round_digs)
output = args.output or \
conf.getpath('paths', 'v3bw_fname').format(now_fname())
bw_file.write(output)
......
......@@ -37,6 +37,7 @@ TORFLOW_BW_MARGIN = 0.05
TORFLOW_OBS_LAST = 0
TORFLOW_OBS_MEAN = 1
TORFLOW_OBS_DECAYING = 3
TORFLOW_ROUND_DIG = 3
BW_LINE_SIZE = 510
......
......@@ -9,8 +9,9 @@ from statistics import median, mean
from sbws import __version__
from sbws.globals import (SPEC_VERSION, BW_LINE_SIZE, SBWS_SCALE_CONSTANT,
SBWS_SCALING, TORFLOW_BW_MARGIN, TORFLOW_SCALING,
TORFLOW_OBS_LAST, TORFLOW_OBS_MEAN)
TORFLOW_SCALING, SBWS_SCALING, TORFLOW_BW_MARGIN,
TORFLOW_OBS_LAST, TORFLOW_OBS_MEAN,
TORFLOW_ROUND_DIG)
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
......@@ -48,6 +49,12 @@ BW_KEYVALUES_INT = ['bw', 'rtt', 'success', 'error_stream',
BW_KEYVALUES = BW_KEYVALUES_BASIC + BW_KEYVALUES_EXTRA
def kb_round_x_sig_dig(bw_bs, digits=TORFLOW_ROUND_DIG):
"""Convert bw to KB and round to x most significat digits."""
bw_kb = bw_bs / 1000
return max(int(round(bw_kb, -digits)), 1)
def num_results_of_type(results, type_str):
return len([r for r in results if r.type == type_str])
......@@ -399,6 +406,7 @@ class V3BWFile(object):
scale_constant=SBWS_SCALE_CONSTANT,
scaling_method=None, torflow_obs=TORFLOW_OBS_LAST,
torflow_cap=TORFLOW_BW_MARGIN,
torflow_round_digs=TORFLOW_ROUND_DIG,
reverse=False):
"""Create V3BWFile class from sbws Results.
......@@ -434,7 +442,7 @@ class V3BWFile(object):
# log.debug(bw_lines[-1])
elif scaling_method == TORFLOW_SCALING:
bw_lines = cls.bw_torflow_scale(bw_lines_raw, torflow_obs,
torflow_cap)
torflow_cap, torflow_round_digs)
# log.debug(bw_lines[-1])
else:
bw_lines = cls.bw_kb(bw_lines_raw)
......@@ -519,7 +527,8 @@ class V3BWFile(object):
@staticmethod
def bw_torflow_scale(bw_lines, desc_obs_bws=TORFLOW_OBS_LAST,
cap=TORFLOW_BW_MARGIN, reverse=False):
cap=TORFLOW_BW_MARGIN,
num_round_dig=TORFLOW_ROUND_DIG, reverse=False):
"""
Obtain final bandwidth measurements applying Torflow's scaling
method.
......@@ -699,11 +708,12 @@ class V3BWFile(object):
elif desc_obs_bws == TORFLOW_OBS_MEAN:
desc_obs_bw = l.desc_obs_bw_bs_mean
# just applying the formula above:
bw_new = max(
bw_new = kb_round_x_sig_dig(
max(
l.bw_bs_mean / mu, # ratio
min(l.bw_bs_mean, mu) / muf # ratio filtered
) * desc_obs_bw \
/ 1000 # convert to KB
) * desc_obs_bw, \
digits=num_round_dig) # convert to KB
# Cap maximum bw
if cap is not None:
bw_new = min(hlimit, bw_new)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment