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 {
host.removeMigratingInVm(vm);
boolean result = getVmAllocationPolicy().allocateHostForVm(vm, host);
if (!result) {
Log.printLine("Allocation failed");
Log.printLine("[Datacenter.processVmMigrate] VM allocation to the destination host failed");
System.exit(0);
}
if (ack) {
......
......@@ -170,13 +170,12 @@ public class DatacenterCharacteristics {
* @pre $none
* @post $result >= -1
*/
@SuppressWarnings("unchecked")
public int getMipsOfOnePe() {
public int getMipsOfOnePe() {
if (getHostList().size() == 0) {
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 {
* @pre peID >= 0
* @post $result >= -1
*/
@SuppressWarnings("unchecked")
public int getMipsOfOnePe(int id, int peId) {
public int getMipsOfOnePe(int id, int peId) {
if (getHostList().size() == 0) {
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;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.lists.PeList;
import org.cloudbus.cloudsim.provisioners.BwProvisioner;
import org.cloudbus.cloudsim.provisioners.RamProvisioner;
/**
* Host class extends a Machine to include other hostList beside PEs
* to support simulation of virtualized grids. It executes actions related
* Host executes actions related
* 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
* for Pe's to virtual machines.
......@@ -57,16 +57,16 @@ public class Host {
/** The vms migrating in. */
private List<Vm> vmsMigratingIn;
/** THe datacenter where the host is placed */
/** The datacenter where the host is placed. */
private Datacenter datacenter;
/**
* Instantiates a new host.
*
* @param id the id
* @param storage the storage
* @param ramProvisioner the ram provisioner
* @param bwProvisioner the bw provisioner
* @param storage the storage
* @param peList the pe list
* @param vmScheduler the vm scheduler
*/
......@@ -102,9 +102,6 @@ public class Host {
double smallerTime = Double.MAX_VALUE;
for (Vm vm : getVmList()) {
// if (vm.isInMigration()) {
// continue;
// }
double time = vm.updateVmProcessing(currentTime, getVmScheduler().getAllocatedMipsForVm(vm));
if (time > 0.0 && time < smallerTime) {
smallerTime = time;
......@@ -114,24 +111,73 @@ public class Host {
return smallerTime;
}
/**
* Adds the migrating in vm.
*
* @param vm the vm
*/
public void addMigratingInVm(Vm vm) {
vm.setInMigration(true);
if (!getVmsMigratingIn().contains(vm)) {
getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam());
getBwProvisioner().allocateBwForVm(vm, vm.getCurrentRequestedBw());
if (getStorage() < vm.getSize()){
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);
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) {
getRamProvisioner().deallocateRamForVm(vm);
getBwProvisioner().deallocateBwForVm(vm);
vmDeallocate(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()) {
if (!getVmList().contains(vm)) {
getVmList().add(vm);
}
if (!getVmScheduler().getVmsMigratingIn().contains(vm.getUid())) {
getVmScheduler().getVmsMigratingIn().add(vm.getUid());
}
getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam());
getBwProvisioner().allocateBwForVm(vm, vm.getCurrentRequestedBw());
getVmScheduler().allocatePesForVm(vm, vm.getCurrentRequestedMips());
setStorage(getStorage() - vm.getSize());
}
}
......@@ -159,18 +205,18 @@ public class Host {
* @post $none
*/
public boolean vmCreate(Vm vm) {
if (storage<vm.getSize()){
Log.printLine("Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by storage");
if (getStorage() < vm.getSize()){
Log.printLine("[VmScheduler.vmCreate] Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by storage");
return false;
}
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;
}
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);
return false;
}
......@@ -182,7 +228,7 @@ public class Host {
return false;
}
storage-=vm.getSize();
setStorage(getStorage() - vm.getSize());
getVmList().add(vm);
vm.setHost(this);
return true;
......@@ -201,7 +247,6 @@ public class Host {
vmDeallocate(vm);
getVmList().remove(vm);
vm.setHost(null);
storage+=vm.getSize();
}
}
......@@ -215,7 +260,7 @@ public class Host {
vmDeallocateAll();
for (Vm vm : getVmList()) {
vm.setHost(null);
storage+=vm.getSize();
setStorage(getStorage() + vm.getSize());
}
getVmList().clear();
}
......@@ -229,12 +274,12 @@ public class Host {
getRamProvisioner().deallocateRamForVm(vm);
getBwProvisioner().deallocateBwForVm(vm);
getVmScheduler().deallocatePesForVm(vm);
setStorage(getStorage() + vm.getSize());
}
/**
* Deallocate all hostList for the VM.
*
* @param vm the VM
*/
protected void vmDeallocateAll() {
getRamProvisioner().deallocateRamForAllVms();
......@@ -276,7 +321,6 @@ public class Host {
*
* @return the free pes number
*/
@SuppressWarnings("unchecked")
public int getFreePesNumber() {
return PeList.getFreePesNumber((List<Pe>) getPeList());
}
......@@ -286,7 +330,6 @@ public class Host {
*
* @return the total mips
*/
@SuppressWarnings("unchecked")
public int getTotalMips() {
return PeList.getTotalMips((List<Pe>) getPeList());
}
......@@ -468,28 +511,32 @@ public class Host {
protected void setVmScheduler(VmScheduler vmScheduler) {
this.vmScheduler = vmScheduler;
}
/**
* Gets the pe list.
*
* @param <T> the generic type
* @return the pe list
*/
public List<? extends Pe> getPeList() {
return this.peList;
@SuppressWarnings("unchecked")
public <T extends Pe> List<T> getPeList() {
return (List<T>) peList;
}
/**
* Sets the pe list.
*
* @param <T> the generic type
* @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;
}
/**
* Gets the vm list.
*
* @param <T> the generic type
* @return the vm list
*/
@SuppressWarnings("unchecked")
......@@ -500,6 +547,7 @@ public class Host {
/**
* Sets the vm list.
*
* @param <T> the generic type
* @param vmList the new vm list
*/
protected <T extends Vm> void setVmList(List<T> vmList) {
......@@ -536,8 +584,7 @@ public class Host {
*
* @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)
this.failed = failed;
PeList.setStatusFailed((List<Pe>) getPeList(), resName, getId(), failed);
......@@ -551,8 +598,7 @@ public class Host {
*
* @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)
this.failed = failed;
PeList.setStatusFailed((List<Pe>) getPeList(), failed);
......@@ -562,17 +608,14 @@ public class Host {
/**
* 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 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>
* otherwise (Pe id might not be exist)
*
* @pre peID >= 0
* @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);
}
......
......@@ -10,6 +10,7 @@ package org.cloudbus.cloudsim;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
......@@ -61,7 +62,6 @@ public class HostDynamicWorkload extends Host {
@Override
public double updateVmsProcessing(double currentTime) {
double smallerTime = super.updateVmsProcessing(currentTime);
setUtilizationMips(0);
for (Vm vm : getVmList()) {
......@@ -81,18 +81,22 @@ public class HostDynamicWorkload extends Host {
}
double totalAllocatedMips = getVmScheduler().getTotalAllocatedMipsForVm(vm);
if (totalAllocatedMips + 0.1 < totalRequestedMips) {
Log.printLine("Under allocated MIPS for VM #" + vm.getId() + ": requested " + totalRequestedMips + ", allocated " + totalAllocatedMips);
}
updateUnderAllocatedMips(vm, totalRequestedMips, totalAllocatedMips);
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);
if (vm.isInMigration()) {
Log.printLine("VM #" + vm.getId() + " is in migration");
totalAllocatedMips /= 0.9; // performance degradation due to migration - 10%
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);
if (getVmsMigratingIn().contains(vm)) {
Log.formatLine("%.2f: [Host #" + getId() + "] VM #" + vm.getId() + " is being migrated to Host #" + getId(), CloudSim.clock());
} else {
if (totalAllocatedMips + 0.1 < totalRequestedMips) {
Log.formatLine("%.2f: [Host #" + getId() + "] Under allocated MIPS for VM #" + vm.getId() + ": %.2f", CloudSim.clock(), totalRequestedMips - totalAllocatedMips);
}
updateUnderAllocatedMips(vm, totalRequestedMips, totalAllocatedMips);
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);
......@@ -100,6 +104,20 @@ public class HostDynamicWorkload extends Host {
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.
......@@ -124,7 +142,6 @@ public class HostDynamicWorkload extends Host {
*
* @return the utilization
*/
@SuppressWarnings("unchecked")
public double getMaxUtilization() {
return PeList.getMaxUtilization((List<Pe>) getPeList());
}
......@@ -137,7 +154,6 @@ public class HostDynamicWorkload extends Host {
*
* @return the utilization
*/
@SuppressWarnings("unchecked")
public double getMaxUtilizationAmongVmsPes(Vm vm) {
return PeList.getMaxUtilizationAmongVmsPes((List<Pe>) getPeList(), vm);
}
......
......@@ -16,7 +16,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Random;
// TODO: Auto-generated Javadoc
/**
* The UtilizationModelStochastic class implements a model, according to which
* a Cloudlet generates random CPU utilization every time frame.
......@@ -40,6 +39,11 @@ public class UtilizationModelStochastic implements UtilizationModel {
setRandomGenerator(new Random());
}
/**
* Instantiates a new utilization model stochastic.
*
* @param seed the seed
*/
public UtilizationModelStochastic(long seed) {
setHistory(new HashMap<Double, Double>());
setRandomGenerator(new Random(seed));
......
......@@ -8,6 +8,7 @@
package org.cloudbus.cloudsim;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -33,6 +34,12 @@ public abstract class VmScheduler {
/** The total available mips. */
private double availableMips;
/** The VMs migrating in. */
private List<String> vmsMigratingIn;
/** The VMs migrating out. */
private List<String> vmsMigratingOut;
/**
* Creates a new HostAllocationPolicy.
......@@ -46,6 +53,8 @@ public abstract class VmScheduler {
setPeList(pelist);
setMipsMap(new HashMap<String, List<Double>>());
setAvailableMips(PeList.getTotalMips(getPeList()));
setVmsMigratingIn(new ArrayList<String>());
setVmsMigratingOut(new ArrayList<String>());
}
/**
......@@ -209,4 +218,40 @@ public abstract class VmScheduler {
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;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.cloudbus.cloudsim.lists.PeList;
import org.cloudbus.cloudsim.provisioners.PeProvisioner;
// TODO: Auto-generated Javadoc
/**
* VmSchedulerTimeShared is a VMM allocation policy that
* allocates one or more Pe to a VM, and allows sharing
......@@ -35,9 +37,6 @@ public class VmSchedulerTimeShared extends VmScheduler {
/** The pes in use. */
private int pesInUse;
/** The vms in migration. */
private List<String> vmsMigratingOut;
/**
* Instantiates a new vm scheduler time shared.
*
......@@ -46,7 +45,6 @@ public class VmSchedulerTimeShared extends VmScheduler {
public VmSchedulerTimeShared(List<? extends Pe> pelist) {
super(pelist);
setMipsMapRequested(new HashMap<String, List<Double>>());
setVmsInMigration(new ArrayList<String>());
}
/* (non-Javadoc)
......@@ -54,16 +52,19 @@ public class VmSchedulerTimeShared extends VmScheduler {
*/
@Override
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
*/
if (vm.isInMigration()) {
if (!getVmsInMigration().contains(vm.getUid())) {
getVmsInMigration().add(vm.getUid());
if (!getVmsMigratingIn().contains(vm.getUid()) && !getVmsMigratingOut().contains(vm.getUid())) {
getVmsMigratingOut().add(vm.getUid());
}
} else {
if (getVmsInMigration().contains(vm.getUid())) {
getVmsInMigration().remove(vm.getUid());
if (getVmsMigratingOut().contains(vm.getUid())) {
getVmsMigratingOut().remove(vm.getUid());
}
}
boolean result = allocatePesForVm(vm.getUid(), mipsShareRequested);
......@@ -91,11 +92,17 @@ public class VmSchedulerTimeShared extends VmScheduler {
}
totalRequestedMips += mips;
}
if (getVmsMigratingIn().contains(vmUid)) {
totalRequestedMips *= 0.1; // performance cost incurred by the destination host = 10% MIPS
}
List<Double> mipsShareAllocated = new ArrayList<Double>();
for (Double mipsRequested : mipsShareRequested) {
if (getVmsInMigration().contains(vmUid)) {
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);
}
......@@ -122,7 +129,11 @@ public class VmSchedulerTimeShared extends VmScheduler {
double additionalShortage = 0;
do {
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++) {
if (mipsMap.get(i) == 0) {
continue;
......@@ -205,8 +216,6 @@ public class VmSchedulerTimeShared extends VmScheduler {
/**
* Releases PEs allocated to all the VMs.
*
* @param vm the vm
*
* @pre $none
* @post $none
*/
......@@ -265,22 +274,4 @@ public class VmSchedulerTimeShared extends VmScheduler {
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;
import java.util.List;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Pe;
// TODO: Auto-generated Javadoc
/**
* HostList is a collection of operations on lists of hosts.
*
......@@ -24,11 +24,10 @@ public class HostList {
/**
* Gets the Machine object for a particular ID.
*
* @param id the host ID
* @param <T> the generic type
* @param hostList the host list
*
* @param id the host ID
* @return the Machine object or <tt>null</tt> if no machine exists
*
* @see gridsim.Machine
* @pre id >= 0
* @post $none
......@@ -45,10 +44,9 @@ public class HostList {
/**
* Gets the total number of PEs for all Machines.
*
* @param <T> the generic type
* @param hostList the host list
*
* @return number of PEs
*
* @pre $none
* @post $result >= 0
*/
......@@ -63,18 +61,16 @@ public class HostList {
/**
* 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
*
* @return number of PEs
*
* @pre $none
* @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;
for (T host : hostList) {
freePesNumber += PeList.getFreePesNumber((List<Pe>) host.getPeList());
freePesNumber += PeList.getFreePesNumber(host.getPeList());
}
return freePesNumber;
}
......@@ -82,18 +78,16 @@ public class HostList {
/**
* Gets the total number of <tt>BUSY</tt> PEs for all Machines.
*
* @param <T> the generic type
* @param hostList the host list
*
* @return number of PEs
*
* @pre $none
* @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;
for (T host : hostList) {
busyPesNumber += PeList.getBusyPesNumber((List<Pe>) host.getPeList());
busyPesNumber += PeList.getBusyPesNumber(host.getPeList());
}
return busyPesNumber;
}
......@@ -101,10 +95,9 @@ public class HostList {
/**
* Gets a Machine with free Pe.
*
* @param <T> the generic type
* @param hostList the host list
*
* @return a machine object or <tt>null</tt> if not found
*
* @pre $none
* @post $none
*/
......@@ -115,18 +108,16 @@ public class HostList {
/**
* 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 pesNumber the pes number
* @return a machine object or <tt>null</tt> if not found
*
* @pre $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) {
if (PeList.getFreePesNumber((List<Pe>) host.getPeList()) >= pesNumber) {
if (PeList.getFreePesNumber(host.getPeList()) >= pesNumber) {
return host;
}
}
......@@ -136,14 +127,13 @@ public class HostList {
/**
* 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 hostId the host id
* @param peId the pe id
* @param hostList the host list
*
* @return <tt>true</tt> if the Pe status has changed, <tt>false</tt>
* otherwise (Machine id or Pe id might not be exist)
*
* @pre machineID >= 0
* @pre peID >= 0
* @post $none
......
......@@ -87,62 +87,10 @@ public class PowerDatacenter extends Datacenter {
return;
}
double currentTime = CloudSim.clock();
double timeframePower = 0.0;
// if some time passed since last processing
if (currentTime > getLastProcessTime()) {
double timeDiff = currentTime - getLastProcessTime();
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();
double minTime = updateCloudetProcessingWithoutSchedulingFutureEvents();
if (!isDisableMigrations()) {
List<Map<String, Object>> migrationMap = getVmAllocationPolicy().optimizeAllocation(getVmList());
......@@ -152,21 +100,20 @@ public class PowerDatacenter extends Datacenter {
Vm vm = (Vm) migrate.get("vm");
PowerHost targetHost = (PowerHost) migrate.get("host");
PowerHost oldHost = (PowerHost) vm.getHost();
targetHost.addMigratingInVm(vm);
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 {
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();
vm.setInMigration(true);
/** VM migration delay = RAM / bandwidth + C (C = 10 sec) **/
send(getId(), vm.getRam() / ((double) vm.getBw() / 8000) + 0, CloudSimTags.VM_MIGRATE, migrate);
/** 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
// around 16 seconds for 1024 MB using 1 Gbit/s network
send(getId(), vm.getCurrentAllocatedRam() / ((double) targetHost.getBw() / (2 * 8000)), CloudSimTags.VM_MIGRATE, migrate);
}
}
}
......@@ -180,6 +127,83 @@ public class PowerDatacenter extends Datacenter {
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)
* @see cloudsim.Datacenter#processCloudletSubmit(cloudsim.core.SimEvent, boolean)
......
......@@ -127,18 +127,15 @@ public class PowerDatacenterNonPowerAware extends PowerDatacenter {
PowerHost targetHost = (PowerHost) migrate.get("host");
PowerHost oldHost = (PowerHost) vm.getHost();
targetHost.addMigratingInVm(vm);
if (oldHost == null) {
Log.formatLine("%.2f: Migration of VM #%d to Host #%d is started", CloudSim.clock(), vm.getId(), targetHost.getId());
} else {
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();
vm.setInMigration(true);
/** VM migration delay = RAM / bandwidth + C (C = 10 sec) **/
send(getId(), vm.getRam() / ((double) vm.getBw() / 8000) + 10, CloudSimTags.VM_MIGRATE, migrate);
}
......
......@@ -29,10 +29,10 @@ public class PowerHost extends HostDynamicWorkload {
* Instantiates a new host.
*
* @param id the id
* @param cpuProvisioner the cpu provisioner
* @param ramProvisioner the ram provisioner
* @param bwProvisioner the bw provisioner
* @param storage the storage
* @param peList the pe list
* @param vmScheduler the VM scheduler
*/
public PowerHost(
......@@ -50,9 +50,8 @@ public class PowerHost extends HostDynamicWorkload {
*
* @return the power
*/
@SuppressWarnings("unchecked")
public double getPower() {
return PowerPeList.getPower((List<PowerPe>) getPeList());
return PowerPeList.getPower(this.<PowerPe>getPeList());
}
/**
......@@ -60,9 +59,8 @@ public class PowerHost extends HostDynamicWorkload {
*
* @return the power
*/
@SuppressWarnings("unchecked")
public double getMaxPower() {
return PowerPeList.getMaxPower((List<PowerPe>) getPeList());
return PowerPeList.getMaxPower(this.<PowerPe>getPeList());
}
}
......@@ -109,9 +109,7 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi
PowerHost allocatedHost = findHostForVm(vm);
if (allocatedHost != null && allocatedHost.vmCreate(vm)) { //if vm has been succesfully created in the host
getVmTable().put(vm.getUid(), allocatedHost);
if (!Log.isDisabled()) {
Log.print(String.format("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + allocatedHost.getId() + "\n", CloudSim.clock()));
}
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + allocatedHost.getId() + "\n", CloudSim.clock());
return true;
}
return false;
......@@ -164,7 +162,7 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi
PowerVmList.sortByCpuUtilization(vmsToMigrate);
for (PowerHost host : this.<PowerHost>getHostList()) {
host.reallocateMigratingVms();
host.reallocateMigratingInVms();
}
for (Vm vm : vmsToMigrate) {
......@@ -209,7 +207,7 @@ public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySi
protected void restoreAllocation(List<Vm> vmsToRestore, List<Host> hostList) {
for (Host host : hostList) {
host.vmDestroyAll();
host.reallocateMigratingVms();
host.reallocateMigratingInVms();
}
for (Map<String, Object> map : getSavedAllocation()) {
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