This commit is contained in:
2021-04-06 00:45:28 +02:00
commit 17fabc368e
836 changed files with 3042963 additions and 0 deletions

View File

@@ -0,0 +1,368 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicy;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.core.predicates.PredicateType;
/**
* PowerDatacenter is a class that enables simulation of power-aware data centers.
*
* If you are using any algorithms, policies or workload included in the power package please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerDatacenter extends Datacenter {
/** The power. */
private double power;
/** The disable migrations. */
private boolean disableMigrations;
/** The cloudlet submited. */
private double cloudletSubmitted;
/** The migration count. */
private int migrationCount;
/**
* Instantiates a new datacenter.
*
* @param name the name
* @param characteristics the res config
* @param schedulingInterval the scheduling interval
* @param utilizationBound the utilization bound
* @param vmAllocationPolicy the vm provisioner
* @param storageList the storage list
* @throws Exception the exception
*/
public PowerDatacenter(
String name,
DatacenterCharacteristics characteristics,
VmAllocationPolicy vmAllocationPolicy,
List<Storage> storageList,
double schedulingInterval) throws Exception {
super(name, characteristics, vmAllocationPolicy, storageList, schedulingInterval);
setPower(0.0);
setDisableMigrations(false);
setCloudletSubmitted(-1);
setMigrationCount(0);
}
/**
* Updates processing of each cloudlet running in this PowerDatacenter. It is necessary because
* Hosts and VirtualMachines are simple objects, not entities. So, they don't receive events and
* updating cloudlets inside them must be called from the outside.
*
* @pre $none
* @post $none
*/
@Override
protected void updateCloudletProcessing() {
if (getCloudletSubmitted() == -1 || getCloudletSubmitted() == CloudSim.clock()) {
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.VM_DATACENTER_EVENT));
schedule(getId(), getSchedulingInterval(), CloudSimTags.VM_DATACENTER_EVENT);
return;
}
double currentTime = CloudSim.clock();
// if some time passed since last processing
if (currentTime > getLastProcessTime()) {
double minTime = updateCloudetProcessingWithoutSchedulingFutureEventsForce();
if (!isDisableMigrations()) {
List<Map<String, Object>> migrationMap = getVmAllocationPolicy().optimizeAllocation(
getVmList());
if (migrationMap != null) {
for (Map<String, Object> migrate : migrationMap) {
Vm vm = (Vm) migrate.get("vm");
PowerHost targetHost = (PowerHost) migrate.get("host");
PowerHost oldHost = (PowerHost) vm.getHost();
if (oldHost == null) {
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",
currentTime,
vm.getId(),
oldHost.getId(),
targetHost.getId());
}
targetHost.addMigratingInVm(vm);
incrementMigrationCount();
/** 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.getRam() / ((double) targetHost.getBw() / (2 * 8000)),
CloudSimTags.VM_MIGRATE,
migrate);
}
}
}
// schedules an event to the next time
if (minTime != Double.MAX_VALUE) {
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.VM_DATACENTER_EVENT));
send(getId(), getSchedulingInterval(), CloudSimTags.VM_DATACENTER_EVENT);
}
setLastProcessTime(currentTime);
}
}
/**
* Update cloudet processing without scheduling future events.
*
* @return the double
*/
protected double updateCloudetProcessingWithoutSchedulingFutureEvents() {
if (CloudSim.clock() > getLastProcessTime()) {
return updateCloudetProcessingWithoutSchedulingFutureEventsForce();
}
return 0;
}
/**
* Update cloudet processing without scheduling future events.
*
* @return the double
*/
protected double updateCloudetProcessingWithoutSchedulingFutureEventsForce() {
double currentTime = CloudSim.clock();
double minTime = Double.MAX_VALUE;
double timeDiff = currentTime - getLastProcessTime();
double timeFrameDatacenterEnergy = 0.0;
Log.printLine("\n\n--------------------------------------------------------------\n\n");
Log.formatLine("New resource usage for the time frame starting at %.2f:", currentTime);
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);
}
if (timeDiff > 0) {
Log.formatLine(
"\nEnergy consumption for the last time frame from %.2f to %.2f:",
getLastProcessTime(),
currentTime);
for (PowerHost host : this.<PowerHost> getHostList()) {
double previousUtilizationOfCpu = host.getPreviousUtilizationOfCpu();
double utilizationOfCpu = host.getUtilizationOfCpu();
double timeFrameHostEnergy = host.getEnergyLinearInterpolation(
previousUtilizationOfCpu,
utilizationOfCpu,
timeDiff);
timeFrameDatacenterEnergy += timeFrameHostEnergy;
Log.printLine();
Log.formatLine(
"%.2f: [Host #%d] utilization at %.2f was %.2f%%, now is %.2f%%",
currentTime,
host.getId(),
getLastProcessTime(),
previousUtilizationOfCpu * 100,
utilizationOfCpu * 100);
Log.formatLine(
"%.2f: [Host #%d] energy is %.2f W*sec",
currentTime,
host.getId(),
timeFrameHostEnergy);
}
Log.formatLine(
"\n%.2f: Data center's energy is %.2f W*sec\n",
currentTime,
timeFrameDatacenterEnergy);
}
setPower(getPower() + timeFrameDatacenterEnergy);
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);
SimEvent event = CloudSim.findFirstDeferred(getId(), new PredicateType(CloudSimTags.VM_MIGRATE));
if (event == null || event.eventTime() > CloudSim.clock()) {
updateCloudetProcessingWithoutSchedulingFutureEventsForce();
}
}
/*
* (non-Javadoc)
* @see cloudsim.Datacenter#processCloudletSubmit(cloudsim.core.SimEvent, boolean)
*/
@Override
protected void processCloudletSubmit(SimEvent ev, boolean ack) {
super.processCloudletSubmit(ev, ack);
setCloudletSubmitted(CloudSim.clock());
}
/**
* Gets the power.
*
* @return the power
*/
public double getPower() {
return power;
}
/**
* Sets the power.
*
* @param power the new power
*/
protected void setPower(double power) {
this.power = power;
}
/**
* Checks if PowerDatacenter is in migration.
*
* @return true, if PowerDatacenter is in migration
*/
protected boolean isInMigration() {
boolean result = false;
for (Vm vm : getVmList()) {
if (vm.isInMigration()) {
result = true;
break;
}
}
return result;
}
/**
* Checks if is disable migrations.
*
* @return true, if is disable migrations
*/
public boolean isDisableMigrations() {
return disableMigrations;
}
/**
* Sets the disable migrations.
*
* @param disableMigrations the new disable migrations
*/
public void setDisableMigrations(boolean disableMigrations) {
this.disableMigrations = disableMigrations;
}
/**
* Checks if is cloudlet submited.
*
* @return true, if is cloudlet submited
*/
protected double getCloudletSubmitted() {
return cloudletSubmitted;
}
/**
* Sets the cloudlet submited.
*
* @param cloudletSubmitted the new cloudlet submited
*/
protected void setCloudletSubmitted(double cloudletSubmitted) {
this.cloudletSubmitted = cloudletSubmitted;
}
/**
* Gets the migration count.
*
* @return the migration count
*/
public int getMigrationCount() {
return migrationCount;
}
/**
* Sets the migration count.
*
* @param migrationCount the new migration count
*/
protected void setMigrationCount(int migrationCount) {
this.migrationCount = migrationCount;
}
/**
* Increment migration count.
*/
protected void incrementMigrationCount() {
setMigrationCount(getMigrationCount() + 1);
}
}

View File

@@ -0,0 +1,62 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent;
/**
* A broker for the power package.
*
* If you are using any algorithms, policies or workload included in the power package please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerDatacenterBroker extends DatacenterBroker {
/**
* Instantiates a new power datacenter broker.
*
* @param name the name
* @throws Exception the exception
*/
public PowerDatacenterBroker(String name) throws Exception {
super(name);
}
/*
* (non-Javadoc)
* @see
* org.cloudbus.cloudsim.DatacenterBroker#processVmCreate(org.cloudbus.cloudsim.core.SimEvent)
*/
@Override
protected void processVmCreate(SimEvent ev) {
int[] data = (int[]) ev.getData();
int result = data[2];
if (result != CloudSimTags.TRUE) {
int datacenterId = data[0];
int vmId = data[1];
System.out.println(CloudSim.clock() + ": " + getName() + ": Creation of VM #" + vmId
+ " failed in Datacenter #" + datacenterId);
System.exit(0);
}
super.processVmCreate(ev);
}
}

View File

@@ -0,0 +1,187 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicy;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.predicates.PredicateType;
/**
* PowerDatacenterNonPowerAware is a class that represents a non-power aware data center in the
* context of power-aware simulations.
*
* If you are using any algorithms, policies or workload included in the power package please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerDatacenterNonPowerAware extends PowerDatacenter {
/**
* Instantiates a new datacenter.
*
* @param name the name
* @param characteristics the res config
* @param schedulingInterval the scheduling interval
* @param utilizationBound the utilization bound
* @param vmAllocationPolicy the vm provisioner
* @param storageList the storage list
*
* @throws Exception the exception
*/
public PowerDatacenterNonPowerAware(
String name,
DatacenterCharacteristics characteristics,
VmAllocationPolicy vmAllocationPolicy,
List<Storage> storageList,
double schedulingInterval) throws Exception {
super(name, characteristics, vmAllocationPolicy, storageList, schedulingInterval);
}
/**
* Updates processing of each cloudlet running in this PowerDatacenter. It is necessary because
* Hosts and VirtualMachines are simple objects, not entities. So, they don't receive events and
* updating cloudlets inside them must be called from the outside.
*
* @pre $none
* @post $none
*/
@Override
protected void updateCloudletProcessing() {
if (getCloudletSubmitted() == -1 || getCloudletSubmitted() == CloudSim.clock()) {
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.VM_DATACENTER_EVENT));
schedule(getId(), getSchedulingInterval(), CloudSimTags.VM_DATACENTER_EVENT);
return;
}
double currentTime = CloudSim.clock();
double timeframePower = 0.0;
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;
try {
hostPower = host.getMaxPower() * 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;
}
}
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()) {
List<Map<String, Object>> migrationMap = getVmAllocationPolicy().optimizeAllocation(
getVmList());
if (migrationMap != null) {
for (Map<String, Object> migrate : migrationMap) {
Vm vm = (Vm) migrate.get("vm");
PowerHost targetHost = (PowerHost) migrate.get("host");
PowerHost oldHost = (PowerHost) vm.getHost();
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 migration delay = RAM / bandwidth + C (C = 10 sec) **/
send(
getId(),
vm.getRam() / ((double) vm.getBw() / 8000) + 10,
CloudSimTags.VM_MIGRATE,
migrate);
}
}
}
// schedules an event to the next time
if (minTime != Double.MAX_VALUE) {
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.VM_DATACENTER_EVENT));
// CloudSim.cancelAll(getId(), CloudSim.SIM_ANY);
send(getId(), getSchedulingInterval(), CloudSimTags.VM_DATACENTER_EVENT);
}
setLastProcessTime(currentTime);
}
}
}

View File

@@ -0,0 +1,138 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.List;
import org.cloudbus.cloudsim.HostDynamicWorkload;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.VmScheduler;
import org.cloudbus.cloudsim.power.models.PowerModel;
import org.cloudbus.cloudsim.provisioners.BwProvisioner;
import org.cloudbus.cloudsim.provisioners.RamProvisioner;
/**
* PowerHost class enables simulation of power-aware hosts.
*
* If you are using any algorithms, policies or workload included in the power package please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerHost extends HostDynamicWorkload {
/** The power model. */
private PowerModel powerModel;
/**
* Instantiates a new host.
*
* @param id the id
* @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(
int id,
RamProvisioner ramProvisioner,
BwProvisioner bwProvisioner,
long storage,
List<? extends Pe> peList,
VmScheduler vmScheduler,
PowerModel powerModel) {
super(id, ramProvisioner, bwProvisioner, storage, peList, vmScheduler);
setPowerModel(powerModel);
}
/**
* Gets the power. For this moment only consumed by all PEs.
*
* @return the power
*/
public double getPower() {
return getPower(getUtilizationOfCpu());
}
/**
* Gets the power. For this moment only consumed by all PEs.
*
* @param utilization the utilization
* @return the power
*/
protected double getPower(double utilization) {
double power = 0;
try {
power = getPowerModel().getPower(utilization);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
return power;
}
/**
* Gets the max power that can be consumed by the host.
*
* @return the max power
*/
public double getMaxPower() {
double power = 0;
try {
power = getPowerModel().getPower(1);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
return power;
}
/**
* Gets the energy consumption using linear interpolation of the utilization change.
*
* @param fromUtilization the from utilization
* @param toUtilization the to utilization
* @param time the time
* @return the energy
*/
public double getEnergyLinearInterpolation(double fromUtilization, double toUtilization, double time) {
if (fromUtilization == 0) {
return 0;
}
double fromPower = getPower(fromUtilization);
double toPower = getPower(toUtilization);
return (fromPower + (toPower - fromPower) / 2) * time;
}
/**
* Sets the power model.
*
* @param powerModel the new power model
*/
protected void setPowerModel(PowerModel powerModel) {
this.powerModel = powerModel;
}
/**
* Gets the power model.
*
* @return the power model
*/
public PowerModel getPowerModel() {
return powerModel;
}
}

View File

@@ -0,0 +1,75 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.List;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.VmScheduler;
import org.cloudbus.cloudsim.power.models.PowerModel;
import org.cloudbus.cloudsim.provisioners.BwProvisioner;
import org.cloudbus.cloudsim.provisioners.RamProvisioner;
import org.cloudbus.cloudsim.util.MathUtil;
/**
* The class of a host that stores its CPU utilization history. The history is used by VM allocation
* and selection policies.
*
* If you are using any algorithms, policies or workload included in the power package please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerHostUtilizationHistory extends PowerHost {
/**
* Instantiates a new power host utilization history.
*
* @param id the id
* @param ramProvisioner the ram provisioner
* @param bwProvisioner the bw provisioner
* @param storage the storage
* @param peList the pe list
* @param vmScheduler the vm scheduler
* @param powerModel the power model
*/
public PowerHostUtilizationHistory(
int id,
RamProvisioner ramProvisioner,
BwProvisioner bwProvisioner,
long storage,
List<? extends Pe> peList,
VmScheduler vmScheduler,
PowerModel powerModel) {
super(id, ramProvisioner, bwProvisioner, storage, peList, vmScheduler, powerModel);
}
/**
* Gets the host utilization history.
*
* @return the host utilization history
*/
protected double[] getUtilizationHistory() {
double[] utilizationHistory = new double[PowerVm.HISTORY_LENGTH];
double hostMips = getTotalMips();
for (PowerVm vm : this.<PowerVm> getVmList()) {
for (int i = 0; i < vm.getUtilizationHistory().size(); i++) {
utilizationHistory[i] += vm.getUtilizationHistory().get(i) * vm.getMips() / hostMips;
}
}
return MathUtil.trimZeroTail(utilizationHistory);
}
}

View File

@@ -0,0 +1,225 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.LinkedList;
import java.util.List;
import org.cloudbus.cloudsim.CloudletScheduler;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.util.MathUtil;
/**
* The class of a VM that stores its CPU utilization history. The history is used by VM allocation
* and selection policies.
*
* If you are using any algorithms, policies or workload included in the power package please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerVm extends Vm {
/** The Constant HISTORY_LENGTH. */
public static final int HISTORY_LENGTH = 30;
/** The utilization history. */
private final List<Double> utilizationHistory = new LinkedList<Double>();
/** The previous time. */
private double previousTime;
/** The scheduling interval. */
private double schedulingInterval;
/**
* Instantiates a new power vm.
*
* @param id the id
* @param userId the user id
* @param mips the mips
* @param pesNumber the pes number
* @param ram the ram
* @param bw the bw
* @param size the size
* @param priority the priority
* @param vmm the vmm
* @param cloudletScheduler the cloudlet scheduler
* @param schedulingInterval the scheduling interval
*/
public PowerVm(
final int id,
final int userId,
final double mips,
final int pesNumber,
final int ram,
final long bw,
final long size,
final int priority,
final String vmm,
final CloudletScheduler cloudletScheduler,
final double schedulingInterval) {
super(id, userId, mips, pesNumber, ram, bw, size, vmm, cloudletScheduler);
setSchedulingInterval(schedulingInterval);
}
/**
* Updates the processing of cloudlets running on this VM.
*
* @param currentTime current simulation time
* @param mipsShare array with MIPS share of each Pe available to the scheduler
*
* @return time predicted completion time of the earliest finishing cloudlet, or 0 if there is
* no next events
*
* @pre currentTime >= 0
* @post $none
*/
@Override
public double updateVmProcessing(final double currentTime, final List<Double> mipsShare) {
double time = super.updateVmProcessing(currentTime, mipsShare);
if (currentTime > getPreviousTime() && (currentTime - 0.1) % getSchedulingInterval() == 0) {
double utilization = getTotalUtilizationOfCpu(getCloudletScheduler().getPreviousTime());
if (CloudSim.clock() != 0 || utilization != 0) {
addUtilizationHistoryValue(utilization);
}
setPreviousTime(currentTime);
}
return time;
}
/**
* Gets the utilization MAD in MIPS.
*
* @return the utilization mean in MIPS
*/
public double getUtilizationMad() {
double mad = 0;
if (!getUtilizationHistory().isEmpty()) {
int n = HISTORY_LENGTH;
if (HISTORY_LENGTH > getUtilizationHistory().size()) {
n = getUtilizationHistory().size();
}
double median = MathUtil.median(getUtilizationHistory());
double[] deviationSum = new double[n];
for (int i = 0; i < n; i++) {
deviationSum[i] = Math.abs(median - getUtilizationHistory().get(i));
}
mad = MathUtil.median(deviationSum);
}
return mad;
}
/**
* Gets the utilization mean in percents.
*
* @return the utilization mean in MIPS
*/
public double getUtilizationMean() {
double mean = 0;
if (!getUtilizationHistory().isEmpty()) {
int n = HISTORY_LENGTH;
if (HISTORY_LENGTH > getUtilizationHistory().size()) {
n = getUtilizationHistory().size();
}
for (int i = 0; i < n; i++) {
mean += getUtilizationHistory().get(i);
}
mean /= n;
}
return mean * getMips();
}
/**
* Gets the utilization variance in MIPS.
*
* @return the utilization variance in MIPS
*/
public double getUtilizationVariance() {
double mean = getUtilizationMean();
double variance = 0;
if (!getUtilizationHistory().isEmpty()) {
int n = HISTORY_LENGTH;
if (HISTORY_LENGTH > getUtilizationHistory().size()) {
n = getUtilizationHistory().size();
}
for (int i = 0; i < n; i++) {
double tmp = getUtilizationHistory().get(i) * getMips() - mean;
variance += tmp * tmp;
}
variance /= n;
}
return variance;
}
/**
* Adds the utilization history value.
*
* @param utilization the utilization
*/
public void addUtilizationHistoryValue(final double utilization) {
getUtilizationHistory().add(0, utilization);
if (getUtilizationHistory().size() > HISTORY_LENGTH) {
getUtilizationHistory().remove(HISTORY_LENGTH);
}
}
/**
* Gets the utilization history.
*
* @return the utilization history
*/
protected List<Double> getUtilizationHistory() {
return utilizationHistory;
}
/**
* Gets the previous time.
*
* @return the previous time
*/
public double getPreviousTime() {
return previousTime;
}
/**
* Sets the previous time.
*
* @param previousTime the new previous time
*/
public void setPreviousTime(final double previousTime) {
this.previousTime = previousTime;
}
/**
* Gets the scheduling interval.
*
* @return the schedulingInterval
*/
public double getSchedulingInterval() {
return schedulingInterval;
}
/**
* Sets the scheduling interval.
*
* @param schedulingInterval the schedulingInterval to set
*/
protected void setSchedulingInterval(final double schedulingInterval) {
this.schedulingInterval = schedulingInterval;
}
}

View File

@@ -0,0 +1,136 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicy;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* The class of an abstract power-aware VM allocation policy.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public abstract class PowerVmAllocationPolicyAbstract extends VmAllocationPolicy {
/** The vm table. */
private final Map<String, Host> vmTable = new HashMap<String, Host>();
/**
* Instantiates a new power vm allocation policy abstract.
*
* @param list the list
*/
public PowerVmAllocationPolicyAbstract(List<? extends Host> list) {
super(list);
}
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.VmAllocationPolicy#allocateHostForVm(org.cloudbus.cloudsim.Vm)
*/
@Override
public boolean allocateHostForVm(Vm vm) {
return allocateHostForVm(vm, findHostForVm(vm));
}
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.VmAllocationPolicy#allocateHostForVm(org.cloudbus.cloudsim.Vm,
* org.cloudbus.cloudsim.Host)
*/
@Override
public boolean allocateHostForVm(Vm vm, Host host) {
if (host == null) {
Log.formatLine("%.2f: No suitable host found for VM #" + vm.getId() + "\n", CloudSim.clock());
return false;
}
if (host.vmCreate(vm)) { // if vm has been succesfully created in the host
getVmTable().put(vm.getUid(), host);
Log.formatLine(
"%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(),
CloudSim.clock());
return true;
}
Log.formatLine(
"%.2f: Creation of VM #" + vm.getId() + " on the host #" + host.getId() + " failed\n",
CloudSim.clock());
return false;
}
/**
* Find host for vm.
*
* @param vm the vm
* @return the power host
*/
public PowerHost findHostForVm(Vm vm) {
for (PowerHost host : this.<PowerHost> getHostList()) {
if (host.isSuitableForVm(vm)) {
return host;
}
}
return null;
}
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.VmAllocationPolicy#deallocateHostForVm(org.cloudbus.cloudsim.Vm)
*/
@Override
public void deallocateHostForVm(Vm vm) {
Host host = getVmTable().remove(vm.getUid());
if (host != null) {
host.vmDestroy(vm);
}
}
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.VmAllocationPolicy#getHost(org.cloudbus.cloudsim.Vm)
*/
@Override
public Host getHost(Vm vm) {
return getVmTable().get(vm.getUid());
}
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.VmAllocationPolicy#getHost(int, int)
*/
@Override
public Host getHost(int vmId, int userId) {
return getVmTable().get(Vm.getUid(userId, vmId));
}
/**
* Gets the vm table.
*
* @return the vm table
*/
public Map<String, Host> getVmTable() {
return vmTable;
}
}

View File

@@ -0,0 +1,674 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.HostDynamicWorkload;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.power.lists.PowerVmList;
import org.cloudbus.cloudsim.util.ExecutionTimeMeasurer;
/**
* The class of an abstract power-aware VM allocation policy that dynamically optimizes the VM
* allocation using migration.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public abstract class PowerVmAllocationPolicyMigrationAbstract extends PowerVmAllocationPolicyAbstract {
/** The vm selection policy. */
private PowerVmSelectionPolicy vmSelectionPolicy;
/** The saved allocation. */
private final List<Map<String, Object>> savedAllocation = new ArrayList<Map<String, Object>>();
/** The utilization history. */
private final Map<Integer, List<Double>> utilizationHistory = new HashMap<Integer, List<Double>>();
/** The metric history. */
private final Map<Integer, List<Double>> metricHistory = new HashMap<Integer, List<Double>>();
/** The time history. */
private final Map<Integer, List<Double>> timeHistory = new HashMap<Integer, List<Double>>();
/** The execution time history vm selection. */
private final List<Double> executionTimeHistoryVmSelection = new LinkedList<Double>();
/** The execution time history host selection. */
private final List<Double> executionTimeHistoryHostSelection = new LinkedList<Double>();
/** The execution time history vm reallocation. */
private final List<Double> executionTimeHistoryVmReallocation = new LinkedList<Double>();
/** The execution time history total. */
private final List<Double> executionTimeHistoryTotal = new LinkedList<Double>();
/**
* Instantiates a new power vm allocation policy migration abstract.
*
* @param hostList the host list
* @param vmSelectionPolicy the vm selection policy
*/
public PowerVmAllocationPolicyMigrationAbstract(
List<? extends Host> hostList,
PowerVmSelectionPolicy vmSelectionPolicy) {
super(hostList);
setVmSelectionPolicy(vmSelectionPolicy);
}
/**
* Optimize allocation of the VMs according to current utilization.
*
* @param vmList the vm list
*
* @return the array list< hash map< string, object>>
*/
@Override
public List<Map<String, Object>> optimizeAllocation(List<? extends Vm> vmList) {
ExecutionTimeMeasurer.start("optimizeAllocationTotal");
ExecutionTimeMeasurer.start("optimizeAllocationHostSelection");
List<PowerHostUtilizationHistory> overUtilizedHosts = getOverUtilizedHosts();
getExecutionTimeHistoryHostSelection().add(
ExecutionTimeMeasurer.end("optimizeAllocationHostSelection"));
printOverUtilizedHosts(overUtilizedHosts);
saveAllocation();
ExecutionTimeMeasurer.start("optimizeAllocationVmSelection");
List<? extends Vm> vmsToMigrate = getVmsToMigrateFromHosts(overUtilizedHosts);
getExecutionTimeHistoryVmSelection().add(ExecutionTimeMeasurer.end("optimizeAllocationVmSelection"));
Log.printLine("Reallocation of VMs from the over-utilized hosts:");
ExecutionTimeMeasurer.start("optimizeAllocationVmReallocation");
List<Map<String, Object>> migrationMap = getNewVmPlacement(vmsToMigrate, new HashSet<Host>(
overUtilizedHosts));
getExecutionTimeHistoryVmReallocation().add(
ExecutionTimeMeasurer.end("optimizeAllocationVmReallocation"));
Log.printLine();
migrationMap.addAll(getMigrationMapFromUnderUtilizedHosts(overUtilizedHosts));
restoreAllocation();
getExecutionTimeHistoryTotal().add(ExecutionTimeMeasurer.end("optimizeAllocationTotal"));
return migrationMap;
}
/**
* Gets the migration map from under utilized hosts.
*
* @param overUtilizedHosts the over utilized hosts
* @return the migration map from under utilized hosts
*/
protected List<Map<String, Object>> getMigrationMapFromUnderUtilizedHosts(
List<PowerHostUtilizationHistory> overUtilizedHosts) {
List<Map<String, Object>> migrationMap = new LinkedList<Map<String, Object>>();
List<PowerHost> switchedOffHosts = getSwitchedOffHosts();
// over-utilized hosts + hosts that are selected to migrate VMs to from over-utilized hosts
Set<PowerHost> excludedHostsForFindingUnderUtilizedHost = new HashSet<PowerHost>();
excludedHostsForFindingUnderUtilizedHost.addAll(overUtilizedHosts);
excludedHostsForFindingUnderUtilizedHost.addAll(switchedOffHosts);
excludedHostsForFindingUnderUtilizedHost.addAll(extractHostListFromMigrationMap(migrationMap));
// over-utilized + under-utilized hosts
Set<PowerHost> excludedHostsForFindingNewVmPlacement = new HashSet<PowerHost>();
excludedHostsForFindingNewVmPlacement.addAll(overUtilizedHosts);
excludedHostsForFindingNewVmPlacement.addAll(switchedOffHosts);
int numberOfHosts = getHostList().size();
while (true) {
if (numberOfHosts == excludedHostsForFindingUnderUtilizedHost.size()) {
break;
}
PowerHost underUtilizedHost = getUnderUtilizedHost(excludedHostsForFindingUnderUtilizedHost);
if (underUtilizedHost == null) {
break;
}
Log.printLine("Under-utilized host: host #" + underUtilizedHost.getId() + "\n");
excludedHostsForFindingUnderUtilizedHost.add(underUtilizedHost);
excludedHostsForFindingNewVmPlacement.add(underUtilizedHost);
List<? extends Vm> vmsToMigrateFromUnderUtilizedHost = getVmsToMigrateFromUnderUtilizedHost(underUtilizedHost);
if (vmsToMigrateFromUnderUtilizedHost.isEmpty()) {
continue;
}
Log.print("Reallocation of VMs from the under-utilized host: ");
if (!Log.isDisabled()) {
for (Vm vm : vmsToMigrateFromUnderUtilizedHost) {
Log.print(vm.getId() + " ");
}
}
Log.printLine();
List<Map<String, Object>> newVmPlacement = getNewVmPlacementFromUnderUtilizedHost(
vmsToMigrateFromUnderUtilizedHost,
excludedHostsForFindingNewVmPlacement);
excludedHostsForFindingUnderUtilizedHost.addAll(extractHostListFromMigrationMap(newVmPlacement));
migrationMap.addAll(newVmPlacement);
Log.printLine();
}
return migrationMap;
}
/**
* Prints the over utilized hosts.
*
* @param overUtilizedHosts the over utilized hosts
*/
protected void printOverUtilizedHosts(List<PowerHostUtilizationHistory> overUtilizedHosts) {
if (!Log.isDisabled()) {
Log.printLine("Over-utilized hosts:");
for (PowerHostUtilizationHistory host : overUtilizedHosts) {
Log.printLine("Host #" + host.getId());
}
Log.printLine();
}
}
/**
* Find host for vm.
*
* @param vm the vm
* @param excludedHosts the excluded hosts
* @return the power host
*/
public PowerHost findHostForVm(Vm vm, Set<? extends Host> excludedHosts) {
double minPower = Double.MAX_VALUE;
PowerHost allocatedHost = null;
for (PowerHost host : this.<PowerHost> getHostList()) {
if (excludedHosts.contains(host)) {
continue;
}
if (host.isSuitableForVm(vm)) {
if (getUtilizationOfCpuMips(host) != 0 && isHostOverUtilizedAfterAllocation(host, vm)) {
continue;
}
try {
double powerAfterAllocation = getPowerAfterAllocation(host, vm);
if (powerAfterAllocation != -1) {
double powerDiff = powerAfterAllocation - host.getPower();
if (powerDiff < minPower) {
minPower = powerDiff;
allocatedHost = host;
}
}
} catch (Exception e) {
}
}
}
return allocatedHost;
}
/**
* Checks if is host over utilized after allocation.
*
* @param host the host
* @param vm the vm
* @return true, if is host over utilized after allocation
*/
protected boolean isHostOverUtilizedAfterAllocation(PowerHost host, Vm vm) {
boolean isHostOverUtilizedAfterAllocation = true;
if (host.vmCreate(vm)) {
isHostOverUtilizedAfterAllocation = isHostOverUtilized(host);
host.vmDestroy(vm);
}
return isHostOverUtilizedAfterAllocation;
}
/**
* Find host for vm.
*
* @param vm the vm
* @return the power host
*/
@Override
public PowerHost findHostForVm(Vm vm) {
Set<Host> excludedHosts = new HashSet<Host>();
if (vm.getHost() != null) {
excludedHosts.add(vm.getHost());
}
return findHostForVm(vm, excludedHosts);
}
/**
* Extract host list from migration map.
*
* @param migrationMap the migration map
* @return the list
*/
protected List<PowerHost> extractHostListFromMigrationMap(List<Map<String, Object>> migrationMap) {
List<PowerHost> hosts = new LinkedList<PowerHost>();
for (Map<String, Object> map : migrationMap) {
hosts.add((PowerHost) map.get("host"));
}
return hosts;
}
/**
* Gets the new vm placement.
*
* @param vmsToMigrate the vms to migrate
* @param excludedHosts the excluded hosts
* @return the new vm placement
*/
protected List<Map<String, Object>> getNewVmPlacement(
List<? extends Vm> vmsToMigrate,
Set<? extends Host> excludedHosts) {
List<Map<String, Object>> migrationMap = new LinkedList<Map<String, Object>>();
PowerVmList.sortByCpuUtilization(vmsToMigrate);
for (Vm vm : vmsToMigrate) {
PowerHost allocatedHost = findHostForVm(vm, excludedHosts);
if (allocatedHost != null) {
allocatedHost.vmCreate(vm);
Log.printLine("VM #" + vm.getId() + " allocated to host #" + allocatedHost.getId());
Map<String, Object> migrate = new HashMap<String, Object>();
migrate.put("vm", vm);
migrate.put("host", allocatedHost);
migrationMap.add(migrate);
}
}
return migrationMap;
}
/**
* Gets the new vm placement from under utilized host.
*
* @param vmsToMigrate the vms to migrate
* @param excludedHosts the excluded hosts
* @return the new vm placement from under utilized host
*/
protected List<Map<String, Object>> getNewVmPlacementFromUnderUtilizedHost(
List<? extends Vm> vmsToMigrate,
Set<? extends Host> excludedHosts) {
List<Map<String, Object>> migrationMap = new LinkedList<Map<String, Object>>();
PowerVmList.sortByCpuUtilization(vmsToMigrate);
for (Vm vm : vmsToMigrate) {
PowerHost allocatedHost = findHostForVm(vm, excludedHosts);
if (allocatedHost != null) {
allocatedHost.vmCreate(vm);
Log.printLine("VM #" + vm.getId() + " allocated to host #" + allocatedHost.getId());
Map<String, Object> migrate = new HashMap<String, Object>();
migrate.put("vm", vm);
migrate.put("host", allocatedHost);
migrationMap.add(migrate);
} else {
Log.printLine("Not all VMs can be reallocated from the host, reallocation cancelled");
for (Map<String, Object> map : migrationMap) {
((Host) map.get("host")).vmDestroy((Vm) map.get("vm"));
}
migrationMap.clear();
break;
}
}
return migrationMap;
}
/**
* Gets the vms to migrate from hosts.
*
* @param overUtilizedHosts the over utilized hosts
* @return the vms to migrate from hosts
*/
protected
List<? extends Vm>
getVmsToMigrateFromHosts(List<PowerHostUtilizationHistory> overUtilizedHosts) {
List<Vm> vmsToMigrate = new LinkedList<Vm>();
for (PowerHostUtilizationHistory host : overUtilizedHosts) {
while (true) {
Vm vm = getVmSelectionPolicy().getVmToMigrate(host);
if (vm == null) {
break;
}
vmsToMigrate.add(vm);
host.vmDestroy(vm);
if (!isHostOverUtilized(host)) {
break;
}
}
}
return vmsToMigrate;
}
/**
* Gets the vms to migrate from under utilized host.
*
* @param host the host
* @return the vms to migrate from under utilized host
*/
protected List<? extends Vm> getVmsToMigrateFromUnderUtilizedHost(PowerHost host) {
List<Vm> vmsToMigrate = new LinkedList<Vm>();
for (Vm vm : host.getVmList()) {
if (!vm.isInMigration()) {
vmsToMigrate.add(vm);
}
}
return vmsToMigrate;
}
/**
* Gets the over utilized hosts.
*
* @return the over utilized hosts
*/
protected List<PowerHostUtilizationHistory> getOverUtilizedHosts() {
List<PowerHostUtilizationHistory> overUtilizedHosts = new LinkedList<PowerHostUtilizationHistory>();
for (PowerHostUtilizationHistory host : this.<PowerHostUtilizationHistory> getHostList()) {
if (isHostOverUtilized(host)) {
overUtilizedHosts.add(host);
}
}
return overUtilizedHosts;
}
/**
* Gets the switched off host.
*
* @return the switched off host
*/
protected List<PowerHost> getSwitchedOffHosts() {
List<PowerHost> switchedOffHosts = new LinkedList<PowerHost>();
for (PowerHost host : this.<PowerHost> getHostList()) {
if (host.getUtilizationOfCpu() == 0) {
switchedOffHosts.add(host);
}
}
return switchedOffHosts;
}
/**
* Gets the under utilized host.
*
* @param excludedHosts the excluded hosts
* @return the under utilized host
*/
protected PowerHost getUnderUtilizedHost(Set<? extends Host> excludedHosts) {
double minUtilization = 1;
PowerHost underUtilizedHost = null;
for (PowerHost host : this.<PowerHost> getHostList()) {
if (excludedHosts.contains(host)) {
continue;
}
double utilization = host.getUtilizationOfCpu();
if (utilization > 0 && utilization < minUtilization
&& !areAllVmsMigratingOutOrAnyVmMigratingIn(host)) {
minUtilization = utilization;
underUtilizedHost = host;
}
}
return underUtilizedHost;
}
/**
* Checks whether all vms are in migration.
*
* @param host the host
* @return true, if successful
*/
protected boolean areAllVmsMigratingOutOrAnyVmMigratingIn(PowerHost host) {
for (PowerVm vm : host.<PowerVm> getVmList()) {
if (!vm.isInMigration()) {
return false;
}
if (host.getVmsMigratingIn().contains(vm)) {
return true;
}
}
return true;
}
/**
* Checks if is host over utilized.
*
* @param host the host
* @return true, if is host over utilized
*/
protected abstract boolean isHostOverUtilized(PowerHost host);
/**
* Adds the history value.
*
* @param host the host
* @param metric the metric
*/
protected void addHistoryEntry(HostDynamicWorkload host, double metric) {
int hostId = host.getId();
if (!getTimeHistory().containsKey(hostId)) {
getTimeHistory().put(hostId, new LinkedList<Double>());
}
if (!getUtilizationHistory().containsKey(hostId)) {
getUtilizationHistory().put(hostId, new LinkedList<Double>());
}
if (!getMetricHistory().containsKey(hostId)) {
getMetricHistory().put(hostId, new LinkedList<Double>());
}
if (!getTimeHistory().get(hostId).contains(CloudSim.clock())) {
getTimeHistory().get(hostId).add(CloudSim.clock());
getUtilizationHistory().get(hostId).add(host.getUtilizationOfCpu());
getMetricHistory().get(hostId).add(metric);
}
}
/**
* Save allocation.
*/
protected void saveAllocation() {
getSavedAllocation().clear();
for (Host host : getHostList()) {
for (Vm vm : host.getVmList()) {
if (host.getVmsMigratingIn().contains(vm)) {
continue;
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("host", host);
map.put("vm", vm);
getSavedAllocation().add(map);
}
}
}
/**
* Restore allocation.
*/
protected void restoreAllocation() {
for (Host host : getHostList()) {
host.vmDestroyAll();
host.reallocateMigratingInVms();
}
for (Map<String, Object> map : getSavedAllocation()) {
Vm vm = (Vm) map.get("vm");
PowerHost host = (PowerHost) map.get("host");
if (!host.vmCreate(vm)) {
Log.printLine("Couldn't restore VM #" + vm.getId() + " on host #" + host.getId());
System.exit(0);
}
getVmTable().put(vm.getUid(), host);
}
}
/**
* Gets the power after allocation.
*
* @param host the host
* @param vm the vm
*
* @return the power after allocation
*/
protected double getPowerAfterAllocation(PowerHost host, Vm vm) {
double power = 0;
try {
power = host.getPowerModel().getPower(getMaxUtilizationAfterAllocation(host, vm));
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
return power;
}
/**
* Gets the power after allocation. We assume that load is balanced between PEs. The only
* restriction is: VM's max MIPS < PE's MIPS
*
* @param host the host
* @param vm the vm
*
* @return the power after allocation
*/
protected double getMaxUtilizationAfterAllocation(PowerHost host, Vm vm) {
double requestedTotalMips = vm.getCurrentRequestedTotalMips();
double hostUtilizationMips = getUtilizationOfCpuMips(host);
double hostPotentialUtilizationMips = hostUtilizationMips + requestedTotalMips;
double pePotentialUtilization = hostPotentialUtilizationMips / host.getTotalMips();
return pePotentialUtilization;
}
/**
* Gets the utilization of the CPU in MIPS for the current potentially allocated VMs.
*
* @param host the host
*
* @return the utilization of the CPU in MIPS
*/
protected double getUtilizationOfCpuMips(PowerHost host) {
double hostUtilizationMips = 0;
for (Vm vm2 : host.getVmList()) {
if (host.getVmsMigratingIn().contains(vm2)) {
// calculate additional potential CPU usage of a migrating in VM
hostUtilizationMips += host.getTotalAllocatedMipsForVm(vm2) * 0.9 / 0.1;
}
hostUtilizationMips += host.getTotalAllocatedMipsForVm(vm2);
}
return hostUtilizationMips;
}
/**
* Gets the saved allocation.
*
* @return the saved allocation
*/
protected List<Map<String, Object>> getSavedAllocation() {
return savedAllocation;
}
/**
* Sets the vm selection policy.
*
* @param vmSelectionPolicy the new vm selection policy
*/
protected void setVmSelectionPolicy(PowerVmSelectionPolicy vmSelectionPolicy) {
this.vmSelectionPolicy = vmSelectionPolicy;
}
/**
* Gets the vm selection policy.
*
* @return the vm selection policy
*/
protected PowerVmSelectionPolicy getVmSelectionPolicy() {
return vmSelectionPolicy;
}
/**
* Gets the utilization history.
*
* @return the utilization history
*/
public Map<Integer, List<Double>> getUtilizationHistory() {
return utilizationHistory;
}
/**
* Gets the metric history.
*
* @return the metric history
*/
public Map<Integer, List<Double>> getMetricHistory() {
return metricHistory;
}
/**
* Gets the time history.
*
* @return the time history
*/
public Map<Integer, List<Double>> getTimeHistory() {
return timeHistory;
}
/**
* Gets the execution time history vm selection.
*
* @return the execution time history vm selection
*/
public List<Double> getExecutionTimeHistoryVmSelection() {
return executionTimeHistoryVmSelection;
}
/**
* Gets the execution time history host selection.
*
* @return the execution time history host selection
*/
public List<Double> getExecutionTimeHistoryHostSelection() {
return executionTimeHistoryHostSelection;
}
/**
* Gets the execution time history vm reallocation.
*
* @return the execution time history vm reallocation
*/
public List<Double> getExecutionTimeHistoryVmReallocation() {
return executionTimeHistoryVmReallocation;
}
/**
* Gets the execution time history total.
*
* @return the execution time history total
*/
public List<Double> getExecutionTimeHistoryTotal() {
return executionTimeHistoryTotal;
}
}

View File

@@ -0,0 +1,157 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.List;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.util.MathUtil;
/**
* The Inter Quartile Range (IQR) VM allocation policy.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerVmAllocationPolicyMigrationInterQuartileRange extends
PowerVmAllocationPolicyMigrationAbstract {
/** The safety parameter. */
private double safetyParameter = 0;
/** The fallback vm allocation policy. */
private PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy;
/**
* Instantiates a new power vm allocation policy migration mad.
*
* @param hostList the host list
* @param vmSelectionPolicy the vm selection policy
* @param safetyParameter the safety parameter
* @param utilizationThreshold the utilization threshold
*/
public PowerVmAllocationPolicyMigrationInterQuartileRange(
List<? extends Host> hostList,
PowerVmSelectionPolicy vmSelectionPolicy,
double safetyParameter,
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy,
double utilizationThreshold) {
super(hostList, vmSelectionPolicy);
setSafetyParameter(safetyParameter);
setFallbackVmAllocationPolicy(fallbackVmAllocationPolicy);
}
/**
* Instantiates a new power vm allocation policy migration mad.
*
* @param hostList the host list
* @param vmSelectionPolicy the vm selection policy
* @param safetyParameter the safety parameter
*/
public PowerVmAllocationPolicyMigrationInterQuartileRange(
List<? extends Host> hostList,
PowerVmSelectionPolicy vmSelectionPolicy,
double safetyParameter,
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy) {
super(hostList, vmSelectionPolicy);
setSafetyParameter(safetyParameter);
setFallbackVmAllocationPolicy(fallbackVmAllocationPolicy);
}
/**
* Checks if is host over utilized.
*
* @param _host the _host
* @return true, if is host over utilized
*/
@Override
protected boolean isHostOverUtilized(PowerHost host) {
PowerHostUtilizationHistory _host = (PowerHostUtilizationHistory) host;
double upperThreshold = 0;
try {
upperThreshold = 1 - getSafetyParameter() * getHostUtilizationIqr(_host);
} catch (IllegalArgumentException e) {
return getFallbackVmAllocationPolicy().isHostOverUtilized(host);
}
addHistoryEntry(host, upperThreshold);
double totalRequestedMips = 0;
for (Vm vm : host.getVmList()) {
totalRequestedMips += vm.getCurrentRequestedTotalMips();
}
double utilization = totalRequestedMips / host.getTotalMips();
return utilization > upperThreshold;
}
/**
* Gets the host utilization iqr.
*
* @param host the host
* @return the host utilization iqr
*/
protected double getHostUtilizationIqr(PowerHostUtilizationHistory host) throws IllegalArgumentException {
double[] data = host.getUtilizationHistory();
if (MathUtil.countNonZeroBeginning(data) >= 12) { // 12 has been suggested as a safe value
return MathUtil.iqr(data);
}
throw new IllegalArgumentException();
}
/**
* Sets the safety parameter.
*
* @param safetyParameter the new safety parameter
*/
protected void setSafetyParameter(double safetyParameter) {
if (safetyParameter < 0) {
Log.printLine("The safety parameter cannot be less than zero. The passed value is: "
+ safetyParameter);
System.exit(0);
}
this.safetyParameter = safetyParameter;
}
/**
* Gets the safety parameter.
*
* @return the safety parameter
*/
protected double getSafetyParameter() {
return safetyParameter;
}
/**
* Sets the fallback vm allocation policy.
*
* @param fallbackVmAllocationPolicy the new fallback vm allocation policy
*/
public void setFallbackVmAllocationPolicy(
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy) {
this.fallbackVmAllocationPolicy = fallbackVmAllocationPolicy;
}
/**
* Gets the fallback vm allocation policy.
*
* @return the fallback vm allocation policy
*/
public PowerVmAllocationPolicyMigrationAbstract getFallbackVmAllocationPolicy() {
return fallbackVmAllocationPolicy;
}
}

