Commit b463216f authored by rodrigo.calheiros's avatar rodrigo.calheiros

Updates in documentation and tests.

parent d2495835
...@@ -8,11 +8,12 @@ ...@@ -8,11 +8,12 @@
package org.cloudbus.cloudsim; package org.cloudbus.cloudsim;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.cloudbus.cloudsim.lists.PeList; import org.cloudbus.cloudsim.lists.PeList;
import org.cloudbus.cloudsim.util.MathUtil;
/** /**
* This is a Time-Shared VM Scheduler, which allows over-subscription. In other words, the scheduler * This is a Time-Shared VM Scheduler, which allows over-subscription. In other words, the scheduler
...@@ -47,9 +48,20 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared ...@@ -47,9 +48,20 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared
@Override @Override
protected boolean allocatePesForVm(String vmUid, List<Double> mipsShareRequested) { protected boolean allocatePesForVm(String vmUid, List<Double> mipsShareRequested) {
double totalRequestedMips = 0; double totalRequestedMips = 0;
//if the requested mips is bigger than the capacity of a single PE, we cap
//the request to the PE's capacity
List<Double> mipsShareRequestedCapped = new ArrayList<Double>();
double peMips = getPeCapacity();
for (Double mips : mipsShareRequested) { for (Double mips : mipsShareRequested) {
if (mips > peMips) {
mipsShareRequestedCapped.add(peMips);
totalRequestedMips += peMips;
} else {
mipsShareRequestedCapped.add(mips);
totalRequestedMips += mips; totalRequestedMips += mips;
} }
}
getMipsMapRequested().put(vmUid, mipsShareRequested); getMipsMapRequested().put(vmUid, mipsShareRequested);
setPesInUse(getPesInUse() + mipsShareRequested.size()); setPesInUse(getPesInUse() + mipsShareRequested.size());
...@@ -61,7 +73,7 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared ...@@ -61,7 +73,7 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared
if (getAvailableMips() >= totalRequestedMips) { if (getAvailableMips() >= totalRequestedMips) {
List<Double> mipsShareAllocated = new ArrayList<Double>(); List<Double> mipsShareAllocated = new ArrayList<Double>();
for (Double mipsRequested : mipsShareRequested) { for (Double mipsRequested : mipsShareRequestedCapped) {
if (getVmsMigratingOut().contains(vmUid)) { if (getVmsMigratingOut().contains(vmUid)) {
// performance degradation due to migration = 10% MIPS // performance degradation due to migration = 10% MIPS
mipsRequested *= 0.9; mipsRequested *= 0.9;
...@@ -90,8 +102,26 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared ...@@ -90,8 +102,26 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared
// proportionally // proportionally
double totalRequiredMipsByAllVms = 0; double totalRequiredMipsByAllVms = 0;
Map<String,List<Double>> mipsMapCapped = new HashMap<String,List<Double>>();
for (Entry<String, List<Double>> entry : getMipsMapRequested().entrySet()) { for (Entry<String, List<Double>> entry : getMipsMapRequested().entrySet()) {
double requiredMipsByThisVm = MathUtil.sum(entry.getValue());
double requiredMipsByThisVm = 0.0;
String vmId = entry.getKey();
List<Double> mipsShareRequested = entry.getValue();
List<Double> mipsShareRequestedCapped = new ArrayList<Double>();
double peMips = getPeCapacity();
for (Double mips : mipsShareRequested) {
if (mips > peMips) {
mipsShareRequestedCapped.add(peMips);
requiredMipsByThisVm += peMips;
} else {
mipsShareRequestedCapped.add(mips);
requiredMipsByThisVm += mips;
}
}
mipsMapCapped.put(vmId, mipsShareRequestedCapped);
if (getVmsMigratingIn().contains(entry.getKey())) { if (getVmsMigratingIn().contains(entry.getKey())) {
// the destination host only experience 10% of the migrating VM's MIPS // the destination host only experience 10% of the migrating VM's MIPS
requiredMipsByThisVm *= 0.1; requiredMipsByThisVm *= 0.1;
...@@ -106,7 +136,7 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared ...@@ -106,7 +136,7 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared
getMipsMap().clear(); getMipsMap().clear();
// Update the actual MIPS allocated to the VMs // Update the actual MIPS allocated to the VMs
for (Entry<String, List<Double>> entry : getMipsMapRequested().entrySet()) { for (Entry<String, List<Double>> entry : mipsMapCapped.entrySet()) {
String vmUid = entry.getKey(); String vmUid = entry.getKey();
List<Double> requestedMips = entry.getValue(); List<Double> requestedMips = entry.getValue();
...@@ -138,11 +168,11 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared ...@@ -138,11 +168,11 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared
setAvailableMips(0); setAvailableMips(0);
} }
/** // /**
* Update allocation of VMs on PEs. // * Update allocation of VMs on PEs.
*/ // */
@Override // @Override
protected void updatePeProvisioning() { // protected void updatePeProvisioning() {
// getPeMap().clear(); // getPeMap().clear();
// for (Pe pe : getPeList()) { // for (Pe pe : getPeList()) {
// pe.getPeProvisioner().deallocateMipsForAllVms(); // pe.getPeProvisioner().deallocateMipsForAllVms();
...@@ -182,6 +212,6 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared ...@@ -182,6 +212,6 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared
// } // }
// } // }
// } // }
} // }
} }
...@@ -203,4 +203,43 @@ public class VmSchedulerTimeSharedOverSubscriptionTest { ...@@ -203,4 +203,43 @@ public class VmSchedulerTimeSharedOverSubscriptionTest {
assertEquals(3500, vmScheduler.getMaxAvailableMips(), 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);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment