mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
feat(computes): Balance and the spread count each host's share of its size
Balance evened out the memory, then the vCPUs, the hosts give their running VMs, and the Bulk Migrate spread sent a VM to the host with the least memory: a host twice as large got the same as a small one. Both now count each host's load against its memory and CPUs: propose lowers the sum of each host's load squared over its size, least when every host has the same share; spread sends a VM to the host with the least share after it. With hosts of one size the proposal is the same as before. The Balance page shows each host's memory, its CPUs next to the vCPUs, and the bars as the share of the host's own memory.
This commit is contained in:
parent
ea20f12bc8
commit
070a4b99da
8 changed files with 179 additions and 133 deletions
|
|
@ -1,6 +1,6 @@
|
|||
"""Balance proposes migrations of running VMs that even out the memory, then
|
||||
the vCPUs, the hosts give their running VMs, and runs the proposal shown in
|
||||
one job of migrate jobs that take only a running VM."""
|
||||
"""Balance proposes migrations of running VMs that even out the share of
|
||||
their memory, then of their CPUs, the hosts give their running VMs, and runs
|
||||
the proposal shown in one job of migrate jobs that take only a running VM."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
|
|
@ -20,6 +20,7 @@ DOMAIN = """<domain type='test'><name>{name}</name><memory unit='MiB'>128</memor
|
|||
<os><type arch='i686'>hvm</type></os>{disk}</domain>"""
|
||||
LOCAL = "<devices><disk type='file' device='disk'><source file='/local/{name}.img'/><target dev='vda'/></disk></devices>"
|
||||
ROOM = {"a": 100, "b": 100, "c": 100, "d": 100}
|
||||
SIZES = {host: (64, 16) for host in "abcd"} # hosts of one size
|
||||
|
||||
|
||||
class ProposeTests(SimpleTestCase):
|
||||
|
|
@ -28,64 +29,83 @@ class ProposeTests(SimpleTestCase):
|
|||
loads = {"a": (10, 0), "b": (10, 0), "c": (0, 0), "d": (0, 0)}
|
||||
vms = [(1, "a", 5, 0, {"b", "c", "d"}), (2, "a", 5, 0, {"b", "c", "d"}),
|
||||
(3, "b", 5, 0, {"a", "c", "d"}), (4, "b", 5, 0, {"a", "c", "d"})]
|
||||
moves, after = propose(loads, vms, ROOM)
|
||||
moves, after = propose(loads, vms, ROOM, SIZES)
|
||||
self.assertEqual(len(moves), 2)
|
||||
self.assertEqual(sorted(load[0] for load in after.values()), [5, 5, 5, 5])
|
||||
|
||||
def test_the_memory_comes_first_then_the_vcpus(self):
|
||||
loads = {"a": (8, 2), "b": (0, 6)}
|
||||
vms = [(1, "a", 4, 1, {"b"}), (2, "b", 0, 3, {"a"})]
|
||||
moves, after = propose(loads, vms, ROOM)
|
||||
moves, after = propose(loads, vms, ROOM, SIZES)
|
||||
self.assertEqual(moves, [(1, "a", "b"), (2, "b", "a")])
|
||||
self.assertEqual(after, {"a": [4, 4], "b": [4, 4]})
|
||||
|
||||
def test_a_vm_moves_once_and_only_where_it_may_go(self):
|
||||
loads = {"a": (12, 0), "b": (0, 0), "c": (0, 0)}
|
||||
moves, _after = propose(loads, [(1, "a", 6, 0, {"b"}), (2, "a", 6, 0, {"b"})], ROOM)
|
||||
moves, _after = propose(loads, [(1, "a", 6, 0, {"b"}), (2, "a", 6, 0, {"b"})], ROOM, SIZES)
|
||||
self.assertEqual(moves, [(1, "a", "b")])
|
||||
|
||||
def test_no_move_fills_a_host_past_its_room(self):
|
||||
loads = {"a": (60, 0), "b": (50, 0)}
|
||||
self.assertEqual(propose(loads, [(1, "a", 30, 0, {"b"})], {"a": 40, "b": 20}), ([], {"a": [60, 0], "b": [50, 0]}))
|
||||
self.assertEqual(propose(loads, [(1, "a", 30, 0, {"b"})], {"a": 40, "b": 20}, SIZES), ([], {"a": [60, 0], "b": [50, 0]}))
|
||||
|
||||
def test_a_vm_moved_away_makes_no_room_for_one_moved_in(self):
|
||||
# b's room stays 0 after vm 2 leaves it: vm 1 would fill b before vm 2 has left, if it ran first
|
||||
loads = {"a": (100, 0), "b": (80, 0), "c": (0, 0)}
|
||||
vms = [(1, "a", 30, 0, {"b"}), (2, "b", 40, 0, {"c"})]
|
||||
self.assertEqual(propose(loads, vms, {"a": 0, "b": 0, "c": 100})[0], [(2, "b", "c")])
|
||||
self.assertEqual(propose(loads, vms, {"a": 0, "b": 0, "c": 100}, SIZES)[0], [(2, "b", "c")])
|
||||
|
||||
def test_small_vms_move_rather_than_a_large_one_for_the_same_balance(self):
|
||||
# a: a large VM (16) and two small ones (1, 2); b: one small VM (1). Moving the large VM to b and
|
||||
# the small one back ends as even as moving the two small ones, which moves far less memory
|
||||
loads = {"a": (19, 7), "b": (1, 4)}
|
||||
vms = [(1, "a", 16, 2, {"b"}), (2, "a", 1, 1, {"b"}), (3, "a", 2, 4, {"b"}), (4, "b", 1, 4, {"a"})]
|
||||
moves, after = propose(loads, vms, ROOM)
|
||||
moves, after = propose(loads, vms, ROOM, SIZES)
|
||||
self.assertEqual(moves, [(2, "a", "b"), (3, "a", "b")])
|
||||
self.assertEqual(after, {"a": [16, 2], "b": [4, 9]})
|
||||
|
||||
def test_a_large_vm_moves_when_only_it_evens_out_the_hosts(self):
|
||||
loads = {"a": (20, 0), "b": (0, 0)}
|
||||
vms = [(1, "a", 10, 0, {"b"}), (2, "a", 1, 0, {"b"})]
|
||||
self.assertEqual(propose(loads, vms, {"a": 100, "b": 100})[0], [(1, "a", "b")])
|
||||
self.assertEqual(propose(loads, vms, {"a": 100, "b": 100}, SIZES)[0], [(1, "a", "b")])
|
||||
|
||||
def test_even_hosts_need_no_move(self):
|
||||
loads = {"a": (4, 2), "b": (4, 2)}
|
||||
self.assertEqual(propose(loads, [(1, "a", 4, 2, {"b"})], ROOM)[0], [])
|
||||
self.assertEqual(propose(loads, [(1, "a", 4, 2, {"b"})], ROOM, SIZES)[0], [])
|
||||
|
||||
|
||||
def test_a_host_twice_as_large_takes_twice_the_memory(self):
|
||||
loads = {"a": (12, 0), "b": (0, 0)}
|
||||
vms = [(n, "a", 2, 0, {"b"}) for n in range(1, 7)]
|
||||
moves, after = propose(loads, vms, ROOM, {"a": (32, 8), "b": (64, 8)})
|
||||
self.assertEqual(len(moves), 4)
|
||||
self.assertEqual(after, {"a": [4, 0], "b": [8, 0]})
|
||||
|
||||
def test_the_vcpus_count_against_the_cpus_of_each_host(self):
|
||||
loads = {"a": (0, 6), "b": (0, 0)}
|
||||
_moves, after = propose(loads, [(n, "a", 0, 1, {"b"}) for n in range(1, 7)], ROOM, {"a": (64, 4), "b": (64, 8)})
|
||||
self.assertEqual(after, {"a": [0, 2], "b": [0, 4]})
|
||||
|
||||
|
||||
class SpreadTests(SimpleTestCase):
|
||||
def test_the_largest_vm_goes_first_each_to_the_emptiest_host(self):
|
||||
loads = {"b": (4, 0), "c": (0, 0)}
|
||||
vms = [(1, 2, 1, True, {"b", "c"}), (2, 6, 1, True, {"b", "c"}), (3, 3, 1, False, {"b", "c"})]
|
||||
placed, after = spread(loads, vms, ROOM)
|
||||
placed, after = spread(loads, vms, ROOM, SIZES)
|
||||
self.assertEqual(placed, {2: "c", 3: "b", 1: "c"})
|
||||
self.assertEqual(after, {"b": [7, 1], "c": [8, 2]})
|
||||
|
||||
def test_a_running_vm_goes_only_where_it_fits_and_a_shut_off_one_anywhere(self):
|
||||
loads = {"b": (0, 0)}
|
||||
placed, _after = spread(loads, [(1, 8, 1, True, {"b"}), (2, 8, 1, False, {"b"})], {"b": 4})
|
||||
placed, _after = spread(loads, [(1, 8, 1, True, {"b"}), (2, 8, 1, False, {"b"})], {"b": 4}, SIZES)
|
||||
self.assertEqual(placed, {2: "b"})
|
||||
|
||||
def test_the_larger_host_takes_more(self):
|
||||
loads = {"b": (0, 0), "c": (0, 0)}
|
||||
vms = [(n, 2, 0, False, {"b", "c"}) for n in range(1, 7)]
|
||||
_placed, after = spread(loads, vms, ROOM, {"b": (32, 8), "c": (64, 8)})
|
||||
self.assertEqual(after, {"b": [4, 0], "c": [8, 0]})
|
||||
|
||||
|
||||
class BalancePageTests(TestCase):
|
||||
def setUp(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue