Example #1
0
    def initialize(self):
        """ Initialize the environment when an episode starts
        Returns:
            state: np.array, current state
        """
        self.score = 0.0
        self.last_external_metrics = []
        self.steps = 0
        self.terminate = False

        flag = self._apply_knobs(self.default_knobs)
        i = 0
        while not flag:
            flag = self._apply_knobs(self.default_knobs)
            i += 1
            if i >= 5:
                print("Initialize: {} times ....".format(i))

        external_metrics, internal_metrics = self._get_state(
            knob=self.default_knobs, method=self.method)
        self.last_external_metrics = external_metrics
        self.default_externam_metrics = external_metrics

        state = internal_metrics
        knobs.save_knobs(
            self.default_knobs,
            metrics=external_metrics,
            knob_file='%sAutoTuner/tuner/save_knobs/knob_metric.txt' %
            PROJECT_DIR)
        return state, external_metrics
Example #2
0
    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
Example #3
0
 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
Example #4
0
    def initialize(self):
        """ Initialize the environment when an episode starts
        Returns:
            state: np.array, current state
        """
        self.score = 0.0
        self.last_external_metrics = []
        self.steps = 0
        self.terminate = False

        flag = self._apply_knobs(self.default_knobs)
        i = 0
        while not flag:
            if i >= 2:
                logger.info("Initialize: {} times ....".format(i))
                os_quit(Err.SET_MYSQL_PARAM_FAILED)
            flag = self._apply_knobs(self.default_knobs)
            i += 1

        external_metrics, internal_metrics = self._get_state(
            knob=self.default_knobs, method=self.method)
        if os.path.exists(self.best_result):
            if os.path.getsize(self.best_result):
                with open(self.best_result) as f:
                    lines = f.readlines()
                best_now = lines[0].split(',')
                self.last_external_metrics = [
                    float(best_now[0]),
                    float(best_now[1]),
                    float(best_now[0])
                ]
        else:
            self.last_external_metrics = external_metrics
        self.default_externam_metrics = external_metrics

        state = internal_metrics
        knobs.save_knobs(self.default_knobs,
                         metrics=external_metrics,
                         instance=self.db_info,
                         task_id=self.task_id)
        return state, external_metrics
Example #5
0
    def initialize(self):
        """ Initialize the environment when an episode starts
        Returns:
            state: np.array, current state
        """
        self.score = 0.0
        self.last_external_metrics = []
        self.steps = 0
        self.terminate = False

        external_metrics, internal_metrics = self._get_state(
            knob=self.default_knobs, method=self.method)
        self.last_external_metrics = external_metrics
        self.default_externam_metrics = external_metrics
        state = internal_metrics
        knobs.save_knobs(
            self.default_knobs,
            metrics=external_metrics,
            knob_file='%sAutoTuner1/tuner/save_knobs/knob_metric.txt' %
            PROJECT_DIR)
        return state, external_metrics
Example #6
0
    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
Example #7
0
    def step(self, knob):
        #apply_knobs
        #Yiming?
        restart_time = 123  # random value
        filename = 'bestnow.log'
        flag = self._apply_knobs(knob)
        if flag != 0:
            return -10000000.0, np.array(
                [0] * self.num_metric), True, self.score - 10000000, [
                    0, 0, 0
                ], restart_time
        s = self._get_state()
        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:
            print('Better performance changed!')
        else:
            print('Performance remained!')

        best_now_performance = self._get_best_now(filename)
        self.last_external_metrics = best_now_performance

        next_state = internal_metrics
        self.terminate = self._encode_complete()
        terminate = self._terminate()
        knobs.save_knobs(knob=knob,
                         metrics=external_metrics,
                         knob_file='%s/tuner/save_knobs/knob_metric.txt' %
                         PROJECT_DIR)

        return reward, next_state, terminate, self.score, external_metrics, restart_time
Example #8
0
    def initialize(self):
        """Initialize the encoder instance environment
        """
        self.score = 0.0
        self.steps = 0
        self.terminate = False
        self.last_external_metrics = []
        push_frame_thread(self.video)
        flag = self._apply_knobs(self.default_knobs)
        i = 0
        while not flag:
            flag = self._apply_knobs(self.default_knobs)
            i += 1
            if i >= 5:
                print("Initialize: {} times ....".format(i))
        '''
        def_knobs = {}

        
        
        for item in KNOB_DETAILS:
            flag = self._apply_knobs([(str(item),str(KNOB_DETAILS[item][1][2]))])
            def_knobs[str(item)] = str(KNOB_DETAILS[item][1][2])
            if flag != 0:
                print("Knob Application of knob " + str(item) + " with value " +str(KNOB_DETAILS[item][1][2]) + " resulted in error " + str(flag) + " in my encoder initialize")
       '''
        external_metrics, internal_metrics = self._get_state()
        state = internal_metrics
        self.default_externam_metrics = external_metrics
        self.last_external_metrics = external_metrics

        knobs.save_knobs(self.default_knobs,
                         metrics=external_metrics,
                         knob_file='%s/tuner/save_knobs/knob_metric.txt' %
                         PROJECT_DIR)

        return state, external_metrics