def test_no_cross_packages_placement_no_bad_affinity_ip(self): w_a = get_test_workload("a", 3, STATIC) w_b = get_test_workload("b", 2, STATIC) w_c = get_test_workload("c", 1, STATIC) w_d = get_test_workload("d", 2, STATIC) cpu = get_cpu(package_count=2, cores_per_package=2, threads_per_core=2) workload_manager = WorkloadManager(cpu, MockCgroupManager(), IntegerProgramCpuAllocator()) workload_manager.add_workload(w_a) workload_manager.add_workload(w_b) workload_manager.add_workload(w_c) workload_manager.add_workload(w_d) self.assertEqual( 0, len(get_cross_package_violations(workload_manager.get_cpu()))) self.assertEqual(0, len(workload_manager.get_cpu().get_empty_threads()))
def test_assign_two_threads_empty_cpu_ip(self): """ Workload 0: 2 threads --> (p:0 c:0 t:0) (p:0 c:1 t:0) """ cpu = get_cpu() allocator = IntegerProgramCpuAllocator(cpu) w = Workload(uuid.uuid4(), 2, STATIC) allocator.assign_threads(w) self.assertEqual(2, len(cpu.get_claimed_threads())) # Expected core and threads core00 = cpu.get_packages()[0].get_cores()[0] core01 = cpu.get_packages()[0].get_cores()[1] thread0 = core00.get_threads()[0] self.assertEqual(0, thread0.get_id()) self.assertTrue(thread0.is_claimed()) thread1 = core01.get_threads()[0] self.assertEqual(1, thread1.get_id()) self.assertTrue(thread1.is_claimed())
def test_assign_two_workloads_empty_cpu_ip(self): """ Workload 0: 2 threads --> (p:0 c:0 t:0) (p:0 c:1 t:0) Workload 1: 1 thread --> (p:1 c:0 t:0) """ for allocator in [ IntegerProgramCpuAllocator(), forecast_ip_alloc_simple ]: cpu = get_cpu() w0 = get_test_workload(uuid.uuid4(), 2, STATIC) w1 = get_test_workload(uuid.uuid4(), 1, STATIC) request0 = AllocateThreadsRequest(cpu, w0.get_id(), {w0.get_id(): w0}, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.assign_threads(request0).get_cpu() request1 = AllocateThreadsRequest(cpu, w1.get_id(), { w0.get_id(): w0, w1.get_id(): w1 }, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.assign_threads(request1).get_cpu() self.assertEqual(3, len(cpu.get_claimed_threads())) ids_per_socket = [] for pid, p in enumerate(cpu.get_packages()): r = [] for cid, c in enumerate(p.get_cores()): for tid, t in enumerate(c.get_threads()): if t.is_claimed(): self.assertEqual(1, len(t.get_workload_ids())) r.append((t.get_workload_ids()[0], c.get_id())) ids_per_socket.append(r) for r in ids_per_socket: # each workload should be on a different socket self.assertEqual(1, len(set([e[0] for e in r]))) # assigned threads should be on different coreds core_ids = [e[1] for e in r] self.assertEqual(len(set(core_ids)), len(core_ids))
def test_shared_core_violation(self): allocator = IntegerProgramCpuAllocator() # Claim all thread but one cpu = get_cpu() w_0 = get_test_workload(uuid.uuid4(), len(cpu.get_threads()) - 1, STATIC) request = get_no_usage_threads_request(cpu, [w_0]) cpu = allocator.assign_threads(request).get_cpu() log.info("{}".format(cpu)) violations = get_shared_core_violations(cpu) log.info("shared core violations: {}".format(violations)) self.assertEqual(0, len(violations)) # Assign another workload which will force core sharing w_1 = get_test_workload(uuid.uuid4(), 1, STATIC) request = get_no_usage_threads_request(cpu, [w_0, w_1]) cpu = allocator.assign_threads(request).get_cpu() log.info("{}".format(cpu)) violations = get_shared_core_violations(cpu) log.info("shared core violations: {}".format(violations)) self.assertEqual(1, len(violations))
def test_assign_ten_threads_empty_cpu_ip(self): """ Workload 0: 10 threads --> (p:0 c:[0-7] t:[0-9]) | 1 | 1 | 1 | 1 | | 1 | 1 | | | | ------------- | | 1 | 1 | 1 | 1 | | | | | | """ cpu = get_cpu() allocator = IntegerProgramCpuAllocator(cpu) w = Workload(uuid.uuid4(), 10, STATIC) allocator.assign_threads(w) self.assertEqual(10, len(cpu.get_claimed_threads())) expected_thread_ids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 12] thread_ids = [thread.get_id() for thread in cpu.get_claimed_threads()] thread_ids.sort() self.assertEqual(expected_thread_ids, thread_ids)
def test_shared_core_violation(self): cpu = get_cpu() violations = get_shared_core_violations(cpu) log.info("shared core violations: {}".format(violations)) self.assertEqual(0, len(violations)) # Claim 1 thread on every core dummy_workload_id = uuid.uuid4() for p in cpu.get_packages(): for c in p.get_cores(): c.get_threads()[0].claim(dummy_workload_id) violations = get_shared_core_violations(cpu) log.info("shared core violations: {}".format(violations)) self.assertEqual(0, len(violations)) # Assign another workload which will force core sharing allocator = IntegerProgramCpuAllocator(cpu) w = Workload(uuid.uuid4(), 2, STATIC) allocator.assign_threads(w) violations = get_shared_core_violations(cpu) log.info("shared core violations: {}".format(violations)) self.assertEqual(2, len(violations))
def __assign_workload(cpu, workload): request = AllocateThreadsRequest(cpu, workload.get_id(), {workload.get_id(): workload}, {}, DEFAULT_TEST_REQUEST_METADATA) return IntegerProgramCpuAllocator().assign_threads(request).get_cpu()
def __get_default_workload_manager(): cpu = get_cpu() return WorkloadManager(cpu, MockCgroupManager(), IntegerProgramCpuAllocator())
self.pod = None def set_pod(self, pod: V1Pod): self.pod = pod def get_pod(self, pod_name: str) -> Optional[V1Pod]: return self.pod forecast_ip_alloc_simple = ForecastIPCpuAllocator( TestCpuUsagePredictorManager(), ConfigManager(TestPropertyProvider({})), OversubscribeFreeThreadProvider(0.1)) ALLOCATORS = [ NaiveCpuAllocator(), IntegerProgramCpuAllocator(), GreedyCpuAllocator(), forecast_ip_alloc_simple ] OVER_ALLOCATORS = [NaiveCpuAllocator(), forecast_ip_alloc_simple] set_workload_monitor_manager(TestWorkloadMonitorManager()) class TestCpu(unittest.TestCase): def test_assign_one_thread_empty_cpu(self): """ Workload 0: 1 thread --> (p:0 c:0 t:0) """ for allocator in ALLOCATORS: cpu = get_cpu() self.assertEqual(DEFAULT_TOTAL_THREAD_COUNT,
OVERSUBSCRIBED_THREADS_KEY, STATIC_ALLOCATED_SIZE_KEY, BURST_ALLOCATED_SIZE_KEY, \ BURST_REQUESTED_SIZE_KEY, ALLOCATED_SIZE_KEY, UNALLOCATED_SIZE_KEY from titus_isolate.model.processor.config import get_cpu from titus_isolate.model.processor.utils import DEFAULT_TOTAL_THREAD_COUNT, is_cpu_full from titus_isolate.monitor.oversubscribe_free_thread_provider import OversubscribeFreeThreadProvider from titus_isolate.utils import set_config_manager, set_workload_monitor_manager config_logs(logging.DEBUG) set_config_manager(ConfigManager(TestPropertyProvider({}))) set_workload_monitor_manager(TestWorkloadMonitorManager()) forecast_ip_alloc_simple = ForecastIPCpuAllocator( TestCpuUsagePredictorManager(), ConfigManager(TestPropertyProvider({})), OversubscribeFreeThreadProvider(DEFAULT_TOTAL_THRESHOLD)) LEGACY_ALLOCATORS = [IntegerProgramCpuAllocator(), GreedyCpuAllocator()] OVERSUBSCRIBING_ALLOCATORS = [forecast_ip_alloc_simple] ALLOCATORS = LEGACY_ALLOCATORS + OVERSUBSCRIBING_ALLOCATORS class TestWorkloadManager(unittest.TestCase): def test_single_static_workload_lifecycle(self): for allocator in ALLOCATORS: thread_count = 2 workload = get_test_workload(uuid.uuid4(), thread_count, STATIC) cgroup_manager = MockCgroupManager() workload_manager = WorkloadManager(get_cpu(), cgroup_manager, allocator) # Add workload
def __assign_workload(cpu, workload): request = get_no_usage_threads_request(cpu, [workload]) return IntegerProgramCpuAllocator().assign_threads(request).get_cpu()