Added a new underload detection algorithm: last_n_average_threshold
This commit is contained in:
parent
df55d8b401
commit
5a924db694
@ -42,6 +42,28 @@ def threshold_factory(time_step, migration_time, params):
|
||||
utilization),
|
||||
{})
|
||||
|
||||
@contract
|
||||
def last_n_average_threshold_factory(time_step, migration_time, params):
|
||||
""" Creates the averaging threshold underload detection algorithm.
|
||||
|
||||
:param time_step: The length of the simulation time step in seconds.
|
||||
:type time_step: int,>=0
|
||||
|
||||
:param migration_time: The VM migration time in time seconds.
|
||||
:type migration_time: float,>=0
|
||||
|
||||
:param params: A dictionary containing the algorithm's parameters.
|
||||
:type params: dict(str: *)
|
||||
|
||||
:return: A function implementing the OTF algorithm.
|
||||
:rtype: function
|
||||
"""
|
||||
return lambda utilization, state=None: (
|
||||
last_n_average_threshold(params['threshold'],
|
||||
params['n'],
|
||||
utilization),
|
||||
{})
|
||||
|
||||
|
||||
@contract
|
||||
def threshold(threshold, utilization):
|
||||
@ -62,3 +84,28 @@ def threshold(threshold, utilization):
|
||||
if utilization:
|
||||
return utilization[-1] <= threshold
|
||||
return False
|
||||
|
||||
|
||||
@contract
|
||||
def last_n_average_threshold(threshold, n, utilization):
|
||||
""" Averaging static threshold-based underload detection algorithm.
|
||||
|
||||
The algorithm returns True, if the average of the last n values of
|
||||
the host's CPU utilization is lower than the specified threshold.
|
||||
|
||||
:param threshold: The static underload CPU utilization threshold.
|
||||
:type threshold: float,>=0,<=1
|
||||
|
||||
:param n: The number of last values to average.
|
||||
:type n: int,>0
|
||||
|
||||
:param utilization: The history of the host's CPU utilization.
|
||||
:type utilization: list(float)
|
||||
|
||||
:return: A decision of whether the host is underloaded.
|
||||
:rtype: bool
|
||||
"""
|
||||
if utilization:
|
||||
utilization = utilization[-n:]
|
||||
return sum(utilization) / len(utilization) <= threshold
|
||||
return False
|
||||
|
@ -32,6 +32,27 @@ class Trivial(TestCase):
|
||||
self.assertEqual(alg([0.0, 0.6]), (False, {}))
|
||||
self.assertEqual(alg([0.0, 1.0]), (False, {}))
|
||||
|
||||
|
||||
def test_last_n_average_threshold_factory(self):
|
||||
alg = trivial.last_n_average_threshold_factory(
|
||||
300, 20., {'threshold': 0.5,
|
||||
'n': 2})
|
||||
self.assertEqual(alg([]), (False, {}))
|
||||
self.assertEqual(alg([0.0, 0.0]), (True, {}))
|
||||
self.assertEqual(alg([0.0, 0.4]), (True, {}))
|
||||
self.assertEqual(alg([0.0, 0.5]), (True, {}))
|
||||
self.assertEqual(alg([0.0, 0.6]), (True, {}))
|
||||
self.assertEqual(alg([0.0, 1.0]), (True, {}))
|
||||
self.assertEqual(alg([0.2, 1.0]), (False, {}))
|
||||
self.assertEqual(alg([0.0, 0.2, 1.0]), (False, {}))
|
||||
self.assertEqual(alg([0.0, 1.0, 1.0]), (False, {}))
|
||||
self.assertEqual(alg([0.0, 0.6, 0.6]), (False, {}))
|
||||
|
||||
alg = trivial.last_n_average_threshold_factory(
|
||||
300, 20., {'threshold': 0.5,
|
||||
'n': 3})
|
||||
self.assertEqual(alg([0.0, 0.6, 0.6]), (True, {}))
|
||||
|
||||
def test_threshold(self):
|
||||
self.assertEqual(trivial.threshold(0.5, []), False)
|
||||
self.assertEqual(trivial.threshold(0.5, [0.0, 0.0]), True)
|
||||
@ -39,3 +60,27 @@ class Trivial(TestCase):
|
||||
self.assertEqual(trivial.threshold(0.5, [0.0, 0.5]), True)
|
||||
self.assertEqual(trivial.threshold(0.5, [0.0, 0.6]), False)
|
||||
self.assertEqual(trivial.threshold(0.5, [0.0, 1.0]), False)
|
||||
|
||||
def test_last_n_average_threshold(self):
|
||||
self.assertEqual(trivial.last_n_average_threshold(
|
||||
0.5, 2, []), False)
|
||||
self.assertEqual(trivial.last_n_average_threshold(
|
||||
0.5, 2, [0.0, 0.0]), True)
|
||||
self.assertEqual(trivial.last_n_average_threshold(
|
||||
0.5, 2, [0.0, 0.4]), True)
|
||||
self.assertEqual(trivial.last_n_average_threshold(
|
||||
0.5, 2, [0.0, 0.5]), True)
|
||||
self.assertEqual(trivial.last_n_average_threshold(
|
||||
0.5, 2, [0.0, 0.6]), True)
|
||||
self.assertEqual(trivial.last_n_average_threshold(
|
||||
0.5, 2, [0.0, 1.0]), True)
|
||||
self.assertEqual(trivial.last_n_average_threshold(
|
||||
0.5, 2, [0.2, 1.0]), False)
|
||||
self.assertEqual(trivial.last_n_average_threshold(
|
||||
0.5, 2, [0.0, 0.2, 1.0]), False)
|
||||
self.assertEqual(trivial.last_n_average_threshold(
|
||||
0.5, 2, [0.0, 1.0, 1.0]), False)
|
||||
self.assertEqual(trivial.last_n_average_threshold(
|
||||
0.5, 2, [0.0, 0.6, 0.6]), False)
|
||||
self.assertEqual(trivial.last_n_average_threshold(
|
||||
0.5, 3, [0.0, 0.6, 0.6]), True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user