View File

@@ -0,0 +1,189 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.List;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.util.MathUtil;
/**
* The Local Regression (LR) VM allocation policy.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerVmAllocationPolicyMigrationLocalRegression extends PowerVmAllocationPolicyMigrationAbstract {
/** The scheduling interval. */
private double schedulingInterval;
/** The safety parameter. */
private double safetyParameter;
/** The fallback vm allocation policy. */
private PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy;
/**
* Instantiates a new power vm allocation policy migration local regression.
*
* @param hostList the host list
* @param vmSelectionPolicy the vm selection policy
* @param schedulingInterval the scheduling interval
* @param fallbackVmAllocationPolicy the fallback vm allocation policy
* @param utilizationThreshold the utilization threshold
*/
public PowerVmAllocationPolicyMigrationLocalRegression(
List<? extends Host> hostList,
PowerVmSelectionPolicy vmSelectionPolicy,
double safetyParameter,
double schedulingInterval,
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy,
double utilizationThreshold) {
super(hostList, vmSelectionPolicy);
setSafetyParameter(safetyParameter);
setSchedulingInterval(schedulingInterval);
setFallbackVmAllocationPolicy(fallbackVmAllocationPolicy);
}
/**
* Instantiates a new power vm allocation policy migration local regression.
*
* @param hostList the host list
* @param vmSelectionPolicy the vm selection policy
* @param schedulingInterval the scheduling interval
* @param fallbackVmAllocationPolicy the fallback vm allocation policy
*/
public PowerVmAllocationPolicyMigrationLocalRegression(
List<? extends Host> hostList,
PowerVmSelectionPolicy vmSelectionPolicy,
double safetyParameter,
double schedulingInterval,
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy) {
super(hostList, vmSelectionPolicy);
setSafetyParameter(safetyParameter);
setSchedulingInterval(schedulingInterval);
setFallbackVmAllocationPolicy(fallbackVmAllocationPolicy);
}
/**
* Checks if is host over utilized.
*
* @param host the host
* @return true, if is host over utilized
*/
@Override
protected boolean isHostOverUtilized(PowerHost host) {
PowerHostUtilizationHistory _host = (PowerHostUtilizationHistory) host;
double[] utilizationHistory = _host.getUtilizationHistory();
int length = 10; // we use 10 to make the regression responsive enough to latest values
if (utilizationHistory.length < length) {
return getFallbackVmAllocationPolicy().isHostOverUtilized(host);
}
double[] utilizationHistoryReversed = new double[length];
for (int i = 0; i < length; i++) {
utilizationHistoryReversed[i] = utilizationHistory[length - i - 1];
}
double[] estimates = null;
try {
estimates = getParameterEstimates(utilizationHistoryReversed);
} catch (IllegalArgumentException e) {
return getFallbackVmAllocationPolicy().isHostOverUtilized(host);
}
double migrationIntervals = Math.ceil(getMaximumVmMigrationTime(_host) / getSchedulingInterval());
double predictedUtilization = estimates[0] + estimates[1] * (length + migrationIntervals);
predictedUtilization *= getSafetyParameter();
addHistoryEntry(host, predictedUtilization);
return predictedUtilization >= 1;
}
/**
* Gets the parameter estimates.
*
* @param utilizationHistoryReversed the utilization history reversed
* @return the parameter estimates
*/
protected double[] getParameterEstimates(double[] utilizationHistoryReversed) {
return MathUtil.getLoessParameterEstimates(utilizationHistoryReversed);
}
/**
* Gets the maximum vm migration time.
*
* @param host the host
* @return the maximum vm migration time
*/
protected double getMaximumVmMigrationTime(PowerHost host) {
int maxRam = Integer.MIN_VALUE;
for (Vm vm : host.getVmList()) {
int ram = vm.getRam();
if (ram > maxRam) {
maxRam = ram;
}
}
return maxRam / ((double) host.getBw() / (2 * 8000));
}
/**
* Sets the scheduling interval.
*
* @param schedulingInterval the new scheduling interval
*/
protected void setSchedulingInterval(double schedulingInterval) {
this.schedulingInterval = schedulingInterval;
}
/**
* Gets the scheduling interval.
*
* @return the scheduling interval
*/
protected double getSchedulingInterval() {
return schedulingInterval;
}
/**
* Sets the fallback vm allocation policy.
*
* @param fallbackVmAllocationPolicy the new fallback vm allocation policy
*/
public void setFallbackVmAllocationPolicy(
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy) {
this.fallbackVmAllocationPolicy = fallbackVmAllocationPolicy;
}
/**
* Gets the fallback vm allocation policy.
*
* @return the fallback vm allocation policy
*/
public PowerVmAllocationPolicyMigrationAbstract getFallbackVmAllocationPolicy() {
return fallbackVmAllocationPolicy;
}
public double getSafetyParameter() {
return safetyParameter;
}
public void setSafetyParameter(double safetyParameter) {
this.safetyParameter = safetyParameter;
}
}

