Ejemplo n.º 1
0
    def __compute_allocation(self, cpu, workload_id, workloads,
                             curr_ids_per_workload, cpu_usage, is_add):
        predicted_usage = {}  # self.__predict_usage(workloads, cpu_usage)
        cpu = self.__place_threads(cpu, workload_id, workloads,
                                   curr_ids_per_workload, predicted_usage,
                                   is_add)

        # Burst workload computation
        burst_workloads = get_burst_workloads(workloads.values())
        if not is_add:
            burst_workloads = [
                workload for workload in burst_workloads
                if workload.get_id() != workload_id
            ]

        # Claim all free threads for burst workloads
        burst_workload_ids = [w.get_id() for w in burst_workloads]
        free_threads = self.__free_thread_provider.get_free_threads(
            cpu, workloads, predicted_usage)
        for t in free_threads:
            for w_id in burst_workload_ids:
                t.claim(w_id)

        self.__call_meta[FREE_THREAD_IDS] = [t.get_id() for t in free_threads]
        return cpu
Ejemplo n.º 2
0
    def assign_threads(self, request: AllocateThreadsRequest) -> AllocateResponse:
        cpu = request.get_cpu()
        workloads = request.get_workloads()
        workload_id = request.get_workload_id()

        burst_workloads = get_burst_workloads(workloads.values())
        release_all_threads(cpu, burst_workloads)
        if workloads[workload_id].get_type() == STATIC:
            self.__assign_threads(cpu, workloads[workload_id])
        update_burst_workloads(cpu, workloads, self.__free_thread_provider)

        return AllocateResponse(cpu, self.get_name())
Ejemplo n.º 3
0
    def free_threads(self, request: AllocateThreadsRequest) -> AllocateResponse:
        cpu = request.get_cpu()
        workloads = request.get_workloads()
        workload_id = request.get_workload_id()

        burst_workloads = get_burst_workloads(workloads.values())
        release_all_threads(cpu, burst_workloads)
        for t in cpu.get_threads():
            if workload_id in t.get_workload_ids():
                t.free(workload_id)

        workloads.pop(workload_id)
        update_burst_workloads(cpu, workloads, self.__free_thread_provider)

        return AllocateResponse(cpu, self.get_name())
Ejemplo n.º 4
0
    def free_threads(self,
                     request: AllocateThreadsRequest) -> AllocateResponse:
        cpu = request.get_cpu()
        workloads = request.get_workloads()
        workload_id = request.get_workload_id()

        burst_workloads = get_burst_workloads(workloads.values())
        release_all_threads(cpu, burst_workloads)
        if workloads[workload_id].get_type() == STATIC:
            self.__free_threads(cpu, workload_id, workloads)
        workloads.pop(workload_id)
        metadata = {}
        update_burst_workloads(cpu, workloads, self.__free_thread_provider,
                               metadata)

        return AllocateResponse(
            cpu, get_workload_allocations(cpu, workloads.values()),
            self.get_name(), metadata)
Ejemplo n.º 5
0
def get_burst_request_size(workloads: list) -> int:
    burst_request_size = 0
    for w in get_burst_workloads(workloads):
        burst_request_size += w.get_thread_count()

    return burst_request_size