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

Updates in documentation and tests.

parent d2495835
......@@ -8,11 +8,12 @@
package org.cloudbus.cloudsim;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
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
......@@ -47,8 +48,19 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared
@Override
protected boolean allocatePesForVm(String vmUid, List<Double> mipsShareRequested) {
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) {
totalRequestedMips += mips;
if (mips > peMips) {
mipsShareRequestedCapped.add(peMips);
totalRequestedMips += peMips;
} else {
mipsShareRequestedCapped.add(mips);
totalRequestedMips += mips;
}
}
getMipsMapRequested().put(vmUid, mipsShareRequested);
......@@ -61,7 +73,7 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared
if (getAvailableMips() >= totalRequestedMips) {
List<Double> mipsShareAllocated = new ArrayList<Double>();
for (Double mipsRequested : mipsShareRequested) {
for (Double mipsRequested : mipsShareRequestedCapped) {
if (getVmsMigratingOut().contains(vmUid)) {
// performance degradation due to migration = 10% MIPS
mipsRequested *= 0.9;
......@@ -89,9 +101,27 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared
// First, we calculate the scaling factor - the MIPS allocation for all VMs will be scaled
// proportionally
double totalRequiredMipsByAllVms = 0;
Map<String,List<Double>> mipsMapCapped = new HashMap<String,List<Double>>();
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())) {
// the destination host only experience 10% of the migrating VM's MIPS
requiredMipsByThisVm *= 0.1;
......@@ -106,7 +136,7 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared
getMipsMap().clear();
// 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();
List<Double> requestedMips = entry.getValue();
......@@ -138,11 +168,11 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared
setAvailableMips(0);
}
/**
* Update allocation of VMs on PEs.
*/
@Override
protected void updatePeProvisioning() {
// /**
// * Update allocation of VMs on PEs.
// */
// @Override
// protected void updatePeProvisioning() {
// getPeMap().clear();
// for (Pe pe : getPeList()) {
// pe.getPeProvisioner().deallocateMipsForAllVms();
......@@ -182,6 +212,6 @@ public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared
// }
// }
// }
}
// }
}
......@@ -202,5 +202,44 @@ public class VmSchedulerTimeSharedOverSubscriptionTest {
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);
}
}
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