View File

@@ -0,0 +1,86 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.List;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.util.MathUtil;
/**
* The Local Regression Robust (LRR) VM allocation policy.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerVmAllocationPolicyMigrationLocalRegressionRobust extends
PowerVmAllocationPolicyMigrationLocalRegression {
/**
* Instantiates a new power vm allocation policy migration local regression.
*
* @param hostList the host list
* @param vmSelectionPolicy the vm selection policy
* @param schedulingInterval the scheduling interval
* @param fallbackVmAllocationPolicy the fallback vm allocation policy
* @param utilizationThreshold the utilization threshold
*/
public PowerVmAllocationPolicyMigrationLocalRegressionRobust(
List<? extends Host> hostList,
PowerVmSelectionPolicy vmSelectionPolicy,
double safetyParameter,
double schedulingInterval,
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy,
double utilizationThreshold) {
super(
hostList,
vmSelectionPolicy,
safetyParameter,
schedulingInterval,
fallbackVmAllocationPolicy,
utilizationThreshold);
}
/**
* Instantiates a new power vm allocation policy migration local regression.
*
* @param hostList the host list
* @param vmSelectionPolicy the vm selection policy
* @param schedulingInterval the scheduling interval
* @param fallbackVmAllocationPolicy the fallback vm allocation policy
*/
public PowerVmAllocationPolicyMigrationLocalRegressionRobust(
List<? extends Host> hostList,
PowerVmSelectionPolicy vmSelectionPolicy,
double safetyParameter,
double schedulingInterval,
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy) {
super(hostList, vmSelectionPolicy, safetyParameter, schedulingInterval, fallbackVmAllocationPolicy);
}
/**
* Gets the parameter estimates.
*
* @param utilizationHistoryReversed the utilization history reversed
* @return the parameter estimates
*/
@Override
protected double[] getParameterEstimates(double[] utilizationHistoryReversed) {
return MathUtil.getRobustLoessParameterEstimates(utilizationHistoryReversed);
}
}

View File

@@ -0,0 +1,157 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.List;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.util.MathUtil;
/**
* The Median Absolute Deviation (MAD) VM allocation policy.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerVmAllocationPolicyMigrationMedianAbsoluteDeviation extends
PowerVmAllocationPolicyMigrationAbstract {
/** The safety parameter. */
private double safetyParameter = 0;
/** The fallback vm allocation policy. */
private PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy;
/**
* Instantiates a new power vm allocation policy migration mad.
*
* @param hostList the host list
* @param vmSelectionPolicy the vm selection policy
* @param safetyParameter the safety parameter
* @param utilizationThreshold the utilization threshold
*/
public PowerVmAllocationPolicyMigrationMedianAbsoluteDeviation(
List<? extends Host> hostList,
PowerVmSelectionPolicy vmSelectionPolicy,
double safetyParameter,
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy,
double utilizationThreshold) {
super(hostList, vmSelectionPolicy);
setSafetyParameter(safetyParameter);
setFallbackVmAllocationPolicy(fallbackVmAllocationPolicy);
}
/**
* Instantiates a new power vm allocation policy migration mad.
*
* @param hostList the host list
* @param vmSelectionPolicy the vm selection policy
* @param safetyParameter the safety parameter
*/
public PowerVmAllocationPolicyMigrationMedianAbsoluteDeviation(
List<? extends Host> hostList,
PowerVmSelectionPolicy vmSelectionPolicy,
double safetyParameter,
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy) {
super(hostList, vmSelectionPolicy);
setSafetyParameter(safetyParameter);
setFallbackVmAllocationPolicy(fallbackVmAllocationPolicy);
}
/**
* Checks if is host over utilized.
*
* @param _host the _host
* @return true, if is host over utilized
*/
@Override
protected boolean isHostOverUtilized(PowerHost host) {
PowerHostUtilizationHistory _host = (PowerHostUtilizationHistory) host;
double upperThreshold = 0;
try {
upperThreshold = 1 - getSafetyParameter() * getHostUtilizationMad(_host);
} catch (IllegalArgumentException e) {
return getFallbackVmAllocationPolicy().isHostOverUtilized(host);
}
addHistoryEntry(host, upperThreshold);
double totalRequestedMips = 0;
for (Vm vm : host.getVmList()) {
totalRequestedMips += vm.getCurrentRequestedTotalMips();
}
double utilization = totalRequestedMips / host.getTotalMips();
return utilization > upperThreshold;
}
/**
* Gets the host utilization mad.
*
* @param host the host
* @return the host utilization mad
*/
protected double getHostUtilizationMad(PowerHostUtilizationHistory host) throws IllegalArgumentException {
double[] data = host.getUtilizationHistory();
if (MathUtil.countNonZeroBeginning(data) >= 12) { // 12 has been suggested as a safe value
return MathUtil.mad(data);
}
throw new IllegalArgumentException();
}
/**
* Sets the safety parameter.
*
* @param safetyParameter the new safety parameter
*/
protected void setSafetyParameter(double safetyParameter) {
if (safetyParameter < 0) {
Log.printLine("The safety parameter cannot be less than zero. The passed value is: "
+ safetyParameter);
System.exit(0);
}
this.safetyParameter = safetyParameter;
}
/**
* Gets the safety parameter.
*
* @return the safety parameter
*/
protected double getSafetyParameter() {
return safetyParameter;
}
/**
* Sets the fallback vm allocation policy.
*
* @param fallbackVmAllocationPolicy the new fallback vm allocation policy
*/
public void setFallbackVmAllocationPolicy(
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy) {
this.fallbackVmAllocationPolicy = fallbackVmAllocationPolicy;
}
/**
* Gets the fallback vm allocation policy.
*
* @return the fallback vm allocation policy
*/
public PowerVmAllocationPolicyMigrationAbstract getFallbackVmAllocationPolicy() {
return fallbackVmAllocationPolicy;
}
}

View File

@@ -0,0 +1,85 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.List;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Vm;
/**
* The Static Threshold (THR) VM allocation policy.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerVmAllocationPolicyMigrationStaticThreshold extends PowerVmAllocationPolicyMigrationAbstract {
/** The utilization threshold. */
private double utilizationThreshold = 0.9;
/**
* Instantiates a new power vm allocation policy migration mad.
*
* @param hostList the host list
* @param vmSelectionPolicy the vm selection policy
* @param utilizationThreshold the utilization threshold
*/
public PowerVmAllocationPolicyMigrationStaticThreshold(
List<? extends Host> hostList,
PowerVmSelectionPolicy vmSelectionPolicy,
double utilizationThreshold) {
super(hostList, vmSelectionPolicy);
setUtilizationThreshold(utilizationThreshold);
}
/**
* Checks if is host over utilized.
*
* @param _host the _host
* @return true, if is host over utilized
*/
@Override
protected boolean isHostOverUtilized(PowerHost host) {
addHistoryEntry(host, getUtilizationThreshold());
double totalRequestedMips = 0;
for (Vm vm : host.getVmList()) {
totalRequestedMips += vm.getCurrentRequestedTotalMips();
}
double utilization = totalRequestedMips / host.getTotalMips();
return utilization > getUtilizationThreshold();
}
/**
* Sets the utilization threshold.
*
* @param utilizationThreshold the new utilization threshold
*/
protected void setUtilizationThreshold(double utilizationThreshold) {
this.utilizationThreshold = utilizationThreshold;
}
/**
* Gets the utilization threshold.
*
* @return the utilization threshold
*/
protected double getUtilizationThreshold() {
return utilizationThreshold;
}
}

View File

@@ -0,0 +1,53 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Vm;
/**
* This a simple class representing a simple VM allocation policy that does not perform any
* optimization of the VM allocation.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerVmAllocationPolicySimple extends PowerVmAllocationPolicyAbstract {
/**
* Instantiates a new power vm allocation policy simple.
*
* @param list the list
*/
public PowerVmAllocationPolicySimple(List<? extends Host> list) {
super(list);
}
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.VmAllocationPolicy#optimizeAllocation(java.util.List)
*/
@Override
public List<Map<String, Object>> optimizeAllocation(List<? extends Vm> vmList) {
// This policy does not optimize the VM allocation
return null;
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.Vm;
/**
* The class of an abstract VM selection policy.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public abstract class PowerVmSelectionPolicy {
/**
* Gets the vms to migrate.
*
* @param host the host
* @return the vms to migrate
*/
public abstract Vm getVmToMigrate(PowerHost host);
/**
* Gets the migratable vms.
*
* @param host the host
* @return the migratable vms
*/
protected List<PowerVm> getMigratableVms(PowerHost host) {
List<PowerVm> migratableVms = new ArrayList<PowerVm>();
for (PowerVm vm : host.<PowerVm> getVmList()) {
if (!vm.isInMigration()) {
migratableVms.add(vm);
}
}
return migratableVms;
}
}

View File

