Skip to content
Snippets Groups Projects
Commit 50493d12 authored by Rowan Powell's avatar Rowan Powell
Browse files

cpu usage function scales on requests

parent 391e83c6
No related branches found
No related tags found
No related merge requests found
......@@ -138,7 +138,7 @@ def _configure_service_function(state, max_connected_clients):
return result
# Simulating telegraf reporting
def generate_CPU_report(time):
def generate_CPU_report(requests, time):
# Measurement
result = 'cpu'
# meta tag
......@@ -146,8 +146,8 @@ def generate_CPU_report(time):
result += ',cpu="cpu-total"'
result += ' '
# field
steal = randint(0, 50)
system = randint(0, 100-steal)
system = randint(0, min(100, requests*5))
steal = randint(0, 100-system)
idle = 100-(system+steal)
result += 'usage_steal='+str(steal/100)
result += ',usage_system='+str(system/100)
......@@ -174,6 +174,64 @@ def generate_mem_report(total_mem, time):
print(result)
return result
def generate_compute_node_config(slice_id, location, node_id, cpus, mem, storage, time):
# Measurement
result = 'compute_node_config'
# CommonContext Tag
result += ',slide_id='+quote_wrap(slice_id)
# Tag
result += ',location='+quote_wrap(location)
result += ',comp_node_id='+quote_wrap(node_id)
result += ' '
# field
result += 'cpus='+str(cpus)
result += ',memory='+str(mem)
result += ',storage='+str(storage)
result += ' '
# Time
result += str(_getNSTime(time))
print(result)
return result
def generate_network_resource_config(slice_id, network_id, bandwidth, time):
# Measurement
result = 'network_resource_config'
# Meta Tag
result += ',slice_id='+quote_wrap(slice_id)
# Tag
result += 'network_id='+quote_wrap(network_id)
result += ' '
# field
result += 'bandwidth='+str(bandwidth)
result += ' '
# Time
result += str(_getNSTime(time))
print(result)
return result
def generate_network_interface_config(slice_id, comp_node_id, port_id, rx_constraint, tx_constraint, time):
# Measurement
result = 'network_interface_config'
# Meta Tag
result += ',slice_id'+quote_wrap(slice_id)
# Tags
result += ',comp_node_id='+quote_wrap(comp_node_id)
result += ',port_id='+quote_wrap(port_id)
result += ' '
# field
result += 'rx_constraint='+str(rx_constraint)
result += ',tx_constraint='+str(tx_constraint)
result += ' '
# Time
result += str(_getNSTime(time))
print(result)
return result
# Influx needs strings to be quoted, this provides a utility interface to do this
def quote_wrap(str):
return "\"" + str + "\""
......
......@@ -162,10 +162,9 @@ class Node():
# DemoServer is the class that simulates the behaviour of the MPEG-DASH server
class DemoServer(object):
def __init__(self, cc, si, db_url, db_name, server_id, server_location):
def __init__(self, si, db_url, db_name, server_id, server_location):
self.influxDB = db_name # InfluxDB database name
self.id = uuid.uuid4() # MPEG-DASH server ID
self.clientCount = cc # Number of clients to simulate
self.simIterations = si # Number of iterations to make for this simulation
self.influxURL = db_url # InfluxDB connection URL
self.currentTime = int(round(time.time() * 1000)) # The current time
......@@ -290,11 +289,11 @@ class DemoServer(object):
print("Configuring")
self.configure_VM('starting')
self.configure_VM('running')
time.sleep(0.1)
#time.sleep(0.1)
self.configure_server(server_id, server_location)
self._sendInfluxData(lp._configure_port('01', 'running', '1GB/s', self.currentTime))
self._sendInfluxData(lp._configure_service_function('starting', 100))
time.sleep(0.1)
#time.sleep(0.1)
self._sendInfluxData(lp._configure_service_function('running', 100))
def _cpuUsage(self, clientCount):
......@@ -393,10 +392,11 @@ class DemoServer(object):
# Entry point
# -----------------------------------------------------------------------------------------------
print("Preparing simulation")
clients = 10
# Iterations is time in seconds for each server to simulate
iterations = 3000
# port 8086: Direct to DB specified
# port 8186: To telegraf, telegraf specifies DB
start_time = time.localtime()
database_manager = DatabaseManager('http://localhost:8186', 'testDB')
# Set up InfluxDB (need to wait a little while)
database_manager.database_teardown()
......@@ -404,8 +404,8 @@ time.sleep(2)
database_manager.database_up()
time.sleep(2)
# configure servers
demoServer_southampton = DemoServer(clients, iterations, 'http://localhost:8186', 'testDB', "Server1", "Southampton")
demoServer_bristol = DemoServer(clients, iterations, 'http://localhost:8186', 'testDB', "Server2", "Bristol")
demoServer_southampton = DemoServer(iterations, 'http://localhost:8186', 'testDB', "Server1", "Southampton")
demoServer_bristol = DemoServer(iterations, 'http://localhost:8186', 'testDB', "Server2", "Bristol")
telegraf_node = Node('http://localhost:8186', 'testDB', True)
server_list = [demoServer_southampton, demoServer_bristol]
client_manager = ClientManager(server_list)
......@@ -427,3 +427,6 @@ while True:
for server in server_list:
server.shutdown()
print("\nFinished")
end_time = time.localtime()
print("Started at {0} ended at {1}, total run time {2}".format(start_time,end_time,(end_time-start_time)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment