Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shreshthtuli committed Dec 1, 2021
1 parent 32aac4b commit 5871342
Show file tree
Hide file tree
Showing 24 changed files with 371 additions and 396 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__pycache__/
*.py[cod]
*$py.class
temp/

# C extensions
*.so
Expand Down
13 changes: 13 additions & 0 deletions decider/Compression_Only.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .Decider import *

class CompressionOnlyDecider(Decider):
def __init__(self):
super().__init__()

def decision(self, workflowlist):
results = []
for CreationID, interval, SLA, application in workflowlist:
choice = self.choices[2]
tasklist = self.createTasks(CreationID, interval, SLA, application, choice)
results += tasklist
return results
34 changes: 28 additions & 6 deletions decider/Decider.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
import math
from utils.MathUtils import *
from utils.MathConstants import *
import pandas as pd
from statistics import median
import numpy as np
from serverless.function.Task import *

class Decider():
def __init__(self):
self.env = None
self.choices = ['layer', 'semantic', 'compression']
self.dataset = list(filter(lambda k: '.md' not in k, os.listdir(SAMPLE_PATH)))
self.dataset = [os.path.join(SAMPLE_PATH, i) for i in self.dataset]

def setEnvironment(self, env):
self.env = env

def decision(self, workflowlist):
pass

def getLayerInputs(self, cid, i):
paths = []
for d in DSET:
d2 = DSET[0].split('.')[0]
paths.append(f'./temp/{d2}_L_{cid}_{i}.jpg')
return paths

def createTasks(cid, interval, SLA, application, choice):
tasklist = []
if choice == 'semantic':
tasklist.append(Task(cid, interval, SLA, application, choice, self.env, 0, [], [self.dataset[0]]))
tasklist.append(Task(cid, interval, SLA, application, choice, self.env, 1, [], [self.dataset[1]]))
tasklist.append(Task(cid, interval, SLA, application, choice, self.env, 2, [], [self.dataset[2]]))
tasklist.append(Task(cid, interval, SLA, application, choice, self.env, 3, [], [self.dataset[3]]))
elif choice == 'layer':
tasklist.append(Task(cid, interval, SLA, application, choice, self.env, 0, [], self.dataset))
tasklist.append(Task(cid, interval, SLA, application, choice, self.env, 1, [0], self.getLayerInputs(cid, 0)))
tasklist.append(Task(cid, interval, SLA, application, choice, self.env, 2, [0, 1], self.getLayerInputs(cid, 1)))
tasklist.append(Task(cid, interval, SLA, application, choice, self.env, 3, [0, 1, 2], self.getLayerInputs(cid, 2)))
elif choice == 'compression':
tasklist.append(Task(cid, interval, SLA, application, choice, self.env, 0, [], self.dataset*2))
return tasklist



7 changes: 6 additions & 1 deletion decider/Layer_Only.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ def __init__(self):
super().__init__()

def decision(self, workflowlist):
return [self.choices[0]] * len(workflowlist)
results = []
for CreationID, interval, SLA, application in workflowlist:
choice = self.choices[0]
tasklist = self.createTasks(CreationID, interval, SLA, application, choice)
results += tasklist
return results
9 changes: 7 additions & 2 deletions decider/Random.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from .Decider import *
import random
import numpy as np

class RandomDecider(Decider):
def __init__(self):
super().__init__()

def decision(self, workflowlist):
return random.choices(self.choices, k = len(workflowlist))
results = []
for CreationID, interval, SLA, application in workflowlist:
choice = np.random.choice(self.choices)
tasklist = self.createTasks(CreationID, interval, SLA, application, choice)
results += tasklist
return results
7 changes: 6 additions & 1 deletion decider/Semantic_Only.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ def __init__(self):
super().__init__()

def decision(self, workflowlist):
return [self.choices[1]] * len(workflowlist)
results = []
for CreationID, interval, SLA, application in workflowlist:
choice = self.choices[1]
tasklist = self.createTasks(CreationID, interval, SLA, application, choice)
results += tasklist
return results
78 changes: 30 additions & 48 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,10 @@
from decider.Random import RandomDecider
from decider.Layer_Only import LayerOnlyDecider
from decider.Semantic_Only import SemanticOnlyDecider
from decider.Compression_Only import CompressionOnlyDecider

# Scheduler imports
from scheduler.IQR_MMT_Random import IQRMMTRScheduler
from scheduler.MAD_MMT_Random import MADMMTRScheduler
from scheduler.MAD_MC_Random import MADMCRScheduler
from scheduler.LR_MMT_Random import LRMMTRScheduler
from scheduler.Random_Random_FirstFit import RFScheduler
from scheduler.Random_Random_LeastFull import RLScheduler
from scheduler.RLR_MMT_Random import RLRMMTRScheduler
from scheduler.Threshold_MC_Random import TMCRScheduler
from scheduler.Random_Random_Random import RandomScheduler
from scheduler.Random import RandomScheduler

# Auxiliary imports
from stats.Stats import *
Expand All @@ -55,7 +48,7 @@
CONTAINERS = HOSTS
TOTAL_POWER = 1000
ROUTER_BW = 10000
INTERVAL_TIME = 300 # seconds
INTERVAL_TIME = 5 # seconds
NEW_CONTAINERS = 0 if HOSTS == 10 else 5
DB_NAME = ''
DB_HOST = ''
Expand All @@ -71,60 +64,49 @@ def initalizeEnvironment(environment, mode):
''' Can be AzureDatacenter '''
datacenter = eval(environment+'Datacenter(mode)')
hostlist = datacenter.generateHosts()
exit()

# Initialize workload
''' Can be SWSD, BWGD2, Azure2017Workload, Azure2019Workload // DFW, AIoTW '''
if environment != '':
workload = DFW(NEW_CONTAINERS, 1.5, db)
else:
workload = BWGD2(NEW_CONTAINERS, 1.5)

''' Can be AIBench '''
workload = AIBenchWorkload(NEW_CONTAINERS, 1.5)

# Initialize decider
''' Can be Random '''
decider = RandomDecider()

# Initialize scheduler
''' Can be LRMMTR, RF, RL, RM, Random, RLRMMTR, TMCR, TMMR, TMMTR, GA, GOBI (arg = 'energy_latency_'+str(HOSTS)) '''
scheduler = GOBIScheduler('energy_latency_'+str(HOSTS)) # GOBIScheduler('energy_latency_'+str(HOSTS))
''' Can be Random '''
scheduler = RandomScheduler()

# Initialize Environment
if environment != '':
env = Framework(scheduler, CONTAINERS, INTERVAL_TIME, hostlist, db, environment, logger)
else:
env = Simulator(TOTAL_POWER, ROUTER_BW, scheduler, CONTAINERS, INTERVAL_TIME, hostlist)
env = Serverless(scheduler, decider, INTERVAL_TIME, hostlist, environment)

# Execute first step
newcontainerinfos = workload.generateNewContainers(env.interval) # New containers info
deployed = env.addContainersInit(newcontainerinfos) # Deploy new containers and get container IDs
start = time()
decision = scheduler.placement(deployed) # Decide placement using container ids
schedulingTime = time() - start
migrations = env.allocateInit(decision) # Schedule containers
workload.updateDeployedContainers(env.getCreationIDs(migrations, deployed)) # Update workload allocated using creation IDs
print("Deployed containers' creation IDs:", env.getCreationIDs(migrations, deployed))
workloadlist = workload.generateNewContainers(env.interval) # New containers info
newtasklist = decider.decision(workloadlist)
decision, schedulingTime = scheduler.placement(newtasklist) # Decide placement using task objects
numdep = env.allocateInit(newtasklist, decision) # Schedule functions
print("New Tasks Size:", len(newtasklist))
print("Waiting List Size:", len(env.waitinglist))
print("Containers in host:", env.getContainersInHosts())
print("Schedule:", env.getActiveContainerList())
printDecisionAndMigrations(decision, migrations)
print("Deployed:", numdep, "of", len(env.waitinglist + newtasklist))
print("Decision:", decision)

# Initialize stats
stats = Stats(env, workload, datacenter, scheduler)
stats.saveStats(deployed, migrations, [], deployed, decision, schedulingTime)
return datacenter, workload, scheduler, env, stats

def stepSimulation(workload, scheduler, env, stats):
newcontainerinfos = workload.generateNewContainers(env.interval) # New containers info
if opts.env != '': print(newcontainerinfos)
deployed, destroyed = env.addContainers(newcontainerinfos) # Deploy new containers and get container IDs
start = time()
selected = scheduler.selection() # Select container IDs for migration
decision = scheduler.filter_placement(scheduler.placement(selected+deployed)) # Decide placement for selected container ids
schedulingTime = time() - start
migrations = env.simulationStep(decision) # Schedule containers
workload.updateDeployedContainers(env.getCreationIDs(migrations, deployed)) # Update workload deployed using creation IDs
print("Deployed containers' creation IDs:", env.getCreationIDs(migrations, deployed))
print("Deployed:", len(env.getCreationIDs(migrations, deployed)), "of", len(newcontainerinfos), [i[0] for i in newcontainerinfos])
print("Destroyed:", len(destroyed), "of", env.getNumActiveContainers())
workloadlist = workload.generateNewContainers(env.interval) # New containers info
newtasklist = decider.decision(workloadlist)
decision, schedulingTime = scheduler.placement(env.waitinglist + newtasklist) # Decide placement using task objects
numdep = env.simulationStep(newtasklist, decision) # Schedule containers
print("New Tasks Size:", len(newtasklist))
print("Waiting List Size:", len(env.waitinglist))
print("Containers in host:", env.getContainersInHosts())
print("Num active containers:", env.getNumActiveContainers())
print("Host allocation:", [(c.getHostID() if c else -1)for c in env.containerlist])
printDecisionAndMigrations(decision, migrations)
print("Deployed:", numdep, "of", len(env.waitinglist + newtasklist))
print("Destroyed:", numdes, "of", len(env.activetasklist))
print("Decision:", decision)

stats.saveStats(deployed, migrations, destroyed, selected, decision, schedulingTime)

Expand Down
21 changes: 0 additions & 21 deletions scheduler/IQR_MMT_Random.py

This file was deleted.

23 changes: 0 additions & 23 deletions scheduler/LR_MMT_Random.py

This file was deleted.

29 changes: 0 additions & 29 deletions scheduler/MAD_MC_Random.py

This file was deleted.

24 changes: 0 additions & 24 deletions scheduler/MAD_MMT_Random.py

This file was deleted.

23 changes: 0 additions & 23 deletions scheduler/RLR_MMT_Random.py

This file was deleted.

8 changes: 3 additions & 5 deletions scheduler/Random_Random_Random.py → scheduler/Random.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ class RandomScheduler(Scheduler):
def __init__(self):
super().__init__()

def selection(self):
return self.RandomContainerSelection()

def placement(self, containerIDs):
return self.RandomPlacement(containerIDs)
def placement(self, tasks):
start = time()
return self.RandomPlacement(tasks), time() - start
14 changes: 0 additions & 14 deletions scheduler/Random_Random_FirstFit.py

This file was deleted.

Loading

0 comments on commit 5871342

Please sign in to comment.