Пример #1
0
 def __init__(self,
              wk_type,
              instance_name,
              method='sysbench',
              num_metric=63,
              num_other_knobs=0):
     """Initialize `TencentServer` Class
     Args:
         instance_name: str, mysql instance name, get the database infomation
     """
     MySQLEnv.__init__(self, wk_type)
     # super(MySQLEnv, self).__init__()
     self.wk_type = wk_type
     self.score = 0.0
     self.num_metric = num_metric
     self.steps = 0
     self.terminate = False
     self.last_external_metrics = None
     self.instance_name = instance_name
     self.db_info = configs.instance_config[instance_name]
     self.url = self.db_info['server_url']
     self.alpha = 1.0
     self.method = method
     knobs.init_knobs(instance_name, num_other_knobs)
     self.default_knobs = knobs.get_init_knobs()
Пример #2
0
 def __init__(self, wk_type, instance_name):
     MySQLEnv.__init__(self, wk_type)
     self.wk_type = wk_type
     self.score = 0.0
     self.steps = 0
     self.terminate = False
     self.last_external_metrics = None
     self.instance_name = instance_name
     self.db_info = configs.instance_config[instance_name]
     self.server_ip = self.db_info['host']
     self.alpha = 1.0
     knobs.init_knobs(instance_name, num_more_knobs=0)
     self.default_knobs = knobs.get_init_knobs()
Пример #3
0
    def __init__(self, video, width, height, fps, num_metric=42):
        self.video = video
        self.width = width
        self.height = height
        self.fps = fps

        self.steps = 0
        self.score = 0.0
        self.terminate = False
        self.last_external_metrics = []
        self.default_externam_metrics = None
        self.num_metric = num_metric

        knobs.init_knobs(num_more_knobs=0)
        self.default_knobs = knobs.get_init_knobs()

        #create an x265 encoder
        encoder_create(self.width, self.height, self.fps)
Пример #4
0
    def __init__(self,  instance, task_detail,model_detail,host):
        """Initialize `TencentServer` Class
        Args:
            instance_name: str, mysql instance name, get the database infomation
        """
        MySQLEnv.__init__(self, task_detail["rw_mode"])
        # super(MySQLEnv, self).__init__()
        self.wk_type = task_detail["rw_mode"]
        self.score = 0.0
        self.num_metric = model_detail["dimension"]
        self.steps = 0
        self.task_id = task_detail["task_id"]
        self.terminate = False
        self.last_external_metrics = None
        self.db_info = instance
        self.host = host
        self.alpha = 1.0
        self.method = task_detail["run_mode"]
        self.best_result = CONST.FILE_LOG_BEST % self.task_id
        self.threads = task_detail["threads"]

        knobs.init_knobs(instance,model_detail["knobs"])
        self.default_knobs = knobs.get_init_knobs()
Пример #5
0
import numpy as np
import knobs
from encoder_tune import *
import os
import knobs
import pdb

BEST_NOW = ""
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

KNOB_DETAILS = knobs.init_knobs()


class MyEncoder(object):
    def __init__(self, video, width, height, fps, num_metric=42):
        self.video = video
        self.width = width
        self.height = height
        self.fps = fps

        self.steps = 0
        self.score = 0.0
        self.terminate = False
        self.last_external_metrics = []
        self.default_externam_metrics = None
        self.num_metric = num_metric

        knobs.init_knobs(num_more_knobs=0)
        self.default_knobs = knobs.get_init_knobs()

        #create an x265 encoder
Пример #6
0
def run_with_knobs(lathe):
    print("Running in interactive mode")
    lock = threading.Lock()

    # mode constants
    ABSOLUTE = 0  # knobs move a specified amount
    SPEED = 1  # knobs affect current speed

    # direction constants
    LEFT = 0
    RIGHT = 1

    gamma = 1.5
    max_speed_index = 16

    # state
    period = 1 / 8192
    mode = ABSOLUTE
    abs_speed = 1
    move_amount = [0, 0]

    speed_index = [0, 0]
    motion_dir = [0, 0]
    events_per_step = [0, 0]

    def move(dir, amount):
        nonlocal speed_index, motion_dir, events_per_step

        # dir in [0, 1], 0 == left, 1 == right
        if mode == ABSOLUTE:
            if amount:
                val = abs_speed * amount
                with lock:
                    move_amount[dir] += val
                print("move {} {} ({})".format(dir, val, move_amount))
        else:

            speed_index[dir] += amount
            speed_index[dir] = clamp_inclusive(speed_index[dir],
                                               -max_speed_index,
                                               max_speed_index)

            # compute move amount given left and right speed indices and count
            if speed_index[dir] < 0:
                motion_dir[dir] = -1
            elif speed_index[dir] > 0:
                motion_dir[dir] = 1
            else:
                motion_dir[dir] = 0

            speed = MAX_SPEED * pow(
                abs(speed_index[dir]) / max_speed_index, gamma)
            steps_per_sec = speed / IN_PER_STEP  # = (in / s) / (in/step) -> steps / s
            if steps_per_sec == 0:
                events_per_step[dir] = 0
            else:
                events_per_step[dir] = int(1 / (period * steps_per_sec))

            print(
                "speed_index: {}\tsteps_per_sec: {}\tspeed: {}\tevents_per_step: {}"
                .format(speed_index, speed, steps_per_sec, events_per_step))

    def move_l(amount):
        move(LEFT, -amount)

    def move_r(amount):
        move(RIGHT, -amount)

    # Change steps per detent in ABSOLUTE mode
    def button_l(state):
        nonlocal abs_speed
        if state and (mode == ABSOLUTE):  # button-up
            abs_speed *= 2
            if abs_speed > MAX_DIST_PER_MOVE:
                abs_speed = 1
            print("speed: {}".format(abs_speed))

    # toggle between ABSOLUTE and SPEED modes
    def button_r(state):
        nonlocal mode, speed_index, motion_dir, events_per_step
        if state:  # button-up
            speed_index = [0, 0]
            events_per_step = [0, 0]
            motion_dir = [0, 0]
            if mode == ABSOLUTE:
                mode = SPEED
            else:
                mode = ABSOLUTE
            print("mode: {}".format("ABS" if mode == ABSOLUTE else "REL"))

    def timer_func(count):
        nonlocal lock
        nonlocal mode, move_amount
        nonlocal events_per_step, motion_dir

        # atomic copy-and-zero
        x, y = 0, 0
        with lock:
            x, y = move_amount
            move_amount = [0, 0]

        if mode == SPEED:
            if events_per_step[
                    LEFT] != 0 and count % events_per_step[LEFT] == 0:
                x += motion_dir[LEFT]
            if events_per_step[
                    RIGHT] != 0 and count % events_per_step[RIGHT] == 0:
                y += motion_dir[RIGHT]

        if x or y:
            lathe.move(x, y)

    knobs.init_knobs()
    knobs.set_knob_callback(knobs.LEFT_MOVE, move_l)
    knobs.set_knob_callback(knobs.RIGHT_MOVE, move_r)
    knobs.set_knob_callback(knobs.LEFT_BUTTON, button_l)
    knobs.set_knob_callback(knobs.RIGHT_BUTTON, button_r)

    s = scheduler.scheduler(period)
    s.run(scheduler.FOREVER, timer_func)