Skip to content
Snippets Groups Projects
Commit a512bb08 authored by Nikolay Stanchev's avatar Nikolay Stanchev
Browse files

[ Issue #61 ] - Updated endpoints configuration states

parent 8a46aba7
Branches
Tags
No related merge requests found
......@@ -87,7 +87,7 @@ def generate_endpoint_config(cpu, mem, storage, time, **kwargs):
# generate and validate the state values
fields = {"cpus": cpu, "memory": mem, "storage": storage} # NOTE: Do we need these fields ?
for state in ("placing", "booting", "connecting"):
for state in ("unplaced", "placing", "placed", "booting", "booted", "connecting", "connected"):
fields[state] = validate(state)
fields[("avg_{0}".format(state))] = validate("avg_{0}".format(state))
......
......@@ -75,7 +75,7 @@ class Sim(object):
# Simulate configuration of the ipendpoints
# endpoint state->mu, sigma, secs normal distribution
config_delay_dist = {"placing": [10, 0.68], "booting": [10, 0.68], "connecting": [10, 0.68]}
config_delay_dist = {"placing": [10, 0.68], "booting": [10, 0.68], "connecting": [10, 0.68], "unplaced": [10, 0.68]}
# Simulation configuration of the media component (MC) state changes
# "MC state", [average (sec), stddev]
......@@ -89,7 +89,8 @@ class Sim(object):
agent_url = urllib.parse.urlparse(ip_endpoint["agent_url"])
agent_db_client = InfluxDBClient(host=agent_url.hostname, port=agent_url.port, database=self.influx_db_name, timeout=10)
delay_time = self._changeVMState(agent_db_client, sim_time, ip_endpoint, config_delay_dist['placing'][0],
config_delay_dist['placing'][0] * config_delay_dist['placing'][1], 'placing')
config_delay_dist['placing'][0] * config_delay_dist['placing'][1], 0.7,
'placing', 'placed')
max_delay = max(delay_time, max_delay)
sim_time += max_delay
......@@ -99,7 +100,8 @@ class Sim(object):
agent_url = urllib.parse.urlparse(ip_endpoint["agent_url"])
agent_db_client = InfluxDBClient(host=agent_url.hostname, port=agent_url.port, database=self.influx_db_name, timeout=10)
delay_time = self._changeVMState(agent_db_client, sim_time, ip_endpoint, config_delay_dist['booting'][0],
config_delay_dist['booting'][0] * config_delay_dist['booting'][1], 'booting')
config_delay_dist['booting'][0] * config_delay_dist['booting'][1], 0.7,
'booting', 'booted')
max_delay = max(delay_time, max_delay)
sim_time += max_delay
......@@ -122,7 +124,8 @@ class Sim(object):
agent_url = urllib.parse.urlparse(ip_endpoint["agent_url"])
agent_db_client = InfluxDBClient(host=agent_url.hostname, port=agent_url.port, database=self.influx_db_name, timeout=10)
delay_time = self._changeVMState(agent_db_client, sim_time, ip_endpoint, config_delay_dist['connecting'][0],
config_delay_dist['connecting'][0] * config_delay_dist['connecting'][1], 'connecting')
config_delay_dist['connecting'][0] * config_delay_dist['connecting'][1], 0.7,
'connecting', 'connected')
max_delay = max(delay_time, max_delay)
sim_time += max_delay
......@@ -194,11 +197,23 @@ class Sim(object):
state_stats = {}
state_stats['running'] = float(TICK_TIME)
state_stats['avg_running'] = float(TICK_TIME)
agent_db_client.write_points(lp.generate_mc_service_config("mpegdash_service_config",state_stats,sim_time))
agent_db_client.write_points(lp.generate_mc_service_config("mpegdash_service_config", state_stats, sim_time))
sim_time += TICK_TIME
# Simulate tear-down of media components
# Simulate tear-down of media components and endpoints
# remove endpoints
max_delay = 0
for ip_endpoint in ip_endpoints:
agent_url = urllib.parse.urlparse(ip_endpoint["agent_url"])
agent_db_client = InfluxDBClient(host=agent_url.hostname, port=agent_url.port, database=self.influx_db_name, timeout=10)
delay_time = self._changeVMState(agent_db_client, sim_time, ip_endpoint, config_delay_dist['placing'][0],
config_delay_dist['unplaced'][0] * config_delay_dist['unplaced'][1], 0.25,
'placed', 'unplaced') # NOTE: Is 'placed' a transition state ?
max_delay = max(delay_time, max_delay)
sim_time += max_delay
# move mpegdash_service endpoints state through from 'running' to 'stopped'
max_delay = 0
for ip_endpoint in ip_endpoints:
......@@ -241,7 +256,7 @@ class Sim(object):
return response_delay
@staticmethod
def _changeVMState(agent_db_client, sim_time, ip_endpoint, mu, sigma, transition_state):
def _changeVMState(agent_db_client, sim_time, ip_endpoint, mu, sigma, trans_ratio, transition_state, next_state):
"""
Send influx data to change VM state. Declared as static method since it doesn't need access to any instance variables.
......@@ -249,16 +264,26 @@ class Sim(object):
:param ip_endpoint: endpoint configuration (cpu, memory, storage, etc.)
:param mu: mean value
:param sigma: standard deviation
:param trans_ratio: the part of the total delay time for transition state
:param transition_state: name of transition state
:param next_state: name of next state
:return: the delay time
"""
# assert transition time is at least 0
delay_time = max(random.normalvariate(mu, sigma), 0.0)
# assert total delay time is at least 0
total_delay_time = max(random.normalvariate(mu, sigma), 0.0)
# part of the total delay time is the transition state period
transition_time = trans_ratio*total_delay_time
# the rest of the delay is the next state period
next_state_time = total_delay_time - transition_time
# transition state and state period are passed to the generate report function as keyword arguments
agent_db_client.write_points(lp.generate_endpoint_config(ip_endpoint['cpu'], ip_endpoint['mem'], ip_endpoint['storage'], sim_time,
**{transition_state: delay_time, 'avg_{0}'.format(transition_state): delay_time}))
**{transition_state: transition_time, 'avg_{0}'.format(transition_state): transition_time,
next_state: next_state_time, 'avg_{0}'.format(next_state): next_state_time}))
return delay_time
return total_delay_time
@staticmethod
def _changeMCState(agent_db_client, sim_time, mc_measurement, mu, sigma, trans_ratio, transition_state, next_state):
......
......@@ -19,10 +19,11 @@ class TestSimulation(object):
{"time": "1970-01-01T00:00:00Z", "count_RX_BYTES_PORT_M": 7200, "count_TX_BYTES_PORT_M": 7200}),
('SELECT count(*) FROM "CLMCMetrics"."autogen"."endpoint_config" WHERE ipendpoint=\'adaptive_streaming_I1_apache1\'',
{"time": "1970-01-01T00:00:00Z", "count_placing": 3, "count_avg_placing": 3, "count_booting": 3, "count_avg_booting": 3, "count_connecting": 3, "count_avg_connecting": 3, "count_cpus": 3, "count_memory": 3, "count_storage": 3}),
{"time": "1970-01-01T00:00:00Z", "count_unplaced": 4, "count_avg_unplaced": 4, "count_placing": 4, "count_avg_placing": 4, "count_placed": 4, "count_avg_placed": 4, "count_booting": 4, "count_avg_booting": 4, "count_booted": 4,
"count_avg_booted": 4, "count_connecting": 4, "count_avg_connecting": 4, "count_connected": 4, "count_avg_connected": 4, "count_cpus": 4, "count_memory": 4, "count_storage": 4}),
('SELECT count(*) FROM "CLMCMetrics"."autogen"."endpoint_config" WHERE ipendpoint=\'adaptive_streaming_I1_apache2\'',
{"time": "1970-01-01T00:00:00Z", "count_placing": 3, "count_avg_placing": 3, "count_booting": 3, "count_avg_booting": 3, "count_connecting": 3, "count_avg_connecting": 3,
"count_cpus": 3, "count_memory": 3, "count_storage": 3}),
{"time": "1970-01-01T00:00:00Z", "count_unplaced": 4, "count_avg_unplaced": 4, "count_placing": 4, "count_avg_placing": 4, "count_placed": 4, "count_avg_placed": 4, "count_booting": 4, "count_avg_booting": 4, "count_booted": 4,
"count_avg_booted": 4, "count_connecting": 4, "count_avg_connecting": 4, "count_connected": 4, "count_avg_connected": 4, "count_cpus": 4, "count_memory": 4, "count_storage": 4}),
('SELECT count(*) FROM "CLMCMetrics"."autogen"."mpegdash_service_config" WHERE ipendpoint=\'adaptive_streaming_I1_apache1\'',
{"time": "1970-01-01T00:00:00Z", "count_avg_running": 3602, "count_avg_starting": 3602, "count_avg_stopped": 3602, "count_avg_stopping": 3602, "count_running": 3602, "count_starting": 3602, "count_stopped": 3602, "count_stopping": 3602}),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment