Moved calculate_migration_time from the local manager to common
This commit is contained in:
parent
de2e988713
commit
f92079c565
@ -21,6 +21,7 @@ from neat.contracts_extra import *
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
import numpy
|
||||||
|
|
||||||
from neat.config import *
|
from neat.config import *
|
||||||
from neat.db_utils import *
|
from neat.db_utils import *
|
||||||
@ -221,4 +222,19 @@ def parse_parameters(params):
|
|||||||
"""
|
"""
|
||||||
return dict((str(k), v)
|
return dict((str(k), v)
|
||||||
for k, v in json.loads(params).items())
|
for k, v in json.loads(params).items())
|
||||||
|
|
||||||
|
|
||||||
|
@contract
|
||||||
|
def calculate_migration_time(vms, bandwidth):
|
||||||
|
""" Calculate the mean migration time from VM RAM usage data.
|
||||||
|
|
||||||
|
:param vms: A map of VM UUIDs to the corresponding maximum RAM in MB.
|
||||||
|
:type vms: dict(str: int)
|
||||||
|
|
||||||
|
:param bandwidth: The network bandwidth in MB/s.
|
||||||
|
:type bandwidth: float,>0
|
||||||
|
|
||||||
|
:return: The mean VM migration time in seconds.
|
||||||
|
:rtype: float
|
||||||
|
"""
|
||||||
|
return float(numpy.mean(vms.values()) / bandwidth)
|
||||||
|
@ -267,8 +267,8 @@ def execute_underload(config, state, host):
|
|||||||
:param state: A state dictionary.
|
:param state: A state dictionary.
|
||||||
:type state: dict(str: *)
|
:type state: dict(str: *)
|
||||||
|
|
||||||
:param state: A host name.
|
:param host: A host name.
|
||||||
:type state: str
|
:type host: str
|
||||||
|
|
||||||
:return: The updated state dictionary.
|
:return: The updated state dictionary.
|
||||||
:rtype: dict(str: *)
|
:rtype: dict(str: *)
|
||||||
@ -284,8 +284,8 @@ def execute_underload(config, state, host):
|
|||||||
for host, vms in hosts_to_vms.items():
|
for host, vms in hosts_to_vms.items():
|
||||||
host_cpu_mhz = sum(vms_last_cpu[x] for x in vms)
|
host_cpu_mhz = sum(vms_last_cpu[x] for x in vms)
|
||||||
if host_cpu_mhz > 0:
|
if host_cpu_mhz > 0:
|
||||||
host_cpu_usage[host] = host_cpu_mhz
|
hosts_cpu_usage[host] = host_cpu_mhz
|
||||||
host_ram_usage[host] = host_used_ram(state['nova'], host)
|
hosts_ram_usage[host] = host_used_ram(state['nova'], host)
|
||||||
else:
|
else:
|
||||||
# Exclude inactive hosts
|
# Exclude inactive hosts
|
||||||
del hosts_cpu_total[host]
|
del hosts_cpu_total[host]
|
||||||
@ -302,8 +302,8 @@ def execute_underload(config, state, host):
|
|||||||
vms_ram = vms_ram_limit(state['nova'], vms_to_migrate)
|
vms_ram = vms_ram_limit(state['nova'], vms_to_migrate)
|
||||||
|
|
||||||
time_step = int(config.get('data_collector_interval'))
|
time_step = int(config.get('data_collector_interval'))
|
||||||
migration_time = calculate_migration_time(
|
migration_time = common.calculate_migration_time(
|
||||||
vm_ram,
|
vms_ram,
|
||||||
float(config.get('network_migration_bandwidth')))
|
float(config.get('network_migration_bandwidth')))
|
||||||
|
|
||||||
if 'vm_placement' not in state:
|
if 'vm_placement' not in state:
|
||||||
@ -397,7 +397,7 @@ def vms_by_host(nova, host):
|
|||||||
:return: A list of VM UUIDs from the specified host.
|
:return: A list of VM UUIDs from the specified host.
|
||||||
:rtype: list(str)
|
:rtype: list(str)
|
||||||
"""
|
"""
|
||||||
return [vm.id for vm in nova.servers.list()
|
return [str(vm.id) for vm in nova.servers.list()
|
||||||
if vm_hostname(vm) == host]
|
if vm_hostname(vm) == host]
|
||||||
|
|
||||||
|
|
||||||
@ -470,8 +470,8 @@ def execute_overload(config, state, vm_uuids):
|
|||||||
for host, vms in hosts_to_vms.items():
|
for host, vms in hosts_to_vms.items():
|
||||||
host_cpu_mhz = sum(vms_last_cpu[x] for x in vms)
|
host_cpu_mhz = sum(vms_last_cpu[x] for x in vms)
|
||||||
if host_cpu_mhz > 0:
|
if host_cpu_mhz > 0:
|
||||||
host_cpu_usage[host] = host_cpu_mhz
|
hosts_cpu_usage[host] = host_cpu_mhz
|
||||||
host_ram_usage[host] = host_used_ram(state['nova'], host)
|
hosts_ram_usage[host] = host_used_ram(state['nova'], host)
|
||||||
else:
|
else:
|
||||||
inactive_hosts_cpu[host] = hosts_cpu_total[host]
|
inactive_hosts_cpu[host] = hosts_cpu_total[host]
|
||||||
inactive_hosts_ram[host] = hosts_ram_total[host]
|
inactive_hosts_ram[host] = hosts_ram_total[host]
|
||||||
@ -483,8 +483,8 @@ def execute_overload(config, state, vm_uuids):
|
|||||||
vms_ram = vms_ram_limit(state['nova'], vms_to_migrate)
|
vms_ram = vms_ram_limit(state['nova'], vms_to_migrate)
|
||||||
|
|
||||||
time_step = int(config.get('data_collector_interval'))
|
time_step = int(config.get('data_collector_interval'))
|
||||||
migration_time = calculate_migration_time(
|
migration_time = common.calculate_migration_time(
|
||||||
vm_ram,
|
vms_ram,
|
||||||
float(config.get('network_migration_bandwidth')))
|
float(config.get('network_migration_bandwidth')))
|
||||||
|
|
||||||
if 'vm_placement' not in state:
|
if 'vm_placement' not in state:
|
||||||
@ -503,7 +503,7 @@ def execute_overload(config, state, vm_uuids):
|
|||||||
placement, vm_placement_state = vm_placement(
|
placement, vm_placement_state = vm_placement(
|
||||||
hosts_cpu_usage, hosts_cpu_total,
|
hosts_cpu_usage, hosts_cpu_total,
|
||||||
hosts_ram_usage, hosts_ram_total,
|
hosts_ram_usage, hosts_ram_total,
|
||||||
host_cpu_usage, host_ram_usage,
|
inactive_hosts_cpu, inactive_hosts_ram,
|
||||||
vms_cpu, vms_ram,
|
vms_cpu, vms_ram,
|
||||||
vm_placement_state)
|
vm_placement_state)
|
||||||
state['vm_placement_state'] = vm_placement_state
|
state['vm_placement_state'] = vm_placement_state
|
||||||
|
@ -103,7 +103,6 @@ local manager performs the following steps:
|
|||||||
from contracts import contract
|
from contracts import contract
|
||||||
from neat.contracts_extra import *
|
from neat.contracts_extra import *
|
||||||
|
|
||||||
import numpy
|
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
import neat.common as common
|
import neat.common as common
|
||||||
@ -214,7 +213,7 @@ def execute(config, state):
|
|||||||
host_cpu_utilization = vm_mhz_to_percentage(
|
host_cpu_utilization = vm_mhz_to_percentage(
|
||||||
vm_cpu_mhz, physical_cpu_mhz_total)
|
vm_cpu_mhz, physical_cpu_mhz_total)
|
||||||
time_step = int(config['data_collector_interval'])
|
time_step = int(config['data_collector_interval'])
|
||||||
migration_time = calculate_migration_time(
|
migration_time = common.calculate_migration_time(
|
||||||
vm_ram, float(config['network_migration_bandwidth']))
|
vm_ram, float(config['network_migration_bandwidth']))
|
||||||
|
|
||||||
if 'underload_detection' not in state:
|
if 'underload_detection' not in state:
|
||||||
@ -373,19 +372,3 @@ def vm_mhz_to_percentage(vms, physical_cpu_mhz):
|
|||||||
"""
|
"""
|
||||||
data = itertools.izip_longest(*vms.values(), fillvalue=0)
|
data = itertools.izip_longest(*vms.values(), fillvalue=0)
|
||||||
return [float(sum(x)) / physical_cpu_mhz for x in data]
|
return [float(sum(x)) / physical_cpu_mhz for x in data]
|
||||||
|
|
||||||
|
|
||||||
@contract
|
|
||||||
def calculate_migration_time(vms, bandwidth):
|
|
||||||
""" Calculate the mean migration time from VM RAM usage data.
|
|
||||||
|
|
||||||
:param vms: A map of VM UUIDs to the corresponding maximum RAM in MB.
|
|
||||||
:type vms: dict(str: int)
|
|
||||||
|
|
||||||
:param bandwidth: The network bandwidth in MB/s.
|
|
||||||
:type bandwidth: float,>0
|
|
||||||
|
|
||||||
:return: The mean VM migration time in seconds.
|
|
||||||
:rtype: float
|
|
||||||
"""
|
|
||||||
return float(numpy.mean(vms.values()) / bandwidth)
|
|
||||||
|
@ -155,17 +155,3 @@ class LocalManager(TestCase):
|
|||||||
'c': [100, 100, 700]},
|
'c': [100, 100, 700]},
|
||||||
3000),
|
3000),
|
||||||
[0.1, 0.2, 0.4])
|
[0.1, 0.2, 0.4])
|
||||||
|
|
||||||
@qc(10)
|
|
||||||
def calculate_migration_time(
|
|
||||||
data=dict_(
|
|
||||||
keys=str_(of='abc123-', min_length=36, max_length=36),
|
|
||||||
values=int_(min=1, max=1000),
|
|
||||||
min_length=1, max_length=10
|
|
||||||
),
|
|
||||||
bandwidth=float_(min=1., max=100.)
|
|
||||||
):
|
|
||||||
ram = data.values()
|
|
||||||
migration_time = float(sum(ram)) / len(ram) / bandwidth
|
|
||||||
assert manager.calculate_migration_time(data, bandwidth) == \
|
|
||||||
migration_time
|
|
||||||
|
@ -145,3 +145,17 @@ class Common(TestCase):
|
|||||||
params = '{"param1": 0.56, "param2": "abc"}'
|
params = '{"param1": 0.56, "param2": "abc"}'
|
||||||
self.assertEqual(common.parse_parameters(params), {'param1': 0.56,
|
self.assertEqual(common.parse_parameters(params), {'param1': 0.56,
|
||||||
'param2': 'abc'})
|
'param2': 'abc'})
|
||||||
|
|
||||||
|
@qc(10)
|
||||||
|
def calculate_migration_time(
|
||||||
|
data=dict_(
|
||||||
|
keys=str_(of='abc123-', min_length=36, max_length=36),
|
||||||
|
values=int_(min=1, max=1000),
|
||||||
|
min_length=1, max_length=10
|
||||||
|
),
|
||||||
|
bandwidth=float_(min=1., max=100.)
|
||||||
|
):
|
||||||
|
ram = data.values()
|
||||||
|
migration_time = float(sum(ram)) / len(ram) / bandwidth
|
||||||
|
assert common.calculate_migration_time(data, bandwidth) == \
|
||||||
|
migration_time
|
||||||
|
Loading…
Reference in New Issue
Block a user