Example #1
0
    def qos_share_limit_policy(self, host: Host):

        total_containers = host.active_list_counter(
        ) + host.inactive_list_counter()
        total_max_memory = host.get_max_usable_memoryPG()

        if self.level == 'BEST':

            if (host.active_list_counter() > 0):
                total_used = host.get_container_total_usedPG()
                local_NAHM = total_max_memory - total_used
                log_basic.info('Effective Not Used NAHM: %d', local_NAHM)
                shared_local_NAHM = round(local_NAHM / total_containers)

                for container in host.container_active_list:

                    if (container.getContainerState()
                            == 'RUNNING') and (shared_local_NAHM > 0):
                        mem_used = container.getUsedMemoryPG()
                        mem_limit = container.getMemoryLimitPG()
                        log_basic.info('C: %s, CMU: %d, CML: %d',
                                       container.name, mem_used, mem_limit)

                        new_limit = mem_used + shared_local_NAHM
                        local_NAHM -= shared_local_NAHM
                        container.setMemLimit2(new_limit)
                        log_basic.info(
                            'Best Effort Adjusts Container: %s, new CML: %d',
                            container.name, container.getMemoryLimitPG())

                self.NAHM = local_NAHM
                log_basic.info('Remain NAHM to start new containers: %d',
                               self.NAHM)

        elif self.level == 'FAIR':

            new_limit = round(total_max_memory / total_containers)

            if host.active_list_counter() > 0:

                for container in host.container_active_list:

                    if container.getContainerState() == 'RUNNING':
                        mem_limit = container.getMemoryLimitPG()
                        log_basic.info('C: %s, CML: %d', container.name,
                                       mem_limit)

                        if new_limit < container.getMinMemoryLimitPG():
                            new_limit = container.getMinMemoryLimitPG()

                        delta = mem_limit - new_limit
                        self.NAHM += delta
                        container.setMemLimit2(new_limit)
                        log_basic.info(
                            'Fair Share Stolen Container: %s, Delta: %d, new CML T1\u25BC: %d, new NAHM\u25B2: %d',
                            container.name, delta,
                            container.getMemoryLimitPG(), self.NAHM)
Example #2
0
    def qos_recovery_limit_policy(self, host: Host):
        limit_division = round(self.NAHM / host.active_list_counter())

        for container in host.container_active_list:
            mem_limit = container.getMemoryLimitPG()
            max_limit = container.getMaxMemoryLimitPG()
            log_basic.info('C: %s, CML: %d', container.name, mem_limit)

            if self.level == 'FAIR':

                if ((mem_limit + limit_division) > max_limit) and (mem_limit !=
                                                                   max_limit):
                    self.NAHM -= max_limit - mem_limit
                    container.setMemLimit2(max_limit)
                    log_basic.info(
                        'Readjusting to Max Container: %s, new CML T1\u25B2: %d, new NAHM: %d\u25BC',
                        container.name, container.getMemoryLimitPG(),
                        self.NAHM)

                elif (mem_limit + limit_division) < max_limit:
                    new_limit = mem_limit + limit_division
                    self.NAHM -= limit_division
                    container.setMemLimit2(new_limit)
                    log_basic.info(
                        'Readjusting Container: %s, new CML T1\u25B2: %d, new NAHM\u25BC: %d',
                        container.name, container.getMemoryLimitPG(),
                        self.NAHM)

            elif self.level == 'BEST':
                new_limit = mem_limit + limit_division
                self.NAHM -= limit_division
                container.setMemLimit2(new_limit)
                log_basic.info(
                    'Readjusting Container: %s, new CML T1\u25B2: %d, new NAHM\u25BC: %d',
                    container.name, container.getMemoryLimitPG(), self.NAHM)
Example #3
0
def no_manager(shared_list: list, entry_queue: mp.Queue):
    logNM = logging.getLogger('Container_Manager')
    logNM.setLevel(logging.INFO)
    format = logging.Formatter(fmt='%(asctime)s %(levelname)s %(message)s',
                               datefmt='%d/%m/%Y %H:%M:%S')
    file_handler = logging.FileHandler(filename='./log/no-manager.log',
                                       mode='a')
    file_handler.setFormatter(format)
    file_handler.setLevel(logging.DEBUG)
    logNM.addHandler(file_handler)

    sched = Basic()

    config = ConfigParser()
    config.read('./config/local-config.txt')
    sched.setLevel(config['QoS']['level'])

    host = Host()
    sched_counter = 1

    while True:
        start_time = datetime.now()
        logNM.info('========================================================')
        logNM.info('Sched counter: %d', sched_counter)
        logNM.info('Sched init timestamp: %s', start_time)
        print(sched_counter, datetime.now())

        # Add Created Containers
        while not entry_queue.empty():
            container = entry_queue.get()
            logNM.info('New Container: %s', container.name)
            container.inactive_time = datetime.now()
            container.setContainerState('QUEUED')
            host.container_inactive_list.append(container)

        host.update()
        host.update_containers2()

        TCML, NAHM, HAM = host.get_host_memory_info()
        sched.setNAHM(NAHM)
        logNM.info('NAHM: %d, HAM: %d, TCML: %d', sched.getNAHM(), HAM, TCML)
        logNM.info('Active List: %s', host.container_active_list)
        logNM.info('Inactive List: %s', host.container_inactive_list)
        logNM.info('QoS Test: %s', sched.getLevel())

        if (host.inactive_list_counter() != 0):
            logNM.info(
                '---------------------------------------------------------')
            logNM.info('Executing Limit Redistribution Policy:')
            sched.qos_share_limit_policy(host)
            logNM.info(
                '---------------------------------------------------------')
            logNM.info('Executing Start Inactive Containers:')
            sched.qos_start_policy(host)

        else:
            if (sched.getNAHM() > 0) and (sched.getLevel() in [
                    'BEST', 'FAIR'
            ]) and (host.active_list_counter() > 0):
                logNM.info(
                    '---------------------------------------------------------'
                )
                logNM.info('Executing NAHM Redistribution:')
                sched.qos_recovery_limit_policy(host)

        host.update()
        host.update_containers2()

        shared_list[0] = host.container_active_list
        shared_list[1] = host.container_inactive_list

        stop_time = datetime.now()
        logNM.info('Sched end timestamp: %s', stop_time)
        latency = (stop_time - start_time).total_seconds()
        logNM.info('New Sched Latency: %f', latency)
        logNM.info('Sleep time: %f seconds', 1 - latency)
        logNM.info('========================================================')
        sched_counter += 1

        if (latency < 1):
            time.sleep(1 - latency)