Hello Pau Espin Pedrol, Harald Welte, Jenkins Builder, I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/6230 to look at the new patch set (#4). ms: Create a cumulative distribution function class We are using the CDF to decide which percentage of the jobs should be running at a given point. The x-axis is time and the y-axis the percentage of how many jobs should be running. There are three functions to do this. The first one is a constant which would result in everything being started right now, one to start them linearly and the last (formula from Qt/3rdparty) to first accelerate and decelerate slowly. Change-Id: I9e3064f4c3c4c7af5d3491f850090516e541f4d3 --- A src/osmo_ms_driver/__init__.py A src/osmo_ms_driver/cdf.py 2 files changed, 252 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/30/6230/4 diff --git a/src/osmo_ms_driver/__init__.py b/src/osmo_ms_driver/__init__.py new file mode 100644 index 0000000..d3c1590 --- /dev/null +++ b/src/osmo_ms_driver/__init__.py @@ -0,0 +1,29 @@ +# osmo_gsm_tester: automated cellular network hardware tests +# +# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH +# +# Authors: D. Lazlo Sitzer <dlsit...@sysmocom.de> +# Neels Hofmeyr <ne...@hofmeyr.de> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +__version__ = 'UNKNOWN' + +try: + from ._version import _version + __version__ = _version +except: + pass + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/src/osmo_ms_driver/cdf.py b/src/osmo_ms_driver/cdf.py new file mode 100644 index 0000000..d5809e1 --- /dev/null +++ b/src/osmo_ms_driver/cdf.py @@ -0,0 +1,223 @@ +# osmo_ms_driver: A cumululative distribution function class. +# Help to start processes over time. +# +# Copyright (C) 2018 by Holger Hans Peter Freyther +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + +from datetime import timedelta + +class DistributionFunctionHandler(object): + """ + The goal is to start n "mobile" processes. We like to see some + conflicts (RACH bursts being ignored) but starting n processes + at the same time is not a realistic model. + We use the concept of cumulative distribution function here. On + the x-axis we have time (maybe in steps of 10ms) and on the + y-axis we have the percentage (from 0.0 to 1.0) of how many + processes should run at the given time. + """ + + def __init__(self, step, duration, fun): + self._step = step + self._fun = fun + self._x = 0.0 + self._y = self._fun(self._x) + self._target = 1.0 + self._duration = duration + + def step_size(self): + return self._step + + def set_target(self, scale): + """ + Scale the percentage to the target value.. + """ + self._target = scale + + def is_done(self): + return self._y >= 1.0 + + def current_value(self): + return self._y + + def current_scaled_value(self): + return self._y * self._target + + def step_once(self): + self._x = self._x + self._step.total_seconds() + self._y = self._fun(self._x) + + def duration(self): + return self._duration + + +def immediate(step_size=timedelta(milliseconds=20)): + """ + Reaches 100% at the first step. + + Example: + >>> a = immediate() + >>> a.is_done() + True + >>> a.current_value() + 1 + """ + duration = timedelta(seconds=0) + return DistributionFunctionHandler(step_size, duration, lambda x: 1) + +def linear_with_slope(slope, duration, step_size=timedelta(milliseconds=20)): + """ + Use the slope and step size you want + """ + return DistributionFunctionHandler(step_size, duration, lambda x: slope*x) + +def linear_with_duration(duration, step_size=timedelta(milliseconds=20)): + """ + Linear progression that reaches 100% after duration.total_seconds() + >>> a = linear_with_duration(timedelta(seconds=10), step_size=timedelta(seconds=2)) + >>> a.is_done() + False + >>> a.current_value() + 0.0 + >>> a.step_once() + >>> a.current_value() + 0.2 + >>> a.step_once() + >>> a.current_value() + 0.4 + >>> a.step_once() + >>> a.current_value() + 0.6... + >>> a.step_once() + >>> a.current_value() + 0.8... + >>> a.is_done() + False + >>> a.step_once() + >>> a.current_value() + 1.0... + >>> a.is_done() + True + + >>> a = linear_with_duration(timedelta(seconds=10), step_size=timedelta(seconds=2)) + >>> a.set_target(1000) + >>> a.is_done() + False + >>> a.current_value() + 0.0 + >>> a.current_scaled_value() + 0.0 + >>> a.step_once() + >>> a.current_value() + 0.2 + >>> a.current_scaled_value() + 200.0 + >>> a.step_once() + >>> a.current_value() + 0.4 + >>> a.current_scaled_value() + 400.0 + >>> a.step_once() + >>> a.current_value() + 0.6... + >>> a.current_scaled_value() + 600.0... + >>> a.step_once() + >>> a.current_value() + 0.8... + >>> a.current_scaled_value() + 800.0... + >>> a.is_done() + False + >>> a.step_once() + >>> a.current_value() + 1.0... + >>> a.current_scaled_value() + 1000.0... + >>> a.is_done() + True + """ + slope = 1.0/duration.total_seconds() + return linear_with_slope(slope, duration, step_size) + +def _in_out(x): + """ + Internal in/out function inspired by Qt + + >>> _in_out(0.5) + 0.5... + >>> _in_out(0.75) + 0.875... + >>> _in_out(0.8) + 0.92... + >>> _in_out(0.85) + 0.955... + >>> _in_out(1.0) + 1.0... + """ + assert x <= 1.0 + # Needs to be between 0..1 and increase first + if x < 0.5: + return (x*x) * 2 + # deaccelerate now. in_out(0.5) == 0.5, in_out(1.0) == 1.0 + x = x * 2 - 1 + return -0.5 * (x*(x-2)- 1) + +def ease_in_out_duration(duration, step_size=timedelta(milliseconds=20)): + """ + Example invocation + + >>> a = ease_in_out_duration(duration=timedelta(seconds=20), step_size=timedelta(seconds=5)) + >>> a.is_done() + False + >>> a.current_value() + 0.0 + + >>> a.step_once() + >>> a._x + 5.0 + >>> a.current_value() + 0.125 + >>> a.is_done() + False + + >>> a.step_once() + >>> a._x + 10.0 + >>> a.current_value() + 0.5 + >>> a.is_done() + False + + >>> a.step_once() + >>> a._x + 15.0 + >>> a.current_value() + 0.875 + >>> a.is_done() + False + + >>> a.step_once() + >>> a._x + 20.0 + >>> a.current_value() + 1.0 + >>> a.is_done() + True + """ + scale = 1.0/duration.total_seconds() + return DistributionFunctionHandler(step_size, duration, + lambda x: _in_out(x*scale)) -- To view, visit https://gerrit.osmocom.org/6230 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newpatchset Gerrit-Change-Id: I9e3064f4c3c4c7af5d3491f850090516e541f4d3 Gerrit-PatchSet: 4 Gerrit-Project: osmo-gsm-tester Gerrit-Branch: master Gerrit-Owner: Holger Freyther <hol...@freyther.de> Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org> Gerrit-Reviewer: Holger Freyther <hol...@freyther.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: Pau Espin Pedrol <pes...@sysmocom.de> Gerrit-Reviewer: Vadim Yanitskiy <axilira...@gmail.com>