Ejemplo n.º 1
0
def configure_env(settings: EnvSettings, topology: Topology):
    env = Environment()
    env.simulator_factory = settings.simulator_factory
    if settings.null_logger:
        env.metrics = OurMetrics(env, log=NullLogger())
    else:
        env.metrics = OurMetrics(env, log=RuntimeLogger(SimulatedClock(env)))
    env.topology = topology
    env.faas = OurFaas(env, settings.scale_by_requests,
                       settings.scale_by_requests_per_replica,
                       settings.scale_by_queue_requests_per_replica)
    env.container_registry = ContainerRegistry()
    env.storage_index = settings.storage_index
    env.cluster = SimulationClusterContext(env)
    env.scheduler = Scheduler(env.cluster, **settings.sched_params)
    env.metrics_server = MetricsServer()

    # TODO inject resource oracle
    resource_monitor = ResourceMonitor(
        env, ResourceOracle(resources_per_node_image))
    env.background_processes.append(lambda env: resource_monitor.run())

    if settings.scale_by_resources:
        hpa_settings = settings.hpaSettings
        hpa = HorizontalPodAutoscaler(
            env,
            average_window=hpa_settings.average_window,
            reconcile_interval=hpa_settings.reconcile_interval,
            target_tolerance=hpa_settings.target_tolerance)
        env.background_processes.append(lambda env: hpa.run())

    if settings.label_problem_solver_settings is not None:
        solver = LabelSolverProcess(settings.label_problem_solver_settings)
        env.background_processes.append(lambda env: solver.solve(env))
    return env
Ejemplo n.º 2
0
    def __init__(self):
        all_images = images.all_images

        fet_oracle = FetOracle(execution_time_distributions)
        resource_oracle = ResourceOracle(resources_per_node_image)

        deployments = create_all_deployments(fet_oracle, resource_oracle)

        super().__init__(all_images, list(deployments.values()), arrival_profiles=dict())
Ejemplo n.º 3
0
    def __init__(self,
                 profile: str,
                 arrival_patterns: Dict[str, str],
                 duration: int,
                 model_folder='./data'):
        all_images = images.all_images
        self.model_folder = model_folder
        self.profile = profile
        self.arrival_patterns = arrival_patterns
        fet_oracle = FetOracle(execution_time_distributions)
        resource_oracle = ResourceOracle(resources_per_node_image)

        deployments = create_deployments_for_profile(profile, fet_oracle,
                                                     resource_oracle)

        super().__init__(all_images,
                         list(deployments.values()),
                         arrival_profiles=dict(),
                         duration=duration)
Ejemplo n.º 4
0
def main():
    """
    Example of settings.json:
    {
        "cores": int,
        "seed": int,
        "model_folder": "path/to/models",
        "device_folder": "path/to/devices",
        "clustering_folder": "path/to/clustering_jsons",
        "solutions_folder": "path/where/solutions/are/saved",
        "ga_results|folder": "path/to/ga_solution_folder

        Scheduler settings
        "percentage_of_nodes_to_scores": [int],

        PriorityWeights
        "capability_weights": [start, stop, num],
        "contention_weights": [start, stop, num],
        "fet_weights": [start, stop, num],

        "profiles": selection of ["ai", "service", "mixed"],
        "durations": [start, stop, num],

        Sine scenario settings
        "sine_max_rps": [start, stop, num],
        "sine_periods": [start, stop, num],

        Constant scenario settings
        "constant_rps": [start,stop,num]
    }

    * folder paths are relative to path of settings.json

    * for definition of [start, stop, num] lookup up doc of np.linspace

    Hints on setting GA parameters:
    https://github.com/PasaOpasen/geneticalgorithm2#hints-on-how-to-adjust-genetic-algorithms-parameters

    * max_num_iterations should be large, only downside is longer runtime
    * population size is shorter recommended, may get stuck in local optima (100 recommended)
    * elit_ratio: recommended to select at most one from population, sometimes 0 is best
    * mutation_probability: probably has to be adjusted more than others; can range from 0.01 to 0.5 or even larger
    * parents portion: anything between 1 and 0 may work
    * crossover_type: uniform crossover recommended

    :return:
    """
    if len(sys.argv) != 2:
        raise ValueError('Expected usage:eval.py settings.json')
    settings_file_path = sys.argv[1]
    settings_folder = os.path.dirname(settings_file_path)
    with open(settings_file_path, 'r') as fd:
        settings = json.load(fd)

    seed = settings['seed']
    set_seed(seed)

    model_folder = os.path.join(settings_folder, settings['model_folder'])
    solutions_folder = settings['solutions_folder']
    ga_results_folder = settings['ga_results_folder']
    profiles = settings['profiles']

    if not check_ga_results_available(settings_folder, solutions_folder,
                                      ga_results_folder, profiles):
        raise ValueError(
            f"Passed ga_results_folder were not availabel: {ga_results_folder}"
        )

    fet_oracle = FetOracle(execution_time_distributions)
    resource_oracle = ResourceOracle(resources_per_node_image)

    now = datetime.datetime.now()
    now = now.strftime('%m_%d_%Y_%H_%M_%S')
    destination_folder = os.path.join(
        settings_folder, solutions_folder,
        f'{os.path.basename(settings_file_path[:-5])}_{now}')
    mkdir(destination_folder)
    for profile in profiles:
        single_run_result: SingleRunGaResult
        results_folder = os.path.join(destination_folder, profile)
        sim_results_folder = os.path.join(results_folder, 'sim_results')

        mkdir(results_folder)
        mkdir(sim_results_folder)

    logging.info('start sims')
    scaling_settings = {
        'alert_window':
        FunctionDeployment.alert_window,
        'target_queue_length':
        FunctionDeployment.target_queue_length,
        'target_average_rps_threshold':
        FunctionDeployment.target_average_rps_threshold
    }
    for single_run_result, profile in read_ga_results(settings_folder,
                                                      solutions_folder,
                                                      ga_results_folder,
                                                      profiles):
        for result in run_all_sim(single_run_result, profile, model_folder,
                                  fet_oracle, resource_oracle, settings):
            results_folder = os.path.join(destination_folder, profile)
            sim_results_folder = os.path.join(results_folder, 'sim_results')
            result.settings.update(settings)
            result.settings.update(scaling_settings)
            save_sim_result(sim_results_folder, result)