def step(self, knob): """step """ restart_time = utils.time_start() flag = self._apply_knobs(knob) restart_time = utils.time_end(restart_time) if not flag: return -100.0, np.array([0] * self.num_metric), True, self.score - 100, [ 0, 0, 0 ], restart_time s = self._get_state(knob, method=self.method) if s is None: return -100.0, np.array([0] * self.num_metric), True, self.score - 100, [ 0, 0, 0 ], restart_time external_metrics, internal_metrics = s reward = self._get_reward(external_metrics) self.last_external_metrics = external_metrics next_state = internal_metrics terminate = self._terminate() knobs.save_knobs( knob=knob, metrics=external_metrics, knob_file='%sAutoTuner/tuner/save_knobs/knob_metric.txt' % PROJECT_DIR) return reward, next_state, terminate, self.score, external_metrics, restart_time
def step(self, knob): """step """ restart_time = utils.time_start() flag = self._apply_knobs(knob) restart_time = utils.time_end(restart_time) # ? if not flag: return -10000000.0, np.array([0] * self.num_metric), True, self.score - 10000000, [0, 0, 0], restart_time s = self._get_state(knob, method=self.method) # crash if s is None: return -10000000.0, np.array([0] * self.num_metric), True, self.score - 10000000, [0, 0, 0], restart_time external_metrics, internal_metrics = s reward = self._get_reward(external_metrics) flag = self.record_best(external_metrics) if flag == True: logger.info('Better performance changed!') else: logger.info('Performance remained!') #get the best performance so far to calculate the reward best_now_performance = self._get_best_now(self.best_result) self.last_external_metrics = best_now_performance next_state = internal_metrics terminate = self._terminate() knobs.save_knobs( knob = knob, metrics = external_metrics, instance=self.db_info, task_id=self.task_id ) return reward, next_state, terminate, self.score, external_metrics, restart_time
def step(self, knob): """step """ filename = 'bestnow.log' restart_time = utils.time_start() # time delay restart_time = utils.time_end(restart_time) # s conclude external_metrics and internal_metrics s = self._get_state(knob, method=self.method) if s is None: return -10000000.0, np.array( [0] * self.num_metric), True, self.score - 10000000, [ 0, 0, 0 ], restart_time external_metrics, internal_metrics = s # 在这里改变了score的记录 reward = self._get_reward(external_metrics) # 记录最佳的reward flag = self.record_best(external_metrics) if flag == True: print('Better performance changed!') else: print('Performance remained!') # get the best performance so far to calculate the reward best_now_performance = self._get_best_now(filename) self.last_external_metrics = best_now_performance next_state = internal_metrics terminate = self._terminate() knobs.save_knobs( knob=knob, metrics=external_metrics, knob_file='%sAutoTuner1/tuner/save_knobs/knob_metric.txt' % PROJECT_DIR) return reward, next_state, terminate, self.score, external_metrics, restart_time
env_step_times = [] # restart time env_restart_times = [] # choose_action_time action_step_times = [] print("[Environment Intialize]Tps: {} Lat:{}".format(default_metrics[0], default_metrics[1])) print("------------------- Starting to Test -----------------------") while step_counter < opt.max_steps: step_time = utils.time_start() state = current_state action_step_time = utils.time_start() action = model.choose_action(state) action_step_time = utils.time_end(action_step_time) current_knob = generate_knob(action, 'ddpg') logger.info("[ddpg] Action: {}".format(action)) env_step_time = utils.time_start() reward, state_, done, score, metrics, restart_time = env.step(current_knob) env_step_time = utils.time_end(env_step_time) logger.info("[{}][Step: {}][Metric tps:{} lat:{}, qps: {}]Reward: {} Score: {} Done: {}".format( opt.method, step_counter, metrics[0], metrics[1], metrics[2], reward, score, done )) _tps, _lat = compute_percentage(default_metrics, metrics) logger.info("[{}][Knob Idx: {}] tps increase: {}% lat decrease: {}%".format(