From 7a7ea9bbf2f29ed7deba95af5234400a457df32a Mon Sep 17 00:00:00 2001 From: Anton Beloglazov Date: Sat, 26 Jan 2013 13:38:29 +1100 Subject: [PATCH] OTF: migrate only if the host is currently overloaded --- neat/locals/overload/otf.py | 8 +++++--- tests/locals/overload/test_otf.py | 30 ++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/neat/locals/overload/otf.py b/neat/locals/overload/otf.py index e5e3a82..e7f18e5 100644 --- a/neat/locals/overload/otf.py +++ b/neat/locals/overload/otf.py @@ -79,10 +79,12 @@ def otf(otf, threshold, limit, migration_time, utilization, state): :rtype: tuple(bool, dict(*: *)) """ state['total'] += 1 - if utilization[-1] >= threshold: + overload = (utilization[-1] >= threshold) + if overload: state['overload'] += 1 if log.isEnabledFor(logging.DEBUG): + log.debug('OTF overload:' + str(overload)) log.debug('OTF overload steps:' + str(state['overload'])) log.debug('OTF total steps:' + str(state['total'])) log.debug('OTF:' + str(float(state['overload']) / state['total'])) @@ -91,10 +93,10 @@ def otf(otf, threshold, limit, migration_time, utilization, state): str((migration_time + state['overload']) / \ (migration_time + state['total']))) log.debug('OTF decision:' + - str((migration_time + state['overload']) / \ + str(overload and (migration_time + state['overload']) / \ (migration_time + state['total']) >= otf)) - if len(utilization) < limit: + if not overload or len(utilization) < limit: decision = False else: decision = (migration_time + state['overload']) / \ diff --git a/tests/locals/overload/test_otf.py b/tests/locals/overload/test_otf.py index f6d3bd8..b49b442 100644 --- a/tests/locals/overload/test_otf.py +++ b/tests/locals/overload/test_otf.py @@ -49,16 +49,26 @@ class Otf(TestCase): decision, state = otf.otf(0.5, 1.0, 4, 100., [0.9, 1.3, 1.1, 1.2, 0.3], state) self.assertEqual(state, {'overload': 3, 'total': 5}) + self.assertFalse(decision) + + decision, state = otf.otf(0.5, 1.0, 4, 1., + [0.9, 1.3, 1.1, 1.2, 1.3], state) + self.assertEqual(state, {'overload': 4, 'total': 6}) self.assertTrue(decision) decision, state = otf.otf(0.5, 1.0, 4, 1., [0.9, 1.3, 1.1, 1.2, 0.3, 0.2], state) - self.assertEqual(state, {'overload': 3, 'total': 6}) - self.assertTrue(decision) + self.assertEqual(state, {'overload': 4, 'total': 7}) + self.assertFalse(decision) decision, state = otf.otf(0.5, 1.0, 4, 0., [0.9, 1.3, 1.1, 1.2, 0.3, 0.2, 0.1], state) - self.assertEqual(state, {'overload': 3, 'total': 7}) + self.assertEqual(state, {'overload': 4, 'total': 8}) + self.assertFalse(decision) + + decision, state = otf.otf(0.5, 1.0, 4, 0., + [0.9, 1.3, 1.1, 1.2, 0.3, 0.2, 0.1, 0.1], state) + self.assertEqual(state, {'overload': 4, 'total': 9}) self.assertFalse(decision) @@ -84,12 +94,20 @@ class Otf(TestCase): decision, state = alg([0.9, 1.3, 1.1, 1.2, 0.3], state) self.assertEqual(state, {'overload': 3, 'total': 5}) + self.assertFalse(decision) + + decision, state = alg([0.9, 1.3, 1.1, 1.2, 1.3], state) + self.assertEqual(state, {'overload': 4, 'total': 6}) self.assertTrue(decision) decision, state = alg([0.9, 1.3, 1.1, 1.2, 0.3, 0.2], state) - self.assertEqual(state, {'overload': 3, 'total': 6}) - self.assertTrue(decision) + self.assertEqual(state, {'overload': 4, 'total': 7}) + self.assertFalse(decision) decision, state = alg([0.9, 1.3, 1.1, 1.2, 0.3, 0.2, 0.1], state) - self.assertEqual(state, {'overload': 3, 'total': 7}) + self.assertEqual(state, {'overload': 4, 'total': 8}) + self.assertFalse(decision) + + decision, state = alg([0.9, 1.3, 1.1, 1.2, 0.3, 0.2, 0.1, 0.1], state) + self.assertEqual(state, {'overload': 4, 'total': 9}) self.assertFalse(decision)