@@ -0,0 +1,160 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.util.MathUtil;
/**
* The Maximum Correlation (MC) VM selection policy.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPolicy {
/** The fallback policy. */
private PowerVmSelectionPolicy fallbackPolicy;
/**
* Instantiates a new power vm selection policy maximum correlation.
*
* @param fallbackPolicy the fallback policy
*/
public PowerVmSelectionPolicyMaximumCorrelation(final PowerVmSelectionPolicy fallbackPolicy) {
super();
setFallbackPolicy(fallbackPolicy);
}
/*
* (non-Javadoc)
*
* @see org.cloudbus.cloudsim.experiments.power.PowerVmSelectionPolicy#
* getVmsToMigrate(org.cloudbus .cloudsim.power.PowerHost)
*/
@Override
public Vm getVmToMigrate(final PowerHost host) {
List<PowerVm> migratableVms = getMigratableVms(host);
if (migratableVms.isEmpty()) {
return null;
}
List<Double> metrics = null;
try {
metrics = getCorrelationCoefficients(getUtilizationMatrix(migratableVms));
} catch (IllegalArgumentException e) { // the degrees of freedom must be greater than zero
return getFallbackPolicy().getVmToMigrate(host);
}
double maxMetric = Double.MIN_VALUE;
int maxIndex = 0;
for (int i = 0; i < metrics.size(); i++) {
double metric = metrics.get(i);
if (metric > maxMetric) {
maxMetric = metric;
maxIndex = i;
}
}
return migratableVms.get(maxIndex);
}
/**
* Gets the utilization matrix.
*
* @param vmList the host
* @return the utilization matrix
*/
protected double[][] getUtilizationMatrix(final List<PowerVm> vmList) {
int n = vmList.size();
int m = getMinUtilizationHistorySize(vmList);
double[][] utilization = new double[n][m];
for (int i = 0; i < n; i++) {
List<Double> vmUtilization = vmList.get(i).getUtilizationHistory();
for (int j = 0; j < vmUtilization.size(); j++) {
utilization[i][j] = vmUtilization.get(j);
}
}
return utilization;
}
/**
* Gets the min utilization history size.
*
* @param vmList the vm list
* @return the min utilization history size
*/
protected int getMinUtilizationHistorySize(final List<PowerVm> vmList) {
int minSize = Integer.MAX_VALUE;
for (PowerVm vm : vmList) {
int size = vm.getUtilizationHistory().size();
if (size < minSize) {
minSize = size;
}
}
return minSize;
}
/**
* Gets the correlation coefficients.
*
* @param data the data
* @return the correlation coefficients
*/
protected List<Double> getCorrelationCoefficients(final double[][] data) {
int n = data.length;
int m = data[0].length;
List<Double> correlationCoefficients = new LinkedList<Double>();
for (int i = 0; i < n; i++) {
double[][] x = new double[n - 1][m];
int k = 0;
for (int j = 0; j < n; j++) {
if (j != i) {
x[k++] = data[j];
}
}
// Transpose the matrix so that it fits the linear model
double[][] xT = new Array2DRowRealMatrix(x).transpose().getData();
// RSquare is the "coefficient of determination"
correlationCoefficients.add(MathUtil.createLinearRegression(xT,
data[i]).calculateRSquared());
}
return correlationCoefficients;
}
/**
* Gets the fallback policy.
*
* @return the fallback policy
*/
public PowerVmSelectionPolicy getFallbackPolicy() {
return fallbackPolicy;
}
/**
* Sets the fallback policy.
*
* @param fallbackPolicy the new fallback policy
*/
public void setFallbackPolicy(final PowerVmSelectionPolicy fallbackPolicy) {
this.fallbackPolicy = fallbackPolicy;
}
}

View File

@@ -0,0 +1,58 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.List;
import org.cloudbus.cloudsim.Vm;
/**
* The Minimum Migration Time (MMT) VM selection policy.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerVmSelectionPolicyMinimumMigrationTime extends PowerVmSelectionPolicy {
/*
* (non-Javadoc)
* @see
* org.cloudbus.cloudsim.experiments.power.PowerVmSelectionPolicy#getVmsToMigrate(org.cloudbus
* .cloudsim.power.PowerHost)
*/
@Override
public Vm getVmToMigrate(PowerHost host) {
List<PowerVm> migratableVms = getMigratableVms(host);
if (migratableVms.isEmpty()) {
return null;
}
Vm vmToMigrate = null;
double minMetric = Double.MAX_VALUE;
for (Vm vm : migratableVms) {
if (vm.isInMigration()) {
continue;
}
double metric = vm.getRam();
if (metric < minMetric) {
minMetric = metric;
vmToMigrate = vm;
}
}
return vmToMigrate;
}
}

View File

@@ -0,0 +1,59 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.List;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* The Minimum Utilization (MU) VM selection policy.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerVmSelectionPolicyMinimumUtilization extends PowerVmSelectionPolicy {
/*
* (non-Javadoc)
* @see
* org.cloudbus.cloudsim.experiments.power.PowerVmSelectionPolicy#getVmsToMigrate(org.cloudbus
* .cloudsim.power.PowerHost)
*/
@Override
public Vm getVmToMigrate(PowerHost host) {
List<PowerVm> migratableVms = getMigratableVms(host);
if (migratableVms.isEmpty()) {
return null;
}
Vm vmToMigrate = null;
double minMetric = Double.MAX_VALUE;
for (Vm vm : migratableVms) {
if (vm.isInMigration()) {
continue;
}
double metric = vm.getTotalUtilizationOfCpuMips(CloudSim.clock()) / vm.getMips();
if (metric < minMetric) {
minMetric = metric;
vmToMigrate = vm;
}
}
return vmToMigrate;
}
}

View File

@@ -0,0 +1,48 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.List;
import java.util.Random;
import org.cloudbus.cloudsim.Vm;
/**
* The Random Selection (RS) VM selection policy.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerVmSelectionPolicyRandomSelection extends PowerVmSelectionPolicy {
/*
* (non-Javadoc)
* @see
* org.cloudbus.cloudsim.experiments.power.PowerVmSelectionPolicy#getVmsToMigrate(org.cloudbus
* .cloudsim.power.PowerHost)
*/
@Override
public Vm getVmToMigrate(PowerHost host) {
List<PowerVm> migratableVms = getMigratableVms(host);
if (migratableVms.isEmpty()) {
return null;
}
int index = (new Random()).nextInt(migratableVms.size());
return migratableVms.get(index);
}
}

View File

@@ -0,0 +1,54 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.lists;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.lists.VmList;
/**
* PowerVmList is a collection of operations on lists of power-enabled VMs.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerVmList extends VmList {
/**
* Sort by cpu utilization.
*
* @param vmList the vm list
*/
public static <T extends Vm> void sortByCpuUtilization(List<T> vmList) {
Collections.sort(vmList, new Comparator<T>() {
@Override
public int compare(T a, T b) throws ClassCastException {
Double aUtilization = a.getTotalUtilizationOfCpuMips(CloudSim.clock());
Double bUtilization = b.getTotalUtilizationOfCpuMips(CloudSim.clock());
return bUtilization.compareTo(aUtilization);
}
});
}
}

View File

@@ -0,0 +1,39 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.models;
/**
* The PowerModel interface needs to be implemented in order to provide a model of power consumption
* depending on utilization for system components.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public interface PowerModel {
/**
* Get power consumption by the utilization percentage according to the power model.
*
* @param utilization the utilization
* @return power consumption
* @throws IllegalArgumentException the illegal argument exception
*/
double getPower(double utilization) throws IllegalArgumentException;
}

View File

@@ -0,0 +1,119 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.models;
/**
* The Class PowerModelCubic.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerModelCubic implements PowerModel {
/** The max power. */
private double maxPower;
/** The constant. */
private double constant;
/** The static power. */
private double staticPower;
/**
* Instantiates a new power model cubic.
*
* @param maxPower the max power
* @param staticPowerPercent the static power percent
*/
public PowerModelCubic(double maxPower, double staticPowerPercent) {
setMaxPower(maxPower);
setStaticPower(staticPowerPercent * maxPower);
setConstant((maxPower - getStaticPower()) / Math.pow(100, 3));
}
/*
* (non-Javadoc)
* @see gridsim.virtualization.power.PowerModel#getPower(double)
*/
@Override
public double getPower(double utilization) throws IllegalArgumentException {
if (utilization < 0 || utilization > 1) {
throw new IllegalArgumentException("Utilization value must be between 0 and 1");
}
if (utilization == 0) {
return 0;
}
return getStaticPower() + getConstant() * Math.pow(utilization * 100, 3);
}
/**
* Gets the max power.
*
* @return the max power
*/
protected double getMaxPower() {
return maxPower;
}
/**
* Sets the max power.
*
* @param maxPower the new max power
*/
protected void setMaxPower(double maxPower) {
this.maxPower = maxPower;
}
/**
* Gets the constant.
*
* @return the constant
*/
protected double getConstant() {
return constant;
}
/**
* Sets the constant.
*
* @param constant the new constant
*/
protected void setConstant(double constant) {
this.constant = constant;
}
/**
* Gets the static power.
*
* @return the static power
*/
protected double getStaticPower() {
return staticPower;
}
/**
* Sets the static power.
*
* @param staticPower the new static power
*/
protected void setStaticPower(double staticPower) {
this.staticPower = staticPower;
}
}

View File

@@ -0,0 +1,119 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.models;
/**
* The Class PowerModelLinear.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerModelLinear implements PowerModel {
/** The max power. */
private double maxPower;
/** The constant. */
private double constant;
/** The static power. */
private double staticPower;
/**
* Instantiates a new linear power model.
*
* @param maxPower the max power
* @param staticPowerPercent the static power percent
*/
public PowerModelLinear(double maxPower, double staticPowerPercent) {
setMaxPower(maxPower);
setStaticPower(staticPowerPercent * maxPower);
setConstant((maxPower - getStaticPower()) / 100);
}
/*
* (non-Javadoc)
* @see cloudsim.power.PowerModel#getPower(double)
*/
@Override
public double getPower(double utilization) throws IllegalArgumentException {
if (utilization < 0 || utilization > 1) {
throw new IllegalArgumentException("Utilization value must be between 0 and 1");
}
if (utilization == 0) {
return 0;
}
return getStaticPower() + getConstant() * utilization * 100;
}
/**
* Gets the max power.
*
* @return the max power
*/
protected double getMaxPower() {
return maxPower;
}
/**
* Sets the max power.
*
* @param maxPower the new max power
*/
protected void setMaxPower(double maxPower) {
this.maxPower = maxPower;
}
/**
* Gets the constant.
*
* @return the constant
*/
protected double getConstant() {
return constant;
}
/**
* Sets the constant.
*
* @param constant the new constant
*/
protected void setConstant(double constant) {
this.constant = constant;
}
/**
* Gets the static power.
*
* @return the static power
*/
protected double getStaticPower() {
return staticPower;
}
/**
* Sets the static power.
*
* @param staticPower the new static power
*/
protected void setStaticPower(double staticPower) {
this.staticPower = staticPower;
}
}

