def optimize_locally(self, info, doing): state = create_state(doing, info, self.cache) processes = list() for n in doing: info["who"] = Device(info["user_cpu"][n], n, info["H"][n], transmission_power=info["P_max"][n], epsilon=info["stop_point"]) info["who"].inital_DAG(n, info["tasks"][n], info["D_n"][n], info["D_n"][n]) info["who"].local_only_execution() info["who"].config = info["configs"][n] x = Process(target=worker, args=(copy.deepcopy(info), state)) x.start() processes.append(x) for process in processes: process.join()
def optimize(self): global validation, finish message = "m: greeting from edge server, doing list " + str(self.doing) self.s.send(message.encode('ascii')) start = time.time() while True: data = self.recv_msg() if str(data.decode('ascii')) == "start_opt": print("waiting data...") self.done = False elif str(data.decode('ascii')) == "waiting": print("no request...") elif str(data.decode('ascii')) == "close": print("done, close connection") self.s.close() return else: info = json.loads(str(data.decode('ascii'))) print("start to optimizing...", self.doing, info["number_of_user"]) if info["clean_cache"] is True and info["current_t"] == 0: self.cache = [] print( "clean cache........................................................." ) state = create_state(self.doing, info, self.cache) processes = list() for n in self.doing: info["who"] = Device(info["user_cpu"][n], n, info["H"][n], transmission_power=info["P_max"][n], epsilon=info["stop_point"]) info["who"].inital_DAG(n, info["tasks"][n], info["D_n"][n], info["D_n"][n]) info["who"].local_only_execution() info["who"].config = info["configs"][n] # x = threading.Thread(target=self.worker, args=(copy.deepcopy(info),)) x = Process(target=worker, args=(copy.deepcopy(info), state)) x.start() processes.append(x) for process in processes: process.join() while not check_worker(self.doing, state): pass print(info["current_t"], "request finished in >>>>>>>>>>>>>>>>", time.time() - start) self.cache = copy.copy(list(state['cache'])) for n in self.doing: if state['request'][n] is not None: if len(state['request'][n]) == 0: state['request'][n] = None print("update request for user", n, "= None") else: if state['request'][n]["validation"] is not None: print( "update request for user", n, "=", state['request'][n]["validation"] ["config"]) else: print("update request for user", n, "= local") else: print("update request for user", n, "= None") self.s.send( json.dumps({ "req": list(state['request']), "doing": self.doing }).encode("utf-8")) self.done = True