Skip to content

Commit

Permalink
Added collaborative filtering in RecSim
Browse files Browse the repository at this point in the history
  • Loading branch information
shreshthtuli committed Dec 12, 2021
1 parent 84dabc7 commit 2264754
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
20 changes: 19 additions & 1 deletion decider/RecSim_Decider.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
from .HASCO_Decider import *
from provisioner.src.utils import *
from .src.utils import *
from .src.opt import *

class RecSimDecider(HASCODecider):
def __init__(self):
super().__init__()
self.model_name = 'RecSim'
self.rt_dict, self.sla_dict = get_dicts()
self.a_dict = get_accuracies()
self.xi = 1 # weight of accuracy w.r.t SLA violation

def getSimScores(self, application, sla):
sla = self.sla_dict[application]
rt_s = [np.random.normal(loc = self.rt_dict[application][choice][0], scale = self.rt_dict[application][choice][1]) for choice in self.choices]
sla_s = [rt <= sla for rt in rt_s]
a_s = [self.a_dict[application][choice] for choice in self.choices]
choice_scores = [sla_s[i] + self.xi * a_s[i] for i in range(len(self.choices))]
return choice_scores

def decision(self, workflowlist):
if not self.model_loaded: self.load_model()
cpu = self.host_util
results = []
for i, (CreationID, interval, SLA, application) in enumerate(workflowlist):
choice = self.choices[np.argmax([self.testall(cpu, app=application, dec=i) for i in self.choices])]
# generate BNN based recommendation scores
scores = np.array([self.testall(cpu, app=application, dec=i) for i in self.choices])
# generate simulator based recommendation scores
sim_scores = self.getSimScores(application, SLA)
# run collaborative filtering
scores += sim_scores
choice = self.choices[np.argmax(scores)]
tasklist = self.createTasks(CreationID, interval, SLA, application, choice)
results += tasklist
return results
29 changes: 27 additions & 2 deletions provisioner/RecSim_Provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,37 @@ class RecSimProvisioner(HASCOProvisioner):
def __init__(self):
super().__init__()
self.model_name = 'RecSim'
self.allpowermodels = ['PMB2s', 'PMB4ms', 'PMB8ms']
costs = np.array([0.08, 0.17, 0.33]) / 12
ipscaps = [2019, 4029, 16111]
self.costdict = dict(zip(self.allpowermodels, costs))
self.ipscaps = dict(zip(self.allpowermodels, ipscaps))
self.gamma = 0.5 # weight of cost w.r.t utilization ratio

def updateMetrics(self):
self.costs = [self.costdict[host.powermodel.__class__.__name__] if host.enable else 0 for host in self.env.hostlist]
self.util = [(host.ips / host.ipsCap) if host.enable else 0 for host in self.env.hostlist]

def getReward(self):
return (np.sum(self.util) - self.gamma * np.sum(self.costs)) * (0 if np.sum(self.util) == 0 else 1)

def getSimScores(self, host):
host.enable = True; self.updateMetrics()
rEnable = self.getReward()
host.enable = False; self.updateMetrics()
rDisable = self.getReward()
return np.array([rDisable, rEnable])

def provision(self):
if not self.model_loaded: self.load_model()
self.host_util = torch.FloatTensor([h.getCPU() for h in self.env.hostlist]) / 100
cpu = self.host_util
for i in range(len(self.env.hostlist)):
scores = [self.testall(cpu, prov=i) for i in [0, 1]]
for i, host in enumerate(self.env.hostlist):
# generate BNN based recommendation scores
scores = np.array([self.testall(cpu, prov=i) for i in [0, 1]])
# generate simulator based recommendation scores
sim_scores = self.getSimScores(host)
# run collaborative filtering
scores += sim_scores
todo = np.argmax(scores)
self.env.hostlist[i].enable = True if todo == 1 else False
35 changes: 32 additions & 3 deletions scheduler/RecSim_Scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,42 @@ class RecSimScheduler(HASCOScheduler):
def __init__(self):
super().__init__()
self.model_name = 'RecSim'

self.alpha, self.beta, self.delta = 0.3, 0.3, 0.3
self.rt_dict, self.sla_dict = get_dicts()
self.estimateTaskIPS = get_estimate_ips();

def getSimScores(self, task):
sim_scores = []; self.emax = self.env.provisioner.emax
for hostID in range(len(self.env.hostlist)):
ehosts = [];
application, choice = task.application, task.choice
for host in self.env.hostlist:
if host.id == hostID:
ehosts.append(host.getPowerFromIPS(host.ips + self.estimateTaskIPS))
else:
ehosts.append(host.getPower())
e = np.sum(ehosts)
e = e / self.emax # normalize
sla = self.sla_dict[application]
rt = np.random.normal(loc = self.rt_dict[application][choice][0], scale = self.rt_dict[application][choice][1])
if self.env.hostlist[hostID].getIPSAvailable() > self.estimateTaskIPS:
rt /= 2
sla_v = (rt <= sla) + 0
sim_scores.append(1 - (self.alpha * e + self.delta * sla_v))
return sim_scores

def placement(self, tasks):
if not self.model_loaded: self.load_model()
start = time()
cpu = self.host_util
decisions = []
for task in tasks:
dec = np.argmax([self.testall(cpu, prov=1, app=task.application, dec=task.choice, sched=i) for i in list(range(len(self.env.hostlist)))])
decisions.append(dec)
# generate BNN based recommendation scores
scores = np.array([self.testall(cpu, prov=1, app=task.application, dec=task.choice, sched=i) for i in list(range(len(self.env.hostlist)))])
# generate simulator based recommendation scores
sim_scores = self.getSimScores(task)
# run collaborative filtering
scores += sim_scores
hostID = np.argmax(scores)
decisions.append(hostID)
return decisions, time() - start

0 comments on commit 2264754

Please sign in to comment.