View File

@@ -0,0 +1,57 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.models;
/**
* The abstract class of power models created based on data from SPECpower benchmark:
* http://www.spec.org/power_ssj2008/
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public abstract class PowerModelSpecPower implements PowerModel {
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.power.models.PowerModel#getPower(double)
*/
@Override
public double getPower(double utilization) throws IllegalArgumentException {
if (utilization < 0 || utilization > 1) {
throw new IllegalArgumentException("Utilization value must be between 0 and 1");
}
if (utilization % 0.1 == 0) {
return getPowerData((int) (utilization * 10));
}
int utilization1 = (int) Math.floor(utilization * 10);
int utilization2 = (int) Math.ceil(utilization * 10);
double power1 = getPowerData(utilization1);
double power2 = getPowerData(utilization2);
double delta = (power2 - power1) / 10;
double power = power1 + delta * (utilization - (double) utilization1 / 10) * 100;
return power;
}
/**
* Gets the power data.
*
* @param index the index
* @return the power data
*/
protected abstract double getPowerData(int index);
}

View File

@@ -0,0 +1,40 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.models;
/**
* The power model of an HP ProLiant ML110 G3 (1 x [Pentium D930 3000 MHz, 2 cores], 4GB).
* http://www.spec.org/power_ssj2008/results/res2011q1/power_ssj2008-20110127-00342.html
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerModelSpecPowerHpProLiantMl110G3PentiumD930 extends PowerModelSpecPower {
/** The power. */
private final double[] power = { 105, 112, 118, 125, 131, 137, 147, 153, 157, 164, 169 };
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.power.models.PowerModelSpecPower#getPowerData(int)
*/
@Override
protected double getPowerData(int index) {
return power[index];
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.models;
/**
* The power model of an HP ProLiant ML110 G4 (1 x [Xeon 3040 1860 MHz, 2 cores], 4GB).
* http://www.spec.org/power_ssj2008/results/res2011q1/power_ssj2008-20110127-00342.html
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerModelSpecPowerHpProLiantMl110G4Xeon3040 extends PowerModelSpecPower {
/** The power. */
private final double[] power = { 86, 89.4, 92.6, 96, 99.5, 102, 106, 108, 112, 114, 117 };
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.power.models.PowerModelSpecPower#getPowerData(int)
*/
@Override
protected double getPowerData(int index) {
return power[index];
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.models;
/**
* The power model of an HP ProLiant ML110 G5 (1 x [Xeon 3075 2660 MHz, 2 cores], 4GB).
* http://www.spec.org/power_ssj2008/results/res2011q1/power_ssj2008-20110124-00339.html
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerModelSpecPowerHpProLiantMl110G5Xeon3075 extends PowerModelSpecPower {
/** The power. */
private final double[] power = { 93.7, 97, 101, 105, 110, 116, 121, 125, 129, 133, 135 };
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.power.models.PowerModelSpecPower#getPowerData(int)
*/
@Override
protected double getPowerData(int index) {
return power[index];
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.models;
/**
* The power model of an IBM server x3250 (1 x [Xeon X3470 2933 MHz, 4 cores], 8GB).
* http://www.spec.org/power_ssj2008/results/res2009q4/power_ssj2008-20091104-00213.html
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerModelSpecPowerIbmX3250XeonX3470 extends PowerModelSpecPower {
/** The power. */
private final double[] power = { 41.6, 46.7, 52.3, 57.9, 65.4, 73, 80.7, 89.5, 99.6, 105, 113 };
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.power.models.PowerModelSpecPower#getPowerData(int)
*/
@Override
protected double getPowerData(int index) {
return power[index];
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.models;
/**
* The power model of an IBM server x3250 (1 x [Xeon X3480 3067 MHz, 4 cores], 8GB).
* http://www.spec.org/power_ssj2008/results/res2010q4/power_ssj2008-20101001-00297.html
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerModelSpecPowerIbmX3250XeonX3480 extends PowerModelSpecPower {
/** The power. */
private final double[] power = { 42.3, 46.7, 49.7, 55.4, 61.8, 69.3, 76.1, 87, 96.1, 106, 113 };
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.power.models.PowerModelSpecPower#getPowerData(int)
*/
@Override
protected double getPowerData(int index) {
return power[index];
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.models;
/**
* The power model of an IBM server x3550 (2 x [Xeon X5670 2933 MHz, 6 cores], 12GB).
* http://www.spec.org/power_ssj2008/results/res2010q2/power_ssj2008-20100315-00239.html
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerModelSpecPowerIbmX3550XeonX5670 extends PowerModelSpecPower {
/** The power. */
private final double[] power = { 66, 107, 120, 131, 143, 156, 173, 191, 211, 229, 247 };
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.power.models.PowerModelSpecPower#getPowerData(int)
*/
@Override
protected double getPowerData(int index) {
return power[index];
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.models;
/**
* The power model of an IBM server x3550 (2 x [Xeon X5675 3067 MHz, 6 cores], 16GB).
* http://www.spec.org/power_ssj2008/results/res2011q2/power_ssj2008-20110406-00368.html
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class PowerModelSpecPowerIbmX3550XeonX5675 extends PowerModelSpecPower {
/** The power. */
private final double[] power = { 58.4, 98, 109, 118, 128, 140, 153, 170, 189, 205, 222 };
/*
* (non-Javadoc)
* @see org.cloudbus.cloudsim.power.models.PowerModelSpecPower#getPowerData(int)
*/
@Override
protected double getPowerData(int index) {
return power[index];
}
}

View File

@@ -0,0 +1,117 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.models;
/**
* The Class PowerModelSqrt.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerModelSqrt implements PowerModel {
/** The max power. */
private double maxPower;
/** The constant. */
private double constant;
/** The static power. */
private double staticPower;
/**
* Instantiates a new power model sqrt.
*
* @param maxPower the max power
* @param staticPowerPercent the static power percent
*/
public PowerModelSqrt(double maxPower, double staticPowerPercent) {
setMaxPower(maxPower);
setStaticPower(staticPowerPercent * maxPower);
setConstant((maxPower - getStaticPower()) / Math.sqrt(100));
}
/*
* (non-Javadoc)
* @see cloudsim.power.PowerModel#getPower(double)
*/
@Override
public double getPower(double utilization) throws IllegalArgumentException {
if (utilization < 0 || utilization > 1) {
throw new IllegalArgumentException("Utilization value must be between 0 and 1");
}
if (utilization == 0) {
return 0;
}
return getStaticPower() + getConstant() * Math.sqrt(utilization * 100);
}
/**
* Gets the max power.
*
* @return the max power
*/
protected double getMaxPower() {
return maxPower;
}
/**
* Sets the max power.
*
* @param maxPower the new max power
*/
protected void setMaxPower(double maxPower) {
this.maxPower = maxPower;
}
/**
* Gets the constant.
*
* @return the constant
*/
protected double getConstant() {
return constant;
}
/**
* Sets the constant.
*
* @param constant the new constant
*/
protected void setConstant(double constant) {
this.constant = constant;
}
/**
* Gets the static power.
*
* @return the static power
*/
protected double getStaticPower() {
return staticPower;
}
/**
* Sets the static power.
*
* @param staticPower the new static power
*/
protected void setStaticPower(double staticPower) {
this.staticPower = staticPower;
}
}

View File

@@ -0,0 +1,117 @@
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power.models;
/**
* The Class PowerModelSquare.
*
* If you are using any algorithms, policies or workload included in the power package, please cite
* the following paper:
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic Algorithms and Adaptive
* Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in
* Cloud Data Centers", Concurrency and Computation: Practice and Experience (CCPE), Volume 24,
* Issue 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerModelSquare implements PowerModel {
/** The max power. */
private double maxPower;
/** The constant. */
private double constant;
/** The static power. */
private double staticPower;
/**
* Instantiates a new power model square.
*
* @param maxPower the max power
* @param staticPowerPercent the static power percent
*/
public PowerModelSquare(double maxPower, double staticPowerPercent) {
setMaxPower(maxPower);
setStaticPower(staticPowerPercent * maxPower);
setConstant((maxPower - getStaticPower()) / Math.pow(100, 2));
}
/*
* (non-Javadoc)
* @see gridsim.virtualization.power.PowerModel#getPower(double)
*/
@Override
public double getPower(double utilization) throws IllegalArgumentException {
if (utilization < 0 || utilization > 1) {
throw new IllegalArgumentException("Utilization value must be between 0 and 1");
}
if (utilization == 0) {
return 0;
}
return getStaticPower() + getConstant() * Math.pow(utilization * 100, 2);
}
/**
* Gets the max power.
*
* @return the max power
*/
protected double getMaxPower() {
return maxPower;
}
/**
* Sets the max power.
*
* @param maxPower the new max power
*/
protected void setMaxPower(double maxPower) {
this.maxPower = maxPower;
}
/**
* Gets the constant.
*
* @return the constant
*/
protected double getConstant() {
return constant;
}
/**
* Sets the constant.
*
* @param constant the new constant
*/
protected void setConstant(double constant) {
this.constant = constant;
}
/**
* Gets the static power.
*
* @return the static power
*/
protected double getStaticPower() {
return staticPower;
}
/**
* Sets the static power.
*
* @param staticPower the new static power
*/
protected void setStaticPower(double staticPower) {
this.staticPower = staticPower;
}
}