Commit 44d41b81 authored by Anton Beloglazov's avatar Anton Beloglazov

Fixing VmSchedulerTimeShared...

parent 5f7f205e
...@@ -78,30 +78,32 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -78,30 +78,32 @@ public class VmSchedulerTimeShared extends VmScheduler {
* @return true, if successful * @return true, if successful
*/ */
protected boolean allocatePesForVm(String vmUid, List<Double> mipsShareRequested) { protected boolean allocatePesForVm(String vmUid, List<Double> mipsShareRequested) {
getMipsMapRequested().put(vmUid, mipsShareRequested);
setPesInUse(getPesInUse() + mipsShareRequested.size());
double totalRequestedMips = 0; double totalRequestedMips = 0;
double peMips = getPeCapacity(); double peMips = getPeCapacity();
for (Double mips : mipsShareRequested) { for (Double mips : mipsShareRequested) {
if (mips > peMips) { // each virtual PE of a VM must require not more than the capacity // each virtual PE of a VM must require not more than the capacity of a physical PE
// of a physical PE if (mips > peMips) {
return false; return false;
} }
totalRequestedMips += mips; totalRequestedMips += mips;
} }
getMipsMapRequested().put(vmUid, mipsShareRequested);
setPesInUse(getPesInUse() + mipsShareRequested.size());
if (getVmsMigratingIn().contains(vmUid)) { if (getVmsMigratingIn().contains(vmUid)) {
totalRequestedMips *= 0.1; // performance cost incurred by the destination host = 10% // performance cost incurred by the destination host = 10% MIPS
// MIPS totalRequestedMips *= 0.1;
} }
List<Double> mipsShareAllocated = new ArrayList<Double>(); List<Double> mipsShareAllocated = new ArrayList<Double>();
for (Double mipsRequested : mipsShareRequested) { for (Double mipsRequested : mipsShareRequested) {
if (getVmsMigratingOut().contains(vmUid)) { if (getVmsMigratingOut().contains(vmUid)) {
mipsRequested *= 0.9; // performance degradation due to migration = 10% MIPS // performance degradation due to migration = 10% MIPS
mipsRequested *= 0.9;
} else if (getVmsMigratingIn().contains(vmUid)) { } else if (getVmsMigratingIn().contains(vmUid)) {
mipsRequested *= 0.1; // performance cost incurred by the destination host = 90% MIPS // performance cost incurred by the destination host = 10% MIPS
mipsRequested *= 0.1;
} }
mipsShareAllocated.add(mipsRequested); mipsShareAllocated.add(mipsRequested);
} }
...@@ -109,7 +111,7 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -109,7 +111,7 @@ public class VmSchedulerTimeShared extends VmScheduler {
if (getAvailableMips() >= totalRequestedMips) { if (getAvailableMips() >= totalRequestedMips) {
getMipsMap().put(vmUid, mipsShareAllocated); getMipsMap().put(vmUid, mipsShareAllocated);
setAvailableMips(getAvailableMips() - totalRequestedMips); setAvailableMips(getAvailableMips() - totalRequestedMips);
} else { } else {
updateShortage(); updateShortage();
} }
...@@ -121,68 +123,69 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -121,68 +123,69 @@ public class VmSchedulerTimeShared extends VmScheduler {
* compared to the amount requested by VMs. * compared to the amount requested by VMs.
*/ */
protected void updateShortage() { protected void updateShortage() {
//first, we have to know the wight of each VM // first, we have to know the weight of each VM in the allocation of mips. We want to keep
//in the allocation of mips. We want to keep // allocation proportional to it
//allocation proportional to it
HashMap<String, Double> weightMap = new HashMap<String, Double>();
HashMap<String,Double> weightMap = new HashMap<String,Double>();
double totalRequiredMips = 0.0; double totalRequiredMips = 0.0;
Iterator<Entry<String, List<Double>>> iter = mipsMapRequested.entrySet().iterator(); Iterator<Entry<String, List<Double>>> iter = mipsMapRequested.entrySet().iterator();
while (iter.hasNext()){ while (iter.hasNext()) {
Entry<String, List<Double>> entry = iter.next(); Entry<String, List<Double>> entry = iter.next();
//each element of the iterator is one entry of the table: (vmId, mipsShare) // each element of the iterator is one entry of the table: (vmId, mipsShare)
String vmId = entry.getKey(); String vmId = entry.getKey();
List<Double> shares = entry.getValue(); List<Double> shares = entry.getValue();
//count amount of mips required by the vm // count amount of mips required by the vm
double requiredMipsByThisVm = 0.0; double requiredMipsByThisVm = 0.0;
for(double share: shares){ for (double share : shares) {
totalRequiredMips+=share; totalRequiredMips += share;
requiredMipsByThisVm+=share; requiredMipsByThisVm += share;
} }
//store the value to use later to define weights // store the value to use later to define weights
weightMap.put(vmId, requiredMipsByThisVm); weightMap.put(vmId, requiredMipsByThisVm);
} }
//now, we have the information on individual weights // now, we have the information on individual weights
//use this information to define actual shares of // use this information to define actual shares of
//mips received by each VM // mips received by each VM
iter = mipsMapRequested.entrySet().iterator(); iter = mipsMapRequested.entrySet().iterator();
while (iter.hasNext()){ while (iter.hasNext()) {
Entry<String, List<Double>> entry = iter.next(); Entry<String, List<Double>> entry = iter.next();
//each element of the iterator is one entry of the table: (vmId, mipsShare) // each element of the iterator is one entry of the table: (vmId, mipsShare)
String vmId = entry.getKey(); String vmId = entry.getKey();
List<Double> shares = entry.getValue(); List<Double> shares = entry.getValue();
//get weight of this vm // get weight of this vm
double vmWeight = weightMap.get(vmId)/totalRequiredMips; double vmWeight = weightMap.get(vmId) / totalRequiredMips;
//update actual received share // update actual received share
LinkedList<Double> updatedSharesList = new LinkedList<Double>(); LinkedList<Double> updatedSharesList = new LinkedList<Double>();
double actuallyAllocatedMips = 0.0; double actuallyAllocatedMips = 0.0;
for(double share: shares){ for (double share : shares) {
double updatedShare = share*vmWeight; double updatedShare = share * vmWeight;
//update share if migrating // update share if migrating
if (getVmsMigratingOut().contains(vmId)) { if (getVmsMigratingOut().contains(vmId)) {
updatedShare *= 0.9; // performance degradation due to migration = 10% MIPS // performance degradation due to migration = 10% MIPS
updatedShare *= 0.9;
} else if (getVmsMigratingIn().contains(vmId)) { } else if (getVmsMigratingIn().contains(vmId)) {
updatedShare *= 0.1; // performance cost incurred by the destination host = 90% MIPS // performance cost incurred by the destination host = 10% MIPS
updatedShare *= 0.1;
} }
actuallyAllocatedMips+=updatedShare; actuallyAllocatedMips += updatedShare;
updatedSharesList.add(updatedShare); updatedSharesList.add(updatedShare);
} }
//add in the new map // add in the new map
getMipsMap().put(vmId, updatedSharesList); getMipsMap().put(vmId, updatedSharesList);
setAvailableMips(getAvailableMips() - actuallyAllocatedMips); setAvailableMips(getAvailableMips() - actuallyAllocatedMips);
} }
} }
/** /**
...@@ -202,7 +205,7 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -202,7 +205,7 @@ public class VmSchedulerTimeShared extends VmScheduler {
for (Map.Entry<String, List<Double>> entry : getMipsMap().entrySet()) { for (Map.Entry<String, List<Double>> entry : getMipsMap().entrySet()) {
String vmUid = entry.getKey(); String vmUid = entry.getKey();
getPeMap().put(vmUid, new LinkedList<Pe>()); getPeMap().put(vmUid, new LinkedList<Pe>());
for (double mips : entry.getValue()) { for (double mips : entry.getValue()) {
while (mips >= 0.1) { while (mips >= 0.1) {
if (availableMips >= mips) { if (availableMips >= mips) {
......
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