VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared { @Override protected boolean allocatePesForVm(String vmUid, List<Double> mipsShareRequested) { double totalRequestedMips = 0; List<Double> mipsShareRequestedCapped = new ArrayList<Double>(); double peMips = getPeCapacity(); for (Double mips : mipsShareRequested) { if (mips > peMips) { mipsShareRequestedCapped.add(peMips); totalRequestedMips += peMips; } else { mipsShareRequestedCapped.add(mips); totalRequestedMips += mips; } } getMipsMapRequested().put(vmUid, mipsShareRequested); setPesInUse(getPesInUse() + mipsShareRequested.size()); if (getVmsMigratingIn().contains(vmUid)) { totalRequestedMips *= 0.1; } if (getAvailableMips() >= totalRequestedMips) { List<Double> mipsShareAllocated = new ArrayList<Double>(); for (Double mipsRequested : mipsShareRequestedCapped) { if (getVmsMigratingOut().contains(vmUid)) { mipsRequested *= 0.9; } else if (getVmsMigratingIn().contains(vmUid)) { mipsRequested *= 0.1; } mipsShareAllocated.add(mipsRequested); } getMipsMap().put(vmUid, mipsShareAllocated); setAvailableMips(getAvailableMips() - totalRequestedMips); } else { redistributeMipsDueToOverSubscription(); } return true; } VmSchedulerTimeSharedOverSubscription(List<? extends Pe> pelist);   }
@Test public void testAllocatePesForVm() { List<Double> mipsShare1 = new ArrayList<Double>(); mipsShare1.add(MIPS / 4); assertTrue(vmScheduler.allocatePesForVm(vm1, mipsShare1)); assertEquals(PeList.getTotalMips(peList) - MIPS / 4, vmScheduler.getAvailableMips(), 0); assertEquals(PeList.getTotalMips(peList) - MIPS / 4, vmScheduler.getMaxAvailableMips(), 0); assertEquals(MIPS / 4, vmScheduler.getTotalAllocatedMipsForVm(vm1), 0); List<Double> mipsShare2 = new ArrayList<Double>(); mipsShare2.add(MIPS / 2); mipsShare2.add(MIPS / 8); assertTrue(vmScheduler.allocatePesForVm(vm2, mipsShare2)); assertEquals( PeList.getTotalMips(peList) - MIPS / 4 - MIPS / 2 - MIPS / 8, vmScheduler.getAvailableMips(), 0); assertEquals( PeList.getTotalMips(peList) - MIPS / 4 - MIPS / 2 - MIPS / 8, vmScheduler.getMaxAvailableMips(), 0); assertEquals(MIPS / 2 + MIPS / 8, vmScheduler.getTotalAllocatedMipsForVm(vm2), 0); vmScheduler.deallocatePesForAllVms(); assertEquals(PeList.getTotalMips(peList), vmScheduler.getAvailableMips(), 0); assertEquals(PeList.getTotalMips(peList), vmScheduler.getMaxAvailableMips(), 0); assertEquals(0, vmScheduler.getTotalAllocatedMipsForVm(vm2), 0); }
@Test public void testAllocatePesForVmInMigration() { vm1.setInMigration(true); vm2.setInMigration(true); List<Double> mipsShare1 = new ArrayList<Double>(); mipsShare1.add(MIPS / 4); assertTrue(vmScheduler.allocatePesForVm(vm1, mipsShare1)); assertEquals(PeList.getTotalMips(peList) - MIPS / 4, vmScheduler.getAvailableMips(), 0); assertEquals(PeList.getTotalMips(peList) - MIPS / 4, vmScheduler.getMaxAvailableMips(), 0); assertEquals(0.9 * MIPS / 4, vmScheduler.getTotalAllocatedMipsForVm(vm1), 0); List<Double> mipsShare2 = new ArrayList<Double>(); mipsShare2.add(MIPS / 2); mipsShare2.add(MIPS / 8); assertTrue(vmScheduler.allocatePesForVm(vm2, mipsShare2)); assertEquals( PeList.getTotalMips(peList) - MIPS / 4 - MIPS / 2 - MIPS / 8, vmScheduler.getAvailableMips(), 0); assertEquals( PeList.getTotalMips(peList) - MIPS / 4 - MIPS / 2 - MIPS / 8, vmScheduler.getMaxAvailableMips(), 0); assertEquals(0.9 * MIPS / 2 + 0.9 * MIPS / 8, vmScheduler.getTotalAllocatedMipsForVm(vm2), 0); vmScheduler.deallocatePesForAllVms(); assertEquals(PeList.getTotalMips(peList), vmScheduler.getAvailableMips(), 0); assertEquals(PeList.getTotalMips(peList), vmScheduler.getMaxAvailableMips(), 0); assertEquals(0, vmScheduler.getTotalAllocatedMipsForVm(vm2), 0); }
@Test public void testAllocatePesForVmShortageEqualsToAllocatedMips() { List<Pe> peList = new ArrayList<Pe>(); peList.add(new Pe(0, new PeProvisionerSimple(3500))); VmScheduler vmScheduler = new VmSchedulerTimeSharedOverSubscription(peList); Vm vm1 = new Vm(0, 0, 170, 1, 0, 0, 0, "", null); Vm vm2 = new Vm(1, 0, 2000, 1, 0, 0, 0, "", null); Vm vm3 = new Vm(2, 0, 10, 1, 0, 0, 0, "", null); Vm vm4 = new Vm(3, 0, 2000, 1, 0, 0, 0, "", null); List<Double> mipsShare1 = new ArrayList<Double>(); mipsShare1.add(170.0); List<Double> mipsShare2 = new ArrayList<Double>(); mipsShare2.add(2000.0); List<Double> mipsShare3 = new ArrayList<Double>(); mipsShare3.add(10.0); List<Double> mipsShare4 = new ArrayList<Double>(); mipsShare4.add(2000.0); assertTrue(vmScheduler.allocatePesForVm(vm1, mipsShare1)); assertEquals(3330, vmScheduler.getAvailableMips(), 0); assertEquals(170, vmScheduler.getTotalAllocatedMipsForVm(vm1), 0); assertTrue(vmScheduler.allocatePesForVm(vm2, mipsShare2)); assertEquals(1330, vmScheduler.getAvailableMips(), 0); assertEquals(2000, vmScheduler.getTotalAllocatedMipsForVm(vm2), 0); assertTrue(vmScheduler.allocatePesForVm(vm3, mipsShare3)); assertEquals(1320, vmScheduler.getAvailableMips(), 0); assertEquals(10, vmScheduler.getTotalAllocatedMipsForVm(vm3), 0); assertTrue(vmScheduler.allocatePesForVm(vm4, mipsShare4)); assertEquals(0, vmScheduler.getAvailableMips(), 0); assertEquals(1674, vmScheduler.getTotalAllocatedMipsForVm(vm4), 0); vmScheduler.deallocatePesForAllVms(); assertEquals(3500, vmScheduler.getAvailableMips(), 0); assertEquals(3500, vmScheduler.getMaxAvailableMips(), 0); }
@Test public void testAllocatePesForSameSizedVmsOversubscribed() { List<Pe> peList = new ArrayList<Pe>(); peList.add(new Pe(0, new PeProvisionerSimple(1000))); VmScheduler vmScheduler = new VmSchedulerTimeSharedOverSubscription(peList); Vm vm1 = new Vm(0, 0, 1500, 1, 0, 0, 0, "", null); Vm vm2 = new Vm(1, 0, 1000, 1, 0, 0, 0, "", null); Vm vm3 = new Vm(2, 0, 1000, 1, 0, 0, 0, "", null); List<Double> mipsShare1 = new ArrayList<Double>(); mipsShare1.add(1500.0); List<Double> mipsShare2 = new ArrayList<Double>(); mipsShare2.add(1000.0); List<Double> mipsShare3 = new ArrayList<Double>(); mipsShare3.add(1000.0); assertTrue(vmScheduler.allocatePesForVm(vm1, mipsShare1)); assertEquals(0, vmScheduler.getAvailableMips(), 0); assertEquals(1000, vmScheduler.getTotalAllocatedMipsForVm(vm1), 0); assertTrue(vmScheduler.allocatePesForVm(vm2, mipsShare2)); assertEquals(0, vmScheduler.getAvailableMips(), 0); assertEquals(500, vmScheduler.getTotalAllocatedMipsForVm(vm1), 0); assertEquals(500, vmScheduler.getTotalAllocatedMipsForVm(vm2), 0); assertTrue(vmScheduler.allocatePesForVm(vm3, mipsShare3)); assertEquals(0, vmScheduler.getAvailableMips(), 0); assertEquals(333, vmScheduler.getTotalAllocatedMipsForVm(vm1), 0); assertEquals(333, vmScheduler.getTotalAllocatedMipsForVm(vm2), 0); assertEquals(333, vmScheduler.getTotalAllocatedMipsForVm(vm3), 0); vmScheduler.deallocatePesForAllVms(); assertEquals(1000, vmScheduler.getAvailableMips(), 0); assertEquals(1000, vmScheduler.getMaxAvailableMips(), 0); }