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

Added clientmanager, clients distributed round robin

parent da4dcace
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -126,6 +126,16 @@ class DatabaseManager(): ...@@ -126,6 +126,16 @@ class DatabaseManager():
req = urllib.request.Request(self.influx_url + '/query ', query) req = urllib.request.Request(self.influx_url + '/query ', query)
urllib.request.urlopen(req) urllib.request.urlopen(req)
class ClientManager():
def __init__(self, servers):
self.servers = servers
def generate_new_clients(self, amount):
assigned_count = 0
while(assigned_count < amount):
for server in self.servers:
if(assigned_count < amount):
server.assign_client(DemoClient())
assigned_count += 1
# DemoServer is the class that simulates the behaviour of the MPEG-DASH server # DemoServer is the class that simulates the behaviour of the MPEG-DASH server
class DemoServer(object): class DemoServer(object):
...@@ -137,18 +147,14 @@ class DemoServer(object): ...@@ -137,18 +147,14 @@ class DemoServer(object):
self.influxURL = db_url # InfluxDB connection URL self.influxURL = db_url # InfluxDB connection URL
self.currentTime = int(round(time.time() * 1000)) # The current time self.currentTime = int(round(time.time() * 1000)) # The current time
self._configure(server_id, server_location) self._configure(server_id, server_location)
self.clients = []
def shutdown(self): def shutdown(self):
print("Shutting down") print("Shutting down")
self.configure_VM('stopping') self.configure_VM('stopping')
def generate_clients(self): def assign_client(self, new_client):
self.clients = [] self.clients.append(new_client)
for i in range(self.clientCount):
self.clients.append(DemoClient())
print('Number of clients: ' + str(len(self.clients)))
def reportStatus(self):
print('Number of clients: ' + str(len(self.clients))) print('Number of clients: ' + str(len(self.clients)))
def configure_server(self, server_id, server_location): def configure_server(self, server_id, server_location):
...@@ -263,7 +269,7 @@ class DemoServer(object): ...@@ -263,7 +269,7 @@ class DemoServer(object):
self.configure_VM('running') self.configure_VM('running')
time.sleep(1) time.sleep(1)
self.configure_server(server_id, server_location) self.configure_server(server_id, server_location)
self.generate_clients() #self.generate_clients()
def _cpuUsage(self, clientCount): def _cpuUsage(self, clientCount):
cpuUsage = randint(0, 10) cpuUsage = randint(0, 10)
...@@ -372,16 +378,24 @@ time.sleep(2) ...@@ -372,16 +378,24 @@ time.sleep(2)
database_manager.database_up() database_manager.database_up()
time.sleep(2) time.sleep(2)
# configure servers # configure servers
demoServer = DemoServer(clients, iterations, 'http://localhost:8186', 'testDB', "Server1", "Southampton") demoServer_southampton = DemoServer(clients, iterations, 'http://localhost:8186', 'testDB', "Server1", "Southampton")
demoServer_bristol = DemoServer(clients, iterations, 'http://localhost:8186', 'testDB', "Server2", "Bristol")
server_list = [demoServer_southampton, demoServer_bristol]
client_manager = ClientManager(server_list)
client_manager.generate_new_clients(20)
# Start simulation # Start simulation
print("Starting simulation") print("Starting simulation")
while True: while True:
itCount = demoServer.iterateService() for server in server_list:
itCount = server.iterateService()
pcDone = round((itCount / iterations) * 100) pcDone = round((itCount / iterations) * 100)
print("Simulation remaining (%): " + str(pcDone) + " \r", end='') print("Simulation remaining (%): " + str(pcDone) + " \r", end='')
if itCount == 0: if itCount == 0:
break break
demoServer.shutdown()
for server in server_list:
server.shutdown()
print("\nFinished") print("\nFinished")
This diff is collapsed.
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