Commit c20c6acf authored by Anton Beloglazov's avatar Anton Beloglazov

- Refactoring, fixes, cleaning

- New VmScheduler: time-shared scheduling supporting over-subscription
parent 84fec2db
...@@ -541,7 +541,8 @@ public class Datacenter extends SimEntity { ...@@ -541,7 +541,8 @@ public class Datacenter extends SimEntity {
host.removeMigratingInVm(vm); host.removeMigratingInVm(vm);
boolean result = getVmAllocationPolicy().allocateHostForVm(vm, host); boolean result = getVmAllocationPolicy().allocateHostForVm(vm, host);
if (!result) { if (!result) {
Log.printLine("Allocation failed"); Log.printLine("[Datacenter.processVmMigrate] VM allocation to the destination host failed");
System.exit(0);
} }
if (ack) { if (ack) {
......
...@@ -170,13 +170,12 @@ public class DatacenterCharacteristics { ...@@ -170,13 +170,12 @@ public class DatacenterCharacteristics {
* @pre $none * @pre $none
* @post $result >= -1 * @post $result >= -1
*/ */
@SuppressWarnings("unchecked") public int getMipsOfOnePe() {
public int getMipsOfOnePe() {
if (getHostList().size() == 0) { if (getHostList().size() == 0) {
return -1; return -1;
} }
return PeList.getMips((List<Pe>) getHostList().get(0).getPeList(), 0); return PeList.getMips(getHostList().get(0).getPeList(), 0);
} }
/** /**
...@@ -192,13 +191,12 @@ public class DatacenterCharacteristics { ...@@ -192,13 +191,12 @@ public class DatacenterCharacteristics {
* @pre peID >= 0 * @pre peID >= 0
* @post $result >= -1 * @post $result >= -1
*/ */
@SuppressWarnings("unchecked") public int getMipsOfOnePe(int id, int peId) {
public int getMipsOfOnePe(int id, int peId) {
if (getHostList().size() == 0) { if (getHostList().size() == 0) {
return -1; return -1;
} }
return PeList.getMips((List<Pe>) HostList.getById(getHostList(), id).getPeList(), peId); return PeList.getMips(HostList.getById(getHostList(), id).getPeList(), peId);
} }
/** /**
......
...@@ -11,13 +11,13 @@ package org.cloudbus.cloudsim; ...@@ -11,13 +11,13 @@ package org.cloudbus.cloudsim;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.lists.PeList; import org.cloudbus.cloudsim.lists.PeList;
import org.cloudbus.cloudsim.provisioners.BwProvisioner; import org.cloudbus.cloudsim.provisioners.BwProvisioner;
import org.cloudbus.cloudsim.provisioners.RamProvisioner; import org.cloudbus.cloudsim.provisioners.RamProvisioner;
/** /**
* Host class extends a Machine to include other hostList beside PEs * Host executes actions related
* to support simulation of virtualized grids. It executes actions related
* to management of virtual machines (e.g., creation and destruction). A host has * to management of virtual machines (e.g., creation and destruction). A host has
* a defined policy for provisioning memory and bw, as well as an allocation policy * a defined policy for provisioning memory and bw, as well as an allocation policy
* for Pe's to virtual machines. * for Pe's to virtual machines.
...@@ -57,16 +57,16 @@ public class Host { ...@@ -57,16 +57,16 @@ public class Host {
/** The vms migrating in. */ /** The vms migrating in. */
private List<Vm> vmsMigratingIn; private List<Vm> vmsMigratingIn;
/** THe datacenter where the host is placed */ /** The datacenter where the host is placed. */
private Datacenter datacenter; private Datacenter datacenter;
/** /**
* Instantiates a new host. * Instantiates a new host.
* *
* @param id the id * @param id the id
* @param storage the storage
* @param ramProvisioner the ram provisioner * @param ramProvisioner the ram provisioner
* @param bwProvisioner the bw provisioner * @param bwProvisioner the bw provisioner
* @param storage the storage
* @param peList the pe list * @param peList the pe list
* @param vmScheduler the vm scheduler * @param vmScheduler the vm scheduler
*/ */
...@@ -102,9 +102,6 @@ public class Host { ...@@ -102,9 +102,6 @@ public class Host {
double smallerTime = Double.MAX_VALUE; double smallerTime = Double.MAX_VALUE;
for (Vm vm : getVmList()) { for (Vm vm : getVmList()) {
// if (vm.isInMigration()) {
// continue;
// }
double time = vm.updateVmProcessing(currentTime, getVmScheduler().getAllocatedMipsForVm(vm)); double time = vm.updateVmProcessing(currentTime, getVmScheduler().getAllocatedMipsForVm(vm));
if (time > 0.0 && time < smallerTime) { if (time > 0.0 && time < smallerTime) {
smallerTime = time; smallerTime = time;
...@@ -114,24 +111,73 @@ public class Host { ...@@ -114,24 +111,73 @@ public class Host {
return smallerTime; return smallerTime;
} }
/**
* Adds the migrating in vm.
*
* @param vm the vm
*/
public void addMigratingInVm(Vm vm) { public void addMigratingInVm(Vm vm) {
vm.setInMigration(true);
if (!getVmsMigratingIn().contains(vm)) { if (!getVmsMigratingIn().contains(vm)) {
getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam()); if (getStorage() < vm.getSize()){
getBwProvisioner().allocateBwForVm(vm, vm.getCurrentRequestedBw()); Log.printLine("[VmScheduler.addMigratingInVm] Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by storage");
System.exit(0);
}
if (!getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam())) {
Log.printLine("[VmScheduler.addMigratingInVm] Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by RAM");
System.exit(0);
}
if (!getBwProvisioner().allocateBwForVm(vm, vm.getCurrentRequestedBw())) {
Log.printLine("[VmScheduler.addMigratingInVm] Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by BW");
System.exit(0);
}
getVmScheduler().getVmsMigratingIn().add(vm.getUid());
if (!getVmScheduler().allocatePesForVm(vm, vm.getCurrentRequestedMips())) {
Log.printLine("[VmScheduler.addMigratingInVm] Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by MIPS");
System.exit(0);
}
setStorage(getStorage() - vm.getSize());
getVmsMigratingIn().add(vm); getVmsMigratingIn().add(vm);
getVmList().add(vm);
updateVmsProcessing(CloudSim.clock());
vm.getHost().updateVmsProcessing(CloudSim.clock());
} }
} }
/**
* Removes the migrating in vm.
*
* @param vm the vm
*/
public void removeMigratingInVm(Vm vm) { public void removeMigratingInVm(Vm vm) {
getRamProvisioner().deallocateRamForVm(vm); vmDeallocate(vm);
getBwProvisioner().deallocateBwForVm(vm);
getVmsMigratingIn().remove(vm); getVmsMigratingIn().remove(vm);
getVmList().remove(vm);
getVmScheduler().getVmsMigratingIn().remove(vm.getUid());
vm.setInMigration(false);
} }
public void reallocateMigratingVms() { /**
* Reallocate migrating in vms.
*/
public void reallocateMigratingInVms() {
for (Vm vm : getVmsMigratingIn()) { for (Vm vm : getVmsMigratingIn()) {
if (!getVmList().contains(vm)) {
getVmList().add(vm);
}
if (!getVmScheduler().getVmsMigratingIn().contains(vm.getUid())) {
getVmScheduler().getVmsMigratingIn().add(vm.getUid());
}
getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam()); getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam());
getBwProvisioner().allocateBwForVm(vm, vm.getCurrentRequestedBw()); getBwProvisioner().allocateBwForVm(vm, vm.getCurrentRequestedBw());
getVmScheduler().allocatePesForVm(vm, vm.getCurrentRequestedMips());
setStorage(getStorage() - vm.getSize());
} }
} }
...@@ -159,18 +205,18 @@ public class Host { ...@@ -159,18 +205,18 @@ public class Host {
* @post $none * @post $none
*/ */
public boolean vmCreate(Vm vm) { public boolean vmCreate(Vm vm) {
if (storage<vm.getSize()){ if (getStorage() < vm.getSize()){
Log.printLine("Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by storage"); Log.printLine("[VmScheduler.vmCreate] Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by storage");
return false; return false;
} }
if (!getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam())) { if (!getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam())) {
Log.printLine("Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by RAM"); Log.printLine("[VmScheduler.vmCreate] Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by RAM");
return false; return false;
} }
if (!getBwProvisioner().allocateBwForVm(vm, vm.getCurrentRequestedBw())) { if (!getBwProvisioner().allocateBwForVm(vm, vm.getCurrentRequestedBw())) {
Log.printLine("Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by BW"); Log.printLine("[VmScheduler.vmCreate] Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by BW");
getRamProvisioner().deallocateRamForVm(vm); getRamProvisioner().deallocateRamForVm(vm);
return false; return false;
} }
...@@ -182,7 +228,7 @@ public class Host { ...@@ -182,7 +228,7 @@ public class Host {
return false; return false;
} }
storage-=vm.getSize(); setStorage(getStorage() - vm.getSize());
getVmList().add(vm); getVmList().add(vm);
vm.setHost(this); vm.setHost(this);
return true; return true;
...@@ -201,7 +247,6 @@ public class Host { ...@@ -201,7 +247,6 @@ public class Host {
vmDeallocate(vm); vmDeallocate(vm);
getVmList().remove(vm); getVmList().remove(vm);
vm.setHost(null); vm.setHost(null);
storage+=vm.getSize();
} }
} }
...@@ -215,7 +260,7 @@ public class Host { ...@@ -215,7 +260,7 @@ public class Host {
vmDeallocateAll(); vmDeallocateAll();
for (Vm vm : getVmList()) { for (Vm vm : getVmList()) {
vm.setHost(null); vm.setHost(null);
storage+=vm.getSize(); setStorage(getStorage() + vm.getSize());
} }
getVmList().clear(); getVmList().clear();
} }
...@@ -229,12 +274,12 @@ public class Host { ...@@ -229,12 +274,12 @@ public class Host {
getRamProvisioner().deallocateRamForVm(vm); getRamProvisioner().deallocateRamForVm(vm);
getBwProvisioner().deallocateBwForVm(vm); getBwProvisioner().deallocateBwForVm(vm);
getVmScheduler().deallocatePesForVm(vm); getVmScheduler().deallocatePesForVm(vm);
setStorage(getStorage() + vm.getSize());
} }
/** /**
* Deallocate all hostList for the VM. * Deallocate all hostList for the VM.
* *
* @param vm the VM
*/ */
protected void vmDeallocateAll() { protected void vmDeallocateAll() {
getRamProvisioner().deallocateRamForAllVms(); getRamProvisioner().deallocateRamForAllVms();
...@@ -276,7 +321,6 @@ public class Host { ...@@ -276,7 +321,6 @@ public class Host {
* *
* @return the free pes number * @return the free pes number
*/ */
@SuppressWarnings("unchecked")
public int getFreePesNumber() { public int getFreePesNumber() {
return PeList.getFreePesNumber((List<Pe>) getPeList()); return PeList.getFreePesNumber((List<Pe>) getPeList());
} }
...@@ -286,7 +330,6 @@ public class Host { ...@@ -286,7 +330,6 @@ public class Host {
* *
* @return the total mips * @return the total mips
*/ */
@SuppressWarnings("unchecked")
public int getTotalMips() { public int getTotalMips() {
return PeList.getTotalMips((List<Pe>) getPeList()); return PeList.getTotalMips((List<Pe>) getPeList());
} }
...@@ -468,28 +511,32 @@ public class Host { ...@@ -468,28 +511,32 @@ public class Host {
protected void setVmScheduler(VmScheduler vmScheduler) { protected void setVmScheduler(VmScheduler vmScheduler) {
this.vmScheduler = vmScheduler; this.vmScheduler = vmScheduler;
} }
/** /**
* Gets the pe list. * Gets the pe list.
* *
* @param <T> the generic type
* @return the pe list * @return the pe list
*/ */
public List<? extends Pe> getPeList() { @SuppressWarnings("unchecked")
return this.peList; public <T extends Pe> List<T> getPeList() {
return (List<T>) peList;
} }
/** /**
* Sets the pe list. * Sets the pe list.
* *
* @param <T> the generic type
* @param peList the new pe list * @param peList the new pe list
*/ */
protected void setPeList(List<? extends Pe> peList) { protected <T extends Pe> void setPeList(List<T> peList) {
this.peList = peList; this.peList = peList;
} }
/** /**
* Gets the vm list. * Gets the vm list.
* *
* @param <T> the generic type
* @return the vm list * @return the vm list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -500,6 +547,7 @@ public class Host { ...@@ -500,6 +547,7 @@ public class Host {
/** /**
* Sets the vm list. * Sets the vm list.
* *
* @param <T> the generic type
* @param vmList the new vm list * @param vmList the new vm list
*/ */
protected <T extends Vm> void setVmList(List<T> vmList) { protected <T extends Vm> void setVmList(List<T> vmList) {
...@@ -536,8 +584,7 @@ public class Host { ...@@ -536,8 +584,7 @@ public class Host {
* *
* @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @return <tt>true</tt> if successful, <tt>false</tt> otherwise
*/ */
@SuppressWarnings("unchecked") public boolean setFailed(String resName, boolean failed) {
public boolean setFailed(String resName, boolean failed) {
// all the PEs are failed (or recovered, depending on fail) // all the PEs are failed (or recovered, depending on fail)
this.failed = failed; this.failed = failed;
PeList.setStatusFailed((List<Pe>) getPeList(), resName, getId(), failed); PeList.setStatusFailed((List<Pe>) getPeList(), resName, getId(), failed);
...@@ -551,8 +598,7 @@ public class Host { ...@@ -551,8 +598,7 @@ public class Host {
* *
* @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @return <tt>true</tt> if successful, <tt>false</tt> otherwise
*/ */
@SuppressWarnings("unchecked") public boolean setFailed(boolean failed) {
public boolean setFailed(boolean failed) {
// all the PEs are failed (or recovered, depending on fail) // all the PEs are failed (or recovered, depending on fail)
this.failed = failed; this.failed = failed;
PeList.setStatusFailed((List<Pe>) getPeList(), failed); PeList.setStatusFailed((List<Pe>) getPeList(), failed);
...@@ -562,17 +608,14 @@ public class Host { ...@@ -562,17 +608,14 @@ public class Host {
/** /**
* Sets the particular Pe status on this Machine. * Sets the particular Pe status on this Machine.
* *
* @param status Pe status, either <tt>Pe.FREE</tt> or <tt>Pe.BUSY</tt>
* @param peId the pe id * @param peId the pe id
* * @param status Pe status, either <tt>Pe.FREE</tt> or <tt>Pe.BUSY</tt>
* @return <tt>true</tt> if the Pe status has changed, <tt>false</tt> * @return <tt>true</tt> if the Pe status has changed, <tt>false</tt>
* otherwise (Pe id might not be exist) * otherwise (Pe id might not be exist)
*
* @pre peID >= 0 * @pre peID >= 0
* @post $none * @post $none
*/ */
@SuppressWarnings("unchecked") public boolean setPeStatus(int peId, int status) {
public boolean setPeStatus(int peId, int status) {
return PeList.setPeStatus((List<Pe>) getPeList(), peId, status); return PeList.setPeStatus((List<Pe>) getPeList(), peId, status);
} }
......
...@@ -10,6 +10,7 @@ package org.cloudbus.cloudsim; ...@@ -10,6 +10,7 @@ package org.cloudbus.cloudsim;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -61,7 +62,6 @@ public class HostDynamicWorkload extends Host { ...@@ -61,7 +62,6 @@ public class HostDynamicWorkload extends Host {
@Override @Override
public double updateVmsProcessing(double currentTime) { public double updateVmsProcessing(double currentTime) {
double smallerTime = super.updateVmsProcessing(currentTime); double smallerTime = super.updateVmsProcessing(currentTime);
setUtilizationMips(0); setUtilizationMips(0);
for (Vm vm : getVmList()) { for (Vm vm : getVmList()) {
...@@ -81,18 +81,22 @@ public class HostDynamicWorkload extends Host { ...@@ -81,18 +81,22 @@ public class HostDynamicWorkload extends Host {
} }
double totalAllocatedMips = getVmScheduler().getTotalAllocatedMipsForVm(vm); double totalAllocatedMips = getVmScheduler().getTotalAllocatedMipsForVm(vm);
if (totalAllocatedMips + 0.1 < totalRequestedMips) { Log.formatLine("%.2f: [Host #" + getId() + "] Total allocated MIPS for VM #" + vm.getId() + " (Host #" + vm.getHost().getId() + ") is %.2f, was requested %.2f out of total %.2f (%.2f%%)", CloudSim.clock(), totalAllocatedMips, totalRequestedMips, vm.getMips(), totalRequestedMips / vm.getMips() * 100);
Log.printLine("Under allocated MIPS for VM #" + vm.getId() + ": requested " + totalRequestedMips + ", allocated " + totalAllocatedMips);
} if (getVmsMigratingIn().contains(vm)) {
Log.formatLine("%.2f: [Host #" + getId() + "] VM #" + vm.getId() + " is being migrated to Host #" + getId(), CloudSim.clock());
updateUnderAllocatedMips(vm, totalRequestedMips, totalAllocatedMips); } else {
if (totalAllocatedMips + 0.1 < totalRequestedMips) {
Log.formatLine("%.2f: Total allocated MIPS for VM #" + vm.getId() + " (Host #" + vm.getHost().getId() + ") is %.2f, was requested %.2f out of total %.2f (%.2f%%)", CloudSim.clock(), totalAllocatedMips, totalRequestedMips, vm.getMips(), totalRequestedMips / vm.getMips() * 100); Log.formatLine("%.2f: [Host #" + getId() + "] Under allocated MIPS for VM #" + vm.getId() + ": %.2f", CloudSim.clock(), totalRequestedMips - totalAllocatedMips);
}
if (vm.isInMigration()) {
Log.printLine("VM #" + vm.getId() + " is in migration"); updateUnderAllocatedMips(vm, totalRequestedMips, totalAllocatedMips);
totalAllocatedMips /= 0.9; // performance degradation due to migration - 10%
if (vm.isInMigration()) {
Log.formatLine("%.2f: [Host #" + getId() + "] VM #" + vm.getId() + " is in migration", CloudSim.clock());
totalAllocatedMips /= 0.9; // performance degradation due to migration - 10%
}
} }
setUtilizationMips(getUtilizationMips() + totalAllocatedMips); setUtilizationMips(getUtilizationMips() + totalAllocatedMips);
...@@ -100,6 +104,20 @@ public class HostDynamicWorkload extends Host { ...@@ -100,6 +104,20 @@ public class HostDynamicWorkload extends Host {
return smallerTime; return smallerTime;
} }
// /**
// * Gets the mips for migrating in vm.
// *
// * @param vm the vm
// * @return the mips for migrating in vm
// */
// protected List<Double> getMipsForMigratingInVm(Vm vm) {
// List<Double> mipsForMigratingIn = new LinkedList<Double>();
// for (Double mips : vm.getCurrentRequestedMips()) {
// mipsForMigratingIn.add(mips * 0.1); // 10% of the requested MIPS
// }
// return mipsForMigratingIn;
// }
/** /**
* Gets the completed vms. * Gets the completed vms.
...@@ -124,7 +142,6 @@ public class HostDynamicWorkload extends Host { ...@@ -124,7 +142,6 @@ public class HostDynamicWorkload extends Host {
* *
* @return the utilization * @return the utilization
*/ */
@SuppressWarnings("unchecked")
public double getMaxUtilization() { public double getMaxUtilization() {
return PeList.getMaxUtilization((List<Pe>) getPeList()); return PeList.getMaxUtilization((List<Pe>) getPeList());
} }
...@@ -137,7 +154,6 @@ public class HostDynamicWorkload extends Host { ...@@ -137,7 +154,6 @@ public class HostDynamicWorkload extends Host {
* *
* @return the utilization * @return the utilization
*/ */
@SuppressWarnings("unchecked")
public double getMaxUtilizationAmongVmsPes(Vm vm) { public double getMaxUtilizationAmongVmsPes(Vm vm) {
return PeList.getMaxUtilizationAmongVmsPes((List<Pe>) getPeList(), vm); return PeList.getMaxUtilizationAmongVmsPes((List<Pe>) getPeList(), vm);
} }
......
...@@ -16,7 +16,6 @@ import java.util.HashMap; ...@@ -16,7 +16,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
// TODO: Auto-generated Javadoc
/** /**
* The UtilizationModelStochastic class implements a model, according to which * The UtilizationModelStochastic class implements a model, according to which
* a Cloudlet generates random CPU utilization every time frame. * a Cloudlet generates random CPU utilization every time frame.
...@@ -40,6 +39,11 @@ public class UtilizationModelStochastic implements UtilizationModel { ...@@ -40,6 +39,11 @@ public class UtilizationModelStochastic implements UtilizationModel {
setRandomGenerator(new Random()); setRandomGenerator(new Random());
} }
/**
* Instantiates a new utilization model stochastic.
*
* @param seed the seed
*/
public UtilizationModelStochastic(long seed) { public UtilizationModelStochastic(long seed) {
setHistory(new HashMap<Double, Double>()); setHistory(new HashMap<Double, Double>());
setRandomGenerator(new Random(seed)); setRandomGenerator(new Random(seed));
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
package org.cloudbus.cloudsim; package org.cloudbus.cloudsim;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -33,6 +34,12 @@ public abstract class VmScheduler { ...@@ -33,6 +34,12 @@ public abstract class VmScheduler {
/** The total available mips. */ /** The total available mips. */
private double availableMips; private double availableMips;
/** The VMs migrating in. */
private List<String> vmsMigratingIn;
/** The VMs migrating out. */
private List<String> vmsMigratingOut;
/** /**
* Creates a new HostAllocationPolicy. * Creates a new HostAllocationPolicy.
...@@ -46,6 +53,8 @@ public abstract class VmScheduler { ...@@ -46,6 +53,8 @@ public abstract class VmScheduler {
setPeList(pelist); setPeList(pelist);
setMipsMap(new HashMap<String, List<Double>>()); setMipsMap(new HashMap<String, List<Double>>());
setAvailableMips(PeList.getTotalMips(getPeList())); setAvailableMips(PeList.getTotalMips(getPeList()));
setVmsMigratingIn(new ArrayList<String>());
setVmsMigratingOut(new ArrayList<String>());
} }
/** /**
...@@ -209,4 +218,40 @@ public abstract class VmScheduler { ...@@ -209,4 +218,40 @@ public abstract class VmScheduler {
this.availableMips = availableMips; this.availableMips = availableMips;
} }
/**
* Gets the vms in migration.
*
* @return the vms in migration
*/
public List<String> getVmsMigratingOut() {
return vmsMigratingOut;
}
/**
* Sets the vms in migration.
*
* @param vmsInMigration the new vms migrating out
*/
protected void setVmsMigratingOut(List<String> vmsInMigration) {
this.vmsMigratingOut = vmsInMigration;
}
/**
* Gets the vms migrating in.
*
* @return the vms migrating in
*/
public List<String> getVmsMigratingIn() {
return vmsMigratingIn;
}
/**
* Sets the vms migrating in.
*
* @param vmsMigratingIn the new vms migrating in
*/
protected void setVmsMigratingIn(List<String> vmsMigratingIn) {
this.vmsMigratingIn = vmsMigratingIn;
}
} }
...@@ -13,10 +13,12 @@ import java.util.HashMap; ...@@ -13,10 +13,12 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import org.cloudbus.cloudsim.lists.PeList; import org.cloudbus.cloudsim.lists.PeList;
import org.cloudbus.cloudsim.provisioners.PeProvisioner; import org.cloudbus.cloudsim.provisioners.PeProvisioner;
// TODO: Auto-generated Javadoc
/** /**
* VmSchedulerTimeShared is a VMM allocation policy that * VmSchedulerTimeShared is a VMM allocation policy that
* allocates one or more Pe to a VM, and allows sharing * allocates one or more Pe to a VM, and allows sharing
...@@ -35,9 +37,6 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -35,9 +37,6 @@ public class VmSchedulerTimeShared extends VmScheduler {
/** The pes in use. */ /** The pes in use. */
private int pesInUse; private int pesInUse;
/** The vms in migration. */
private List<String> vmsMigratingOut;
/** /**
* Instantiates a new vm scheduler time shared. * Instantiates a new vm scheduler time shared.
* *
...@@ -46,7 +45,6 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -46,7 +45,6 @@ public class VmSchedulerTimeShared extends VmScheduler {
public VmSchedulerTimeShared(List<? extends Pe> pelist) { public VmSchedulerTimeShared(List<? extends Pe> pelist) {
super(pelist); super(pelist);
setMipsMapRequested(new HashMap<String, List<Double>>()); setMipsMapRequested(new HashMap<String, List<Double>>());
setVmsInMigration(new ArrayList<String>());
} }
/* (non-Javadoc) /* (non-Javadoc)
...@@ -54,16 +52,19 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -54,16 +52,19 @@ public class VmSchedulerTimeShared extends VmScheduler {
*/ */
@Override @Override
public boolean allocatePesForVm(Vm vm, List<Double> mipsShareRequested) { public boolean allocatePesForVm(Vm vm, List<Double> mipsShareRequested) {
if (getVmsMigratingIn().contains(vm.getUid()) && getVmsMigratingOut().contains(vm.getUid())) {
Log.print("found\n");
}
/** /**
* TODO: add the same to RAM and BW provisioners * TODO: add the same to RAM and BW provisioners
*/ */
if (vm.isInMigration()) { if (vm.isInMigration()) {
if (!getVmsInMigration().contains(vm.getUid())) { if (!getVmsMigratingIn().contains(vm.getUid()) && !getVmsMigratingOut().contains(vm.getUid())) {
getVmsInMigration().add(vm.getUid()); getVmsMigratingOut().add(vm.getUid());
} }
} else { } else {
if (getVmsInMigration().contains(vm.getUid())) { if (getVmsMigratingOut().contains(vm.getUid())) {
getVmsInMigration().remove(vm.getUid()); getVmsMigratingOut().remove(vm.getUid());
} }
} }
boolean result = allocatePesForVm(vm.getUid(), mipsShareRequested); boolean result = allocatePesForVm(vm.getUid(), mipsShareRequested);
...@@ -91,11 +92,17 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -91,11 +92,17 @@ public class VmSchedulerTimeShared extends VmScheduler {
} }
totalRequestedMips += mips; totalRequestedMips += mips;
} }
if (getVmsMigratingIn().contains(vmUid)) {
totalRequestedMips *= 0.1; // performance cost incurred by the destination host = 10% MIPS
}
List<Double> mipsShareAllocated = new ArrayList<Double>(); List<Double> mipsShareAllocated = new ArrayList<Double>();
for (Double mipsRequested : mipsShareRequested) { for (Double mipsRequested : mipsShareRequested) {
if (getVmsInMigration().contains(vmUid)) { if (getVmsMigratingOut().contains(vmUid)) {
mipsRequested *= 0.9; // performance degradation due to migration = 10% MIPS mipsRequested *= 0.9; // performance degradation due to migration = 10% MIPS
} else if (getVmsMigratingIn().contains(vmUid)) {
mipsRequested *= 0.1; // performance cost incurred by the destination host = 10% MIPS
} }
mipsShareAllocated.add(mipsRequested); mipsShareAllocated.add(mipsRequested);
} }
...@@ -122,7 +129,11 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -122,7 +129,11 @@ public class VmSchedulerTimeShared extends VmScheduler {
double additionalShortage = 0; double additionalShortage = 0;
do { do {
additionalShortage = 0; additionalShortage = 0;
for (List<Double> mipsMap : getMipsMap().values()) { for (Entry<String, List<Double>> entry : getMipsMap().entrySet()) {
if (getVmsMigratingIn().contains(entry.getKey())) {
continue;
}
List<Double> mipsMap = entry.getValue();
for (int i = 0; i < mipsMap.size(); i++) { for (int i = 0; i < mipsMap.size(); i++) {
if (mipsMap.get(i) == 0) { if (mipsMap.get(i) == 0) {
continue; continue;
...@@ -205,8 +216,6 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -205,8 +216,6 @@ public class VmSchedulerTimeShared extends VmScheduler {
/** /**
* Releases PEs allocated to all the VMs. * Releases PEs allocated to all the VMs.
* *
* @param vm the vm
*
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
...@@ -265,22 +274,4 @@ public class VmSchedulerTimeShared extends VmScheduler { ...@@ -265,22 +274,4 @@ public class VmSchedulerTimeShared extends VmScheduler {
this.mipsMapRequested = mipsMapRequested; this.mipsMapRequested = mipsMapRequested;
} }
/**
* Gets the vms in migration.
*
* @return the vms in migration
*/
protected List<String> getVmsInMigration() {
return vmsMigratingOut;
}
/**
* Sets the vms in migration.
*
* @param vmsMigratingOut the new vms in migration
*/
protected void setVmsInMigration(List<String> vmsInMigration) {
this.vmsMigratingOut = vmsInMigration;
}
} }
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2010, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
/**
* The Class VmSchedulerTimeSharedOverSubscription.
*/
public class VmSchedulerTimeSharedOverSubscription extends VmSchedulerTimeShared {
/**
* Instantiates a new vm scheduler time shared over subscription.
*
* @param pelist the pelist
*/
public VmSchedulerTimeSharedOverSubscription(List<? extends Pe> pelist) {
super(pelist);
}
/**
* Allocate pes for vm. The policy allow over-subscription. In other words,
* the policy still allows the allocation of VMs that require more CPU capacity
* that is available. Oversubscription results in performance degradation. Each
* virtual PE cannot be allocated more CPU capacity than MIPS of a single PE.
*
* @param vmUid the vm uid
* @param mipsShareRequested the mips share requested
*
* @return true, if successful
*/
protected boolean allocatePesForVm(String vmUid, List<Double> mipsShareRequested) {
getMipsMapRequested().put(vmUid, mipsShareRequested);
setPesInUse(getPesInUse() + mipsShareRequested.size());
double totalRequestedMips = 0;
for (Double mips : mipsShareRequested) {
totalRequestedMips += mips;
}
if (getVmsMigratingIn().contains(vmUid)) {
totalRequestedMips *= 0.1; // performance cost incurred by the destination host = 10% MIPS
}
double peMips = getPeCapacity();
List<Double> mipsShareAllocated = new ArrayList<Double>();
for (Double mipsRequested : mipsShareRequested) {
if (mipsRequested > peMips) {
mipsRequested = peMips; // Over-subscription is implemented by the cost of performance degradation
}
if (getVmsMigratingOut().contains(vmUid)) {
mipsRequested *= 0.9; // performance degradation due to migration = 10% MIPS
} else if (getVmsMigratingIn().contains(vmUid)) {
mipsRequested *= 0.1; // performance cost incurred by the destination host = 10% MIPS
}
mipsShareAllocated.add(mipsRequested);
}
if (getAvailableMips() >= totalRequestedMips) {
getMipsMap().put(vmUid, mipsShareAllocated);
setAvailableMips(getAvailableMips() - totalRequestedMips);
} else {
int pesSkipped = 0;
for (Entry<String, List<Double>> entry : getMipsMap().entrySet()) {
List<Double> mipsMap = entry.getValue();
if (getVmsMigratingIn().contains(entry.getKey())) {
pesSkipped += mipsMap.size();
continue;
}
for (int i = 0; i < mipsMap.size(); i++) {
if (mipsMap.get(i) == 0) {
pesSkipped++;
}
}
}
if (getVmsMigratingIn().contains(vmUid)) {
pesSkipped += mipsShareRequested.size();
}
double shortage = (totalRequestedMips - getAvailableMips()) / (getPesInUse() - pesSkipped);
getMipsMap().put(vmUid, mipsShareAllocated);
setAvailableMips(0);
double additionalShortage = 0;
do {
additionalShortage = 0;
for (Entry<String, List<Double>> entry : getMipsMap().entrySet()) {
if (getVmsMigratingIn().contains(entry.getKey())) {
continue;
}
List<Double> mipsMap = entry.getValue();
for (int i = 0; i < mipsMap.size(); i++) {
if (mipsMap.get(i) == 0) {
continue;
}
if (mipsMap.get(i) >= shortage) {
mipsMap.set(i, mipsMap.get(i) - shortage);
} else {
additionalShortage += shortage - mipsMap.get(i);
mipsMap.set(i, 0.0);
}
if (mipsMap.get(i) == 0) {
pesSkipped++;
}
}
}
shortage = additionalShortage / (getPesInUse() - pesSkipped);
} while (additionalShortage > 0);
}
return true;
}
}
...@@ -11,8 +11,8 @@ package org.cloudbus.cloudsim.lists; ...@@ -11,8 +11,8 @@ package org.cloudbus.cloudsim.lists;
import java.util.List; import java.util.List;
import org.cloudbus.cloudsim.Host; import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Pe;
// TODO: Auto-generated Javadoc
/** /**
* HostList is a collection of operations on lists of hosts. * HostList is a collection of operations on lists of hosts.
* *
...@@ -24,11 +24,10 @@ public class HostList { ...@@ -24,11 +24,10 @@ public class HostList {
/** /**
* Gets the Machine object for a particular ID. * Gets the Machine object for a particular ID.
* *
* @param id the host ID * @param <T> the generic type
* @param hostList the host list * @param hostList the host list
* * @param id the host ID
* @return the Machine object or <tt>null</tt> if no machine exists * @return the Machine object or <tt>null</tt> if no machine exists
*
* @see gridsim.Machine * @see gridsim.Machine
* @pre id >= 0 * @pre id >= 0
* @post $none * @post $none
...@@ -45,10 +44,9 @@ public class HostList { ...@@ -45,10 +44,9 @@ public class HostList {
/** /**
* Gets the total number of PEs for all Machines. * Gets the total number of PEs for all Machines.
* *
* @param <T> the generic type
* @param hostList the host list * @param hostList the host list
*
* @return number of PEs * @return number of PEs
*
* @pre $none * @pre $none
* @post $result >= 0 * @post $result >= 0
*/ */
...@@ -63,18 +61,16 @@ public class HostList { ...@@ -63,18 +61,16 @@ public class HostList {
/** /**
* Gets the total number of <tt>FREE</tt> or non-busy PEs for all Machines. * Gets the total number of <tt>FREE</tt> or non-busy PEs for all Machines.
* *
* @param <T> the generic type
* @param hostList the host list * @param hostList the host list
*
* @return number of PEs * @return number of PEs
*
* @pre $none * @pre $none
* @post $result >= 0 * @post $result >= 0
*/ */
@SuppressWarnings("unchecked") public static <T extends Host> int getFreePesNumber(List<T> hostList) {
public static <T extends Host> int getFreePesNumber(List<T> hostList) {
int freePesNumber = 0; int freePesNumber = 0;
for (T host : hostList) { for (T host : hostList) {
freePesNumber += PeList.getFreePesNumber((List<Pe>) host.getPeList()); freePesNumber += PeList.getFreePesNumber(host.getPeList());
} }
return freePesNumber; return freePesNumber;
} }
...@@ -82,18 +78,16 @@ public class HostList { ...@@ -82,18 +78,16 @@ public class HostList {
/** /**
* Gets the total number of <tt>BUSY</tt> PEs for all Machines. * Gets the total number of <tt>BUSY</tt> PEs for all Machines.
* *
* @param <T> the generic type
* @param hostList the host list * @param hostList the host list
*
* @return number of PEs * @return number of PEs
*
* @pre $none * @pre $none
* @post $result >= 0 * @post $result >= 0
*/ */
@SuppressWarnings("unchecked") public static <T extends Host> int getBusyPesNumber(List<T> hostList) {
public static <T extends Host> int getBusyPesNumber(List<T> hostList) {
int busyPesNumber = 0; int busyPesNumber = 0;
for (T host : hostList) { for (T host : hostList) {
busyPesNumber += PeList.getBusyPesNumber((List<Pe>) host.getPeList()); busyPesNumber += PeList.getBusyPesNumber(host.getPeList());
} }
return busyPesNumber; return busyPesNumber;
} }
...@@ -101,10 +95,9 @@ public class HostList { ...@@ -101,10 +95,9 @@ public class HostList {
/** /**
* Gets a Machine with free Pe. * Gets a Machine with free Pe.
* *
* @param <T> the generic type
* @param hostList the host list * @param hostList the host list
*
* @return a machine object or <tt>null</tt> if not found * @return a machine object or <tt>null</tt> if not found
*
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
...@@ -115,18 +108,16 @@ public class HostList { ...@@ -115,18 +108,16 @@ public class HostList {
/** /**
* Gets a Machine with a specified number of free Pe. * Gets a Machine with a specified number of free Pe.
* *
* @param pesNumber the pes number * @param <T> the generic type
* @param hostList the host list * @param hostList the host list
* * @param pesNumber the pes number
* @return a machine object or <tt>null</tt> if not found * @return a machine object or <tt>null</tt> if not found
*
* @pre $none * @pre $none
* @post $none * @post $none
*/ */
@SuppressWarnings("unchecked") public static <T extends Host> T getHostWithFreePe(List<T> hostList, int pesNumber) {
public static <T extends Host> T getHostWithFreePe(List<T> hostList, int pesNumber) {
for (T host : hostList) { for (T host : hostList) {
if (PeList.getFreePesNumber((List<Pe>) host.getPeList()) >= pesNumber) { if (PeList.getFreePesNumber(host.getPeList()) >= pesNumber) {
return host; return host;
} }
} }
...@@ -136,14 +127,13 @@ public class HostList { ...@@ -136,14 +127,13 @@ public class HostList {
/** /**
* Sets the particular Pe status on a Machine. * Sets the particular Pe status on a Machine.
* *
* @param <T> the generic type
* @param hostList the host list
* @param status Pe status, either <tt>Pe.FREE</tt> or <tt>Pe.BUSY</tt> * @param status Pe status, either <tt>Pe.FREE</tt> or <tt>Pe.BUSY</tt>
* @param hostId the host id * @param hostId the host id
* @param peId the pe id * @param peId the pe id
* @param hostList the host list
*
* @return <tt>true</tt> if the Pe status has changed, <tt>false</tt> * @return <tt>true</tt> if the Pe status has changed, <tt>false</tt>
* otherwise (Machine id or Pe id might not be exist) * otherwise (Machine id or Pe id might not be exist)
*
* @pre machineID >= 0 * @pre machineID >= 0
* @pre peID >= 0 * @pre peID >= 0
* @post $none * @post $none
......
...@@ -87,62 +87,10 @@ public class PowerDatacenter extends Datacenter { ...@@ -87,62 +87,10 @@ public class PowerDatacenter extends Datacenter {
return; return;
} }
double currentTime = CloudSim.clock(); double currentTime = CloudSim.clock();
double timeframePower = 0.0;
// if some time passed since last processing // if some time passed since last processing
if (currentTime > getLastProcessTime()) { if (currentTime > getLastProcessTime()) {
double timeDiff = currentTime - getLastProcessTime(); double minTime = updateCloudetProcessingWithoutSchedulingFutureEvents();
double minTime = Double.MAX_VALUE;
Log.printLine("\n");
for (PowerHost host : this.<PowerHost>getHostList()) {
Log.formatLine("%.2f: Host #%d", CloudSim.clock(), host.getId());
double hostPower = 0.0;
if (host.getUtilizationOfCpu() > 0) {
try {
hostPower = host.getPower() * timeDiff;
timeframePower += hostPower;
} catch (Exception e) {
e.printStackTrace();
}
}
Log.formatLine("%.2f: Host #%d utilization is %.2f%%", CloudSim.clock(), host.getId(), host.getUtilizationOfCpu() * 100);
Log.formatLine("%.2f: Host #%d energy is %.2f W*sec", CloudSim.clock(), host.getId(), hostPower);
}
Log.formatLine("\n%.2f: Consumed energy is %.2f W*sec\n", CloudSim.clock(), timeframePower);
Log.printLine("\n\n--------------------------------------------------------------\n\n");
for (PowerHost host : this.<PowerHost>getHostList()) {
Log.formatLine("\n%.2f: Host #%d", CloudSim.clock(), host.getId());
double time = host.updateVmsProcessing(currentTime); // inform VMs to update processing
if (time < minTime) {
minTime = time;
}
Log.formatLine("%.2f: Host #%d utilization is %.2f%%", CloudSim.clock(), host.getId(), host.getUtilizationOfCpu() * 100);
}
setPower(getPower() + timeframePower);
checkCloudletCompletion();
/** Remove completed VMs **/
for (PowerHost host : this.<PowerHost>getHostList()) {
for (Vm vm : host.getCompletedVms()) {
getVmAllocationPolicy().deallocateHostForVm(vm);
getVmList().remove(vm);
Log.printLine("VM #" + vm.getId() + " has been deallocated from host #" + host.getId());
}
}
Log.printLine();
if (!isDisableMigrations()) { if (!isDisableMigrations()) {
List<Map<String, Object>> migrationMap = getVmAllocationPolicy().optimizeAllocation(getVmList()); List<Map<String, Object>> migrationMap = getVmAllocationPolicy().optimizeAllocation(getVmList());
...@@ -152,21 +100,20 @@ public class PowerDatacenter extends Datacenter { ...@@ -152,21 +100,20 @@ public class PowerDatacenter extends Datacenter {
Vm vm = (Vm) migrate.get("vm"); Vm vm = (Vm) migrate.get("vm");
PowerHost targetHost = (PowerHost) migrate.get("host"); PowerHost targetHost = (PowerHost) migrate.get("host");
PowerHost oldHost = (PowerHost) vm.getHost(); PowerHost oldHost = (PowerHost) vm.getHost();
targetHost.addMigratingInVm(vm);
if (oldHost == null) { if (oldHost == null) {
Log.formatLine("%.2f: Migration of VM #%d to Host #%d is started", CloudSim.clock(), vm.getId(), targetHost.getId()); Log.formatLine("%.2f: Migration of VM #%d to Host #%d is started", currentTime, vm.getId(), targetHost.getId());
} else { } else {
Log.formatLine("%.2f: Migration of VM #%d from Host #%d to Host #%d is started", CloudSim.clock(), vm.getId(), oldHost.getId(), targetHost.getId()); Log.formatLine("%.2f: Migration of VM #%d from Host #%d to Host #%d is started", currentTime, vm.getId(), oldHost.getId(), targetHost.getId());
} }
targetHost.addMigratingInVm(vm);
incrementMigrationCount(); incrementMigrationCount();
vm.setInMigration(true); /** VM migration delay = RAM / bandwidth **/
// we use BW / 2 to model BW available for migration purposes, the other half of BW is for VM communication
/** VM migration delay = RAM / bandwidth + C (C = 10 sec) **/ // around 16 seconds for 1024 MB using 1 Gbit/s network
send(getId(), vm.getRam() / ((double) vm.getBw() / 8000) + 0, CloudSimTags.VM_MIGRATE, migrate); send(getId(), vm.getCurrentAllocatedRam() / ((double) targetHost.getBw() / (2 * 8000)), CloudSimTags.VM_MIGRATE, migrate);
} }
} }
} }
...@@ -180,6 +127,83 @@ public class PowerDatacenter extends Datacenter { ...@@ -180,6 +127,83 @@ public class PowerDatacenter extends Datacenter {
setLastProcessTime(currentTime); setLastProcessTime(currentTime);
} }
} }
/**
* Update cloudet processing without scheduling future events.
*
* @return the double
*/
protected double updateCloudetProcessingWithoutSchedulingFutureEvents() {
double currentTime = CloudSim.clock();
double minTime = Double.MAX_VALUE;
double timeDiff = currentTime - getLastProcessTime();
double timeframePower = 0.0;
if (timeDiff > 0) {
Log.formatLine("\nEnergy consumption for the last time frame from %.2f to %.2f:", getLastProcessTime(), currentTime);
for (PowerHost host : this.<PowerHost>getHostList()) {
Log.printLine();
double hostPower = 0.0;
if (host.getUtilizationOfCpu() > 0) {
try {
hostPower = host.getPower() * timeDiff;
timeframePower += hostPower;
} catch (Exception e) {
e.printStackTrace();
}
}
Log.formatLine("%.2f: [Host #%d] utilization is %.2f%%", currentTime, host.getId(), host.getUtilizationOfCpu() * 100);
Log.formatLine("%.2f: [Host #%d] energy is %.2f W*sec", currentTime, host.getId(), hostPower);
}
Log.formatLine("\n%.2f: Consumed energy is %.2f W*sec\n", currentTime, timeframePower);
}
Log.printLine("\n\n--------------------------------------------------------------\n\n");
Log.printLine("New resource usage for the next time frame:");
for (PowerHost host : this.<PowerHost>getHostList()) {
Log.printLine();
double time = host.updateVmsProcessing(currentTime); // inform VMs to update processing
if (time < minTime) {
minTime = time;
}
Log.formatLine("%.2f: [Host #%d] utilization is %.2f%%", currentTime, host.getId(), host.getUtilizationOfCpu() * 100);
}
setPower(getPower() + timeframePower);
checkCloudletCompletion();
/** Remove completed VMs **/
for (PowerHost host : this.<PowerHost>getHostList()) {
for (Vm vm : host.getCompletedVms()) {
getVmAllocationPolicy().deallocateHostForVm(vm);
getVmList().remove(vm);
Log.printLine("VM #" + vm.getId() + " has been deallocated from host #" + host.getId());
}
}
Log.printLine();
setLastProcessTime(currentTime);
return minTime;
}
/* (non-Javadoc)
* @see org.cloudbus.cloudsim.Datacenter#processVmMigrate(org.cloudbus.cloudsim.core.SimEvent, boolean)
*/
@Override
protected void processVmMigrate(SimEvent ev, boolean ack) {
updateCloudetProcessingWithoutSchedulingFutureEvents();
super.processVmMigrate(ev, ack);
updateCloudetProcessingWithoutSchedulingFutureEvents();
}
/* (non-Javadoc) /* (non-Javadoc)
* @see cloudsim.Datacenter#processCloudletSubmit(cloudsim.core.SimEvent, boolean) * @see cloudsim.Datacenter#processCloudletSubmit(cloudsim.core.SimEvent, boolean)
......
...@@ -127,18 +127,15 @@ public class PowerDatacenterNonPowerAware extends PowerDatacenter { ...@@ -127,18 +127,15 @@ public class PowerDatacenterNonPowerAware extends PowerDatacenter {
PowerHost targetHost = (PowerHost) migrate.get("host"); PowerHost targetHost = (PowerHost) migrate.get("host");
PowerHost oldHost = (PowerHost) vm.getHost(); PowerHost oldHost = (PowerHost) vm.getHost();
targetHost.addMigratingInVm(vm);
if (oldHost == null) { if (oldHost == null) {
Log.formatLine("%.2f: Migration of VM #%d to Host #%d is started", CloudSim.clock(), vm.getId(), targetHost.getId()); Log.formatLine("%.2f: Migration of VM #%d to Host #%d is started", CloudSim.clock(), vm.getId(), targetHost.getId());
} else { } else {
Log.formatLine("%.2f: Migration of VM #%d from Host #%d to Host #%d is started", CloudSim.clock(), vm.getId(), oldHost.getId(), targetHost.getId()); Log.formatLine("%.2f: Migration of VM #%d from Host #%d to Host #%d is started", CloudSim.clock(), vm.getId(), oldHost.getId(), targetHost.getId());
} }
targetHost.addMigratingInVm(vm);
incrementMigrationCount(); incrementMigrationCount();
vm.setInMigration(true);
/** VM migration delay = RAM / bandwidth + C (C = 10 sec) **/ /** VM migration delay = RAM / bandwidth + C (C = 10 sec) **/
send(getId(), vm.getRam() / ((double) vm.getBw() / 8000) + 10, CloudSimTags.VM_MIGRATE, migrate); send(getId(), vm.getRam() / ((double) vm.getBw() / 8000) + 10, CloudSimTags.VM_MIGRATE, migrate);
} }
......
...@@ -29,10 +29,10 @@ public class PowerHost extends HostDynamicWorkload { ...@@ -29,10 +29,10 @@ public class PowerHost extends HostDynamicWorkload {
* Instantiates a new host. * Instantiates a new host.
* *
* @param id the id * @param id the id
* @param cpuProvisioner the cpu provisioner
* @param ramProvisioner the ram provisioner * @param ramProvisioner the ram provisioner
* @param bwProvisioner the bw provisioner * @param bwProvisioner the bw provisioner
* @param storage the storage * @param storage the storage
* @param peList the pe list
* @param vmScheduler the VM scheduler * @param vmScheduler the VM scheduler
*/ */
public PowerHost( public PowerHost(
...@@ -50,9 +50,8 @@ public class PowerHost extends HostDynamicWorkload { ...@@ -50,9 +50,8 @@ public class PowerHost extends HostDynamicWorkload {
* *
* @return the power * @return the power
*/ */
@SuppressWarnings("unchecked")
public double getPower() { public double getPower() {
return PowerPeList.getPower((List<PowerPe>) getPeList()); return PowerPeList.getPower(this.<PowerPe>getPeList());
} }
/** /**
...@@ -60,9 +59,8 @@ public class PowerHost extends HostDynamicWorkload { ...@@ -60,9 +59,8 @@ public class PowerHost extends HostDynamicWorkload {
* *
* @return the power * @return the power
*/ */
@SuppressWarnings("unchecked")
public double getMaxPower() { public double getMaxPower() {
return PowerPeList.getMaxPower((List<PowerPe>) getPeList()); return PowerPeList.getMaxPower(this.<PowerPe>getPeList());
} }
} }
...@@ -109,9 +109,7 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi ...@@ -109,9 +109,7 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi
PowerHost allocatedHost = findHostForVm(vm); PowerHost allocatedHost = findHostForVm(vm);
if (allocatedHost != null && allocatedHost.vmCreate(vm)) { //if vm has been succesfully created in the host if (allocatedHost != null && allocatedHost.vmCreate(vm)) { //if vm has been succesfully created in the host
getVmTable().put(vm.getUid(), allocatedHost); getVmTable().put(vm.getUid(), allocatedHost);
if (!Log.isDisabled()) { Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + allocatedHost.getId() + "\n", CloudSim.clock());
Log.print(String.format("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + allocatedHost.getId() + "\n", CloudSim.clock()));
}
return true; return true;
} }
return false; return false;
...@@ -164,7 +162,7 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi ...@@ -164,7 +162,7 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi
PowerVmList.sortByCpuUtilization(vmsToMigrate); PowerVmList.sortByCpuUtilization(vmsToMigrate);
for (PowerHost host : this.<PowerHost>getHostList()) { for (PowerHost host : this.<PowerHost>getHostList()) {
host.reallocateMigratingVms(); host.reallocateMigratingInVms();
} }
for (Vm vm : vmsToMigrate) { for (Vm vm : vmsToMigrate) {
...@@ -209,7 +207,7 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi ...@@ -209,7 +207,7 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi
protected void restoreAllocation(List<Vm> vmsToRestore, List<Host> hostList) { protected void restoreAllocation(List<Vm> vmsToRestore, List<Host> hostList) {
for (Host host : hostList) { for (Host host : hostList) {
host.vmDestroyAll(); host.vmDestroyAll();
host.reallocateMigratingVms(); host.reallocateMigratingInVms();
} }
for (Map<String, Object> map : getSavedAllocation()) { for (Map<String, Object> map : getSavedAllocation()) {
Vm vm = (Vm) map.get("vm"); Vm vm = (Vm) map.get("vm");
......
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