Commit 06322462 authored by Anton Beloglazov's avatar Anton Beloglazov

Refactored power VM allocation policies, removed old policies, reimplemented the…

Refactored power VM allocation policies, removed old policies, reimplemented the DVFS and single threshold policies
parent 4529b632
......@@ -153,7 +153,7 @@ public class CloudSimExample2 {
}
catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
......
......@@ -152,7 +152,7 @@ public class CloudSimExample3 {
}
catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
......
......@@ -150,7 +150,7 @@ public class CloudSimExample4 {
}
catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
......
......@@ -154,7 +154,7 @@ public class CloudSimExample5 {
}
catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
......
......@@ -152,7 +152,7 @@ public class CloudSimExample6 {
catch (Exception e)
{
e.printStackTrace();
Log.printLine("Unwanted errors happen");
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
......
......@@ -190,7 +190,7 @@ public class CloudSimExample7 {
catch (Exception e)
{
e.printStackTrace();
Log.printLine("Unwanted errors happen");
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
......
......@@ -154,7 +154,7 @@ public class CloudSimExample8 {
catch (Exception e)
{
e.printStackTrace();
Log.printLine("Unwanted errors happen");
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
......
......@@ -146,7 +146,7 @@ public class NetworkExample1 {
}
catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
......
......@@ -171,7 +171,7 @@ public class NetworkExample2 {
}
catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
......
......@@ -177,7 +177,7 @@ public class NetworkExample3 {
}
catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
......
......@@ -138,7 +138,7 @@ public class NetworkExample4 {
}
catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
......
......@@ -127,10 +127,10 @@ public class CloudSim {
// set all the above entity IDs
cisId = cis.getId();
} catch (IllegalArgumentException s) {
Log.printLine("CloudSim.init(): Unwanted errors happen");
Log.printLine("CloudSim.init(): The simulation has been terminated due to an unexpected error");
Log.printLine(s.getMessage());
} catch (Exception e) {
Log.printLine("CloudSim.init(): Unwanted errors happen");
Log.printLine("CloudSim.init(): The simulation has been terminated due to an unexpected error");
Log.printLine(e.getMessage());
}
}
......
/*
* Title: CloudSim Toolkit Description: CloudSim (Cloud Simulation) Toolkit for Modeling and
* Simulation of Parallel and Distributed Systems such as Clusters and Clouds Licence: GPL -
* http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2008, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.HashMap;
......@@ -19,34 +11,29 @@ import org.cloudbus.cloudsim.VmAllocationPolicy;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* PowerVmAllocationPolicySingleThresholdFixed is an VMAllocationPolicy that chooses, as the host
* for a VM, the host with the least power increase due to utilization increase.
* The Class PowerVmAllocationPolicyAbstract.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 4.3
* @invariant $none
* @since Jan 5, 2012
*/
public class PowerVmAllocationPolicySimple extends VmAllocationPolicy {
public abstract class PowerVmAllocationPolicyAbstract extends VmAllocationPolicy {
/** The vm table. */
private Map<String, Host> vmTable;
private final Map<String, Host> vmTable = new HashMap<String, Host>();
/**
* Instantiates a new PowerVmAllocationPolicySimple.
* Instantiates a new power vm allocation policy abstract.
*
* @param hostList the host list
* @param list the list
*/
public PowerVmAllocationPolicySimple(List<? extends Host> hostList) {
super(hostList);
setVmTable(new HashMap<String, Host>());
public PowerVmAllocationPolicyAbstract(List<? extends Host> list) {
super(list);
}
/**
* Allocates a host for a given VM.
*
* @param vm VM specification
/*
* (non-Javadoc)
*
* @return $true if the host could be allocated; $false otherwise
* @see org.cloudbus.cloudsim.VmAllocationPolicy#allocateHostForVm(org.cloudbus.cloudsim.Vm)
*/
@Override
public boolean allocateHostForVm(Vm vm) {
......@@ -79,11 +66,10 @@ public class PowerVmAllocationPolicySimple extends VmAllocationPolicy {
}
/**
* Determines a host to allocate for the VM.
* Find host for vm.
*
* @param vm the vm
*
* @return the host
* @return the power host
*/
public PowerHost findHostForVm(Vm vm) {
for (PowerHost host : this.<PowerHost> getHostList()) {
......@@ -97,18 +83,7 @@ public class PowerVmAllocationPolicySimple extends VmAllocationPolicy {
/*
* (non-Javadoc)
*
* @see org.cloudbus.cloudsim.VmAllocationPolicy#optimizeAllocation(java.util.List)
*/
@Override
public List<Map<String, Object>> optimizeAllocation(List<? extends Vm> vmList) {
// This policy doesn't optimize the VM allocation
return null;
}
/**
* Releases the host used by a VM.
*
* @param vm the vm
* @see org.cloudbus.cloudsim.VmAllocationPolicy#deallocateHostForVm(org.cloudbus.cloudsim.Vm)
*/
@Override
public void deallocateHostForVm(Vm vm) {
......@@ -118,40 +93,26 @@ public class PowerVmAllocationPolicySimple extends VmAllocationPolicy {
}
}
/**
* Gets the host that is executing the given VM belonging to the given user.
*
* @param vm the vm
/*
* (non-Javadoc)
*
* @return the Host with the given vmID and userID; $null if not found
* @see org.cloudbus.cloudsim.VmAllocationPolicy#getHost(org.cloudbus.cloudsim.Vm)
*/
@Override
public Host getHost(Vm vm) {
return getVmTable().get(vm.getUid());
}
/**
* Gets the host that is executing the given VM belonging to the given user.
*
* @param vmId the vm id
* @param userId the user id
/*
* (non-Javadoc)
*
* @return the Host with the given vmID and userID; $null if not found
* @see org.cloudbus.cloudsim.VmAllocationPolicy#getHost(int, int)
*/
@Override
public Host getHost(int vmId, int userId) {
return getVmTable().get(Vm.getUid(userId, vmId));
}
/**
* Sets the vm table.
*
* @param vmTable the vm table
*/
public void setVmTable(Map<String, Host> vmTable) {
this.vmTable = vmTable;
}
/**
* Gets the vm table.
*
......
/*
* Title: CloudSim Toolkit Description: CloudSim (Cloud Simulation) Toolkit for Modeling and
* Simulation of Parallel and Distributed Systems such as Clusters and Clouds Licence: GPL -
* http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2008, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.ArrayList;
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.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* The Class PowerVmAllocationPolicyDoubleThresholdAbstract.
*/
public class PowerVmAllocationPolicyDoubleThresholdAbstract extends VmAllocationPolicySimple {
/** The hosts PEs. */
protected Map<String, Integer> hostsPes;
/** The hosts utilization. */
protected Map<Integer, Double> hostsUtilization;
/** The hosts memory. */
protected Map<Integer, Integer> hostsRam;
/** The hosts bw. */
protected Map<Integer, Long> hostsBw;
/** The old allocation. */
private List<Map<String, Object>> savedAllocation;
/** The utilization threshold lower. */
private double utilizationThresholdLower;
/** The utilization threshold upper. */
private double utilizationThresholdUpper;
/**
* Instantiates a new vM provisioner mpp.
*
* @param list the list
* @param utilizationThresholdLower the utilization threshold lower
* @param utilizationThresholdUpper the utilization threshold upper
*/
public PowerVmAllocationPolicyDoubleThresholdAbstract(
List<? extends PowerHost> list,
double utilizationThresholdLower,
double utilizationThresholdUpper) {
super(list);
setSavedAllocation(new ArrayList<Map<String, Object>>());
setUtilizationThresholdLower(utilizationThresholdLower);
setUtilizationThresholdUpper(utilizationThresholdUpper);
}
/**
* Determines a host to allocate for the VM.
*
* @param vm the vm
*
* @return the host
*/
public PowerHost findHostForVm(Vm vm) {
double minPower = Double.MAX_VALUE;
PowerHost allocatedHost = null;
for (PowerHost host : this.<PowerHost> getHostList()) {
if (host.isSuitableForVm(vm)) {
if (getMaxUtilizationAfterAllocation(host, vm) > getUtilizationThresholdUpper()) {
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;
}
/**
* Allocates a host for a given VM.
*
* @param vm VM specification
*
* @return $true if the host could be allocated; $false otherwise
*
* @pre $none
* @post $none
*/
@Override
public boolean allocateHostForVm(Vm vm) {
PowerHost allocatedHost = findHostForVm(vm);
if (allocatedHost != null && allocatedHost.vmCreate(vm)) { // if vm has been succesfully
// created in the host
getVmTable().put(vm.getUid(), allocatedHost);
Log.formatLine(
"%.2f: VM #" + vm.getId() + " has been allocated to the host #" + allocatedHost.getId()
+ "\n",
CloudSim.clock());
return true;
}
return false;
}
/**
* Releases the host used by a VM.
*
* @param vm the vm
*
* @pre $none
* @post none
*/
@Override
public void deallocateHostForVm(Vm vm) {
if (getVmTable().containsKey(vm.getUid())) {
PowerHost host = (PowerHost) getVmTable().remove(vm.getUid());
if (host != null) {
host.vmDestroy(vm);
}
}
}
/**
* 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) {
Log.printLine("optimizeAllocation() method must be overriden by a child class");
return null;
}
/**
* Save allocation.
*
* @param vmList the vm list
*/
protected void saveAllocation(List<? extends Vm> vmList) {
getSavedAllocation().clear();
for (Vm vm : vmList) {
Map<String, Object> map = new HashMap<String, Object>();
// Log.printLine("Trying to save VM #" + vm.getId());
map.put("vm", vm);
map.put("host", vm.getHost());
getSavedAllocation().add(map);
// we do not destroy current allocation
// vm.getHost().vmDestroy(vm);
// getVmTable().remove(vm.getUid());
}
}
/**
* Restore allocation.
*
* @param vmsToRestore the vms to restore
* @param list
*/
protected void restoreAllocation(List<Vm> vmsToRestore, List<Host> hostList) {
// getVmTable().clear();
for (Host host : hostList) {
host.vmDestroyAll();
host.reallocateMigratingInVms();
}
/*
* for (Map<String, Object> map : getSavedAllocation()) { //Vm vm = (Vm) map.get("vm");
* PowerHost host = (PowerHost) map.get("host"); //PowerHost host = (PowerHost)
* vm.getHost(); if (host != null) { host.vmDestroyAll(); // vm.getHost().vmDestroy(vm); }
* //PowerHost host = (PowerHost) map.get("host"); //host.vmDestroy(vm);
* //host.vmDestroyAll(); }
*/
for (Map<String, Object> map : getSavedAllocation()) {
Vm vm = (Vm) map.get("vm");
PowerHost host = (PowerHost) map.get("host");
// Log.printLine("Trying to restore VM #" + vm.getId() + " on host #" + host.getId());
if (!vmsToRestore.contains(vm)) {
// Log.printLine("VM #" + vm.getVmId() +
// " skipped because it's not in the toRestore list");
continue;
}
if (!host.vmCreate(vm)) {
Log.printLine("failed");
}
getVmTable().put(vm.getUid(), host);
Log.printLine("Restored VM #" + vm.getId() + " on host #" + host.getId());
// host.vmDestroy(vm);
// if (!host.vmCreate(vm)) {
// host.vmCreateBestEffort(vm);
// }
// 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) {
List<Double> allocatedMipsForVm = null;
PowerHost allocatedHost = (PowerHost) vm.getHost();
if (allocatedHost != null) {
allocatedMipsForVm = allocatedHost.getAllocatedMipsForVm(vm);
}
if (!host.allocatePesForVm(vm, vm.getCurrentRequestedMips())) {
return -1;
}
double power = host.getPower();
host.deallocatePesForVm(vm);
if (allocatedHost != null && allocatedMipsForVm != null) {
vm.getHost().allocatePesForVm(vm, allocatedMipsForVm);
}
return power;
}
/**
* Gets the power after allocation.
*
* @param host the host
* @param vm the vm
*
* @return the power after allocation
*/
protected double getMaxUtilizationAfterAllocation(PowerHost host, Vm vm) {
List<Double> allocatedMipsForVm = null;
PowerHost allocatedHost = (PowerHost) vm.getHost();
if (allocatedHost != null) {
allocatedMipsForVm = vm.getHost().getAllocatedMipsForVm(vm);
}
if (!host.allocatePesForVm(vm, vm.getCurrentRequestedMips())) {
return -1;
}
double maxUtilization = host.getMaxUtilizationAmongVmsPes(vm);
host.deallocatePesForVm(vm);
if (allocatedHost != null && allocatedMipsForVm != null) {
vm.getHost().allocatePesForVm(vm, allocatedMipsForVm);
}
return maxUtilization;
}
/**
* Gets the saved allocation.
*
* @return the saved allocation
*/
protected List<Map<String, Object>> getSavedAllocation() {
return savedAllocation;
}
/**
* Sets the saved allocation.
*
* @param savedAllocation the saved allocation
*/
protected void setSavedAllocation(List<Map<String, Object>> savedAllocation) {
this.savedAllocation = savedAllocation;
}
/**
* Sets the utilization threshold lower.
*
* @param utilizationThresholdLower the new utilization threshold lower
*/
public void setUtilizationThresholdLower(double utilizationThresholdLower) {
this.utilizationThresholdLower = utilizationThresholdLower;
}
/**
* Gets the utilization threshold lower.
*
* @return the utilization threshold lower
*/
public double getUtilizationThresholdLower() {
return utilizationThresholdLower;
}
/**
* Sets the utilization threshold upper.
*
* @param utilizationThresholdUpper the new utilization threshold upper
*/
public void setUtilizationThresholdUpper(double utilizationThresholdUpper) {
this.utilizationThresholdUpper = utilizationThresholdUpper;
}
/**
* Gets the utilization threshold upper.
*
* @return the utilization threshold upper
*/
public double getUtilizationThresholdUpper() {
return utilizationThresholdUpper;
}
}
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 DVFS VM allocation policy. The actual application of DVFS
* (adjustment of the host's power consumption) happens in the PowerDatacenter class.
*
* @author Anton Beloglazov
* @since Jan 5, 2012
*
*/
public class PowerVmAllocationPolicyDvfs extends PowerVmAllocationPolicyAbstract {
/**
* Instantiates a new power vm allocation policy dvfs.
*
* @param list the list
*/
public PowerVmAllocationPolicyDvfs(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 doesn't optimize the VM allocation
return null;
}
}
......@@ -19,7 +19,7 @@ import org.cloudbus.cloudsim.util.ExecutionTimeMeasurer;
/**
* The Class PowerVmAllocationPolicyMigrationAbstract.
*/
public abstract class PowerVmAllocationPolicyMigrationAbstract extends PowerVmAllocationPolicySimple {
public abstract class PowerVmAllocationPolicyMigrationAbstract extends PowerVmAllocationPolicyAbstract {
/** The vm selection policy. */
private PowerVmSelectionPolicy vmSelectionPolicy;
......@@ -27,9 +27,6 @@ public abstract class PowerVmAllocationPolicyMigrationAbstract extends PowerVmAl
/** The saved allocation. */
private final List<Map<String, Object>> savedAllocation = new ArrayList<Map<String, Object>>();
/** The utilization threshold. */
private double utilizationThreshold = 0.9;
/** The utilization history. */
private final Map<Integer, List<Double>> utilizationHistory = new HashMap<Integer, List<Double>>();
......@@ -64,21 +61,6 @@ public abstract class PowerVmAllocationPolicyMigrationAbstract extends PowerVmAl
setVmSelectionPolicy(vmSelectionPolicy);
}
/**
* Instantiates a new power vm allocation policy migration abstract.
*
* @param hostList the host list
* @param vmSelectionPolicy the vm selection policy
* @param utilizationThreshold the utilization threshold
*/
public PowerVmAllocationPolicyMigrationAbstract(
List<? extends Host> hostList,
PowerVmSelectionPolicy vmSelectionPolicy,
double utilizationThreshold) {
this(hostList, vmSelectionPolicy);
setUtilizationThreshold(utilizationThreshold);
}
/**
* Optimize allocation of the VMs according to current utilization.
*
......@@ -130,28 +112,15 @@ public abstract class PowerVmAllocationPolicyMigrationAbstract extends PowerVmAl
List<PowerHostUtilizationHistory> overUtilizedHosts) {
List<Map<String, Object>> migrationMap = new LinkedList<Map<String, Object>>();
List<PowerHost> switchedOffHosts = getSwitchedOffHosts();
Set<PowerHost> excludedHostsForFindingUnderUtilizedHost = new HashSet<PowerHost>(); // over-utilized
// hosts
// +
// hosts
// that
// are
// selected
// to
// migrate
// VMs
// to
// from
// over-utilized
// hosts
// 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));
Set<PowerHost> excludedHostsForFindingNewVmPlacement = new HashSet<PowerHost>(); // over-utilized
// +
// under-utilized
// hosts
// over-utilized + under-utilized hosts
Set<PowerHost> excludedHostsForFindingNewVmPlacement = new HashSet<PowerHost>();
excludedHostsForFindingNewVmPlacement.addAll(overUtilizedHosts);
excludedHostsForFindingNewVmPlacement.addAll(switchedOffHosts);
......@@ -188,9 +157,6 @@ public abstract class PowerVmAllocationPolicyMigrationAbstract extends PowerVmAl
List<Map<String, Object>> newVmPlacement = getNewVmPlacementFromUnderUtilizedHost(
vmsToMigrateFromUnderUtilizedHost,
excludedHostsForFindingNewVmPlacement);
// if (newVmPlacement.isEmpty()) {
// break;
// }
excludedHostsForFindingUnderUtilizedHost.addAll(extractHostListFromMigrationMap(newVmPlacement));
......@@ -268,12 +234,11 @@ public abstract class PowerVmAllocationPolicyMigrationAbstract extends PowerVmAl
return isHostOverUtilizedAfterAllocation;
}
/*
* (non-Javadoc)
/**
* Find host for vm.
*
* @see
* org.cloudbus.cloudsim.experiments.power.PowerVmAllocationPolicySimple#findHostForVm(org.cloudbus
* .cloudsim.Vm)
* @param vm the vm
* @return the power host
*/
@Override
public PowerHost findHostForVm(Vm vm) {
......@@ -325,6 +290,13 @@ public abstract class PowerVmAllocationPolicyMigrationAbstract extends PowerVmAl
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) {
......@@ -567,14 +539,8 @@ public abstract class PowerVmAllocationPolicyMigrationAbstract extends PowerVmAl
double hostUtilizationMips = host.getUtilizationOfCpuMips();
for (Vm vm2 : host.getVmList()) {
if (host.getVmsMigratingIn().contains(vm2)) {
hostUtilizationMips += host.getTotalAllocatedMipsForVm(vm2) * 0.9 / 0.1; // calculate
// additional
// potential
// CPU
// usage
// of a
// migrating
// in VM
// calculate additional potential CPU usage of a migrating in VM
hostUtilizationMips += host.getTotalAllocatedMipsForVm(vm2) * 0.9 / 0.1;
}
}
......@@ -592,24 +558,6 @@ public abstract class PowerVmAllocationPolicyMigrationAbstract extends PowerVmAl
return savedAllocation;
}
/**
* 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;
}
/**
* Sets the vm selection policy.
*
......
......@@ -33,7 +33,7 @@ public class PowerVmAllocationPolicyMigrationInterQuartileRange extends
double safetyParameter,
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy,
double utilizationThreshold) {
super(hostList, vmSelectionPolicy, utilizationThreshold);
super(hostList, vmSelectionPolicy);
setSafetyParameter(safetyParameter);
setFallbackVmAllocationPolicy(fallbackVmAllocationPolicy);
}
......
......@@ -36,7 +36,7 @@ public class PowerVmAllocationPolicyMigrationLocalRegression extends PowerVmAllo
double schedulingInterval,
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy,
double utilizationThreshold) {
super(hostList, vmSelectionPolicy, utilizationThreshold);
super(hostList, vmSelectionPolicy);
setSafetyParameter(safetyParameter);
setSchedulingInterval(schedulingInterval);
setFallbackVmAllocationPolicy(fallbackVmAllocationPolicy);
......
......@@ -33,7 +33,7 @@ public class PowerVmAllocationPolicyMigrationMedianAbsoluteDeviation extends
double safetyParameter,
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy,
double utilizationThreshold) {
super(hostList, vmSelectionPolicy, utilizationThreshold);
super(hostList, vmSelectionPolicy);
setSafetyParameter(safetyParameter);
setFallbackVmAllocationPolicy(fallbackVmAllocationPolicy);
}
......
......@@ -35,7 +35,7 @@ public class PowerVmAllocationPolicyMigrationMedianAbsoluteDeviation2 extends
double safetyParameter,
PowerVmAllocationPolicyMigrationAbstract fallbackVmAllocationPolicy,
double utilizationThreshold) {
super(hostList, vmSelectionPolicy, utilizationThreshold);
super(hostList, vmSelectionPolicy);
setSafetyParameter(safetyParameter);
setFallbackVmAllocationPolicy(fallbackVmAllocationPolicy);
}
......
......@@ -8,7 +8,10 @@ import org.cloudbus.cloudsim.Vm;
/**
* The Class PowerVmAllocationPolicyMigrationThresholds.
*/
public class PowerVmAllocationPolicyMigrationThresholds extends PowerVmAllocationPolicyMigrationAbstract {
public class PowerVmAllocationPolicyMigrationStaticThreshold extends PowerVmAllocationPolicyMigrationAbstract {
/** The utilization threshold. */
private double utilizationThreshold = 0.9;
/**
* Instantiates a new power vm allocation policy migration mad.
......@@ -17,11 +20,12 @@ public class PowerVmAllocationPolicyMigrationThresholds extends PowerVmAllocatio
* @param vmSelectionPolicy the vm selection policy
* @param utilizationThreshold the utilization threshold
*/
public PowerVmAllocationPolicyMigrationThresholds(
public PowerVmAllocationPolicyMigrationStaticThreshold(
List<? extends Host> hostList,
PowerVmSelectionPolicy vmSelectionPolicy,
double utilizationThreshold) {
super(hostList, vmSelectionPolicy, utilizationThreshold);
super(hostList, vmSelectionPolicy);
setUtilizationThreshold(utilizationThreshold);
}
/**
......@@ -41,4 +45,22 @@ public class PowerVmAllocationPolicyMigrationThresholds extends PowerVmAllocatio
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;
}
}
/*
* Title: CloudSim Toolkit Description: CloudSim (Cloud Simulation) Toolkit for Modeling and
* Simulation of Clouds Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2010, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.ArrayList;
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.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.power.lists.PowerVmList;
/**
* PowerVmAllocationPolicySingleThreshold is an VMAllocationPolicy that chooses a host with the
* least power increase due to utilization increase caused by the VM allocation.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.0
*/
public class PowerVmAllocationPolicySingleThreshold extends VmAllocationPolicySimple {
/** The hosts PEs. */
protected Map<String, Integer> hostsPes;
/** The hosts utilization. */
protected Map<Integer, Double> hostsUtilization;
/** The hosts memory. */
protected Map<Integer, Integer> hostsRam;
/** The hosts bw. */
protected Map<Integer, Long> hostsBw;
/** The old allocation. */
private List<Map<String, Object>> savedAllocation;
/** The utilization threshold. */
private double utilizationThreshold;
/**
* Instantiates a new vM provisioner mpp.
*
* @param list the list
* @param utilizationThreshold the utilization bound
*/
public PowerVmAllocationPolicySingleThreshold(List<? extends PowerHost> list, double utilizationThreshold) {
super(list);
setSavedAllocation(new ArrayList<Map<String, Object>>());
setUtilizationThreshold(utilizationThreshold);
}
/**
* Determines a host to allocate for the VM.
*
* @param vm the vm
*
* @return the host
*/
public PowerHost findHostForVm(Vm vm) {
double minPower = Double.MAX_VALUE;
PowerHost allocatedHost = null;
for (PowerHost host : this.<PowerHost> getHostList()) {
if (host.isSuitableForVm(vm)) {
if (getMaxUtilizationAfterAllocation(host, vm) > getUtilizationThreshold()) {
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;
}
/**
* Allocates a host for a given VM.
*
* @param vm VM specification
*
* @return $true if the host could be allocated; $false otherwise
*
* @pre $none
* @post $none
*/
@Override
public boolean allocateHostForVm(Vm vm) {
PowerHost allocatedHost = findHostForVm(vm);
if (allocatedHost != null && allocatedHost.vmCreate(vm)) { // if vm has been succesfully
// created in the host
getVmTable().put(vm.getUid(), allocatedHost);
Log.formatLine(
"%.2f: VM #" + vm.getId() + " has been allocated to the host #" + allocatedHost.getId()
+ "\n",
CloudSim.clock());
return true;
}
return false;
}
/**
* Releases the host used by a VM.
*
* @param vm the vm
*
* @pre $none
* @post none
*/
@Override
public void deallocateHostForVm(Vm vm) {
if (getVmTable().containsKey(vm.getUid())) {
PowerHost host = (PowerHost) getVmTable().remove(vm.getUid());
if (host != null) {
host.vmDestroy(vm);
}
}
}
/**
* Optimize allocation of the VMs according to current utilization.
*
* @param vmList the vm list
* @param utilizationThreshold the utilization bound
*
* @return the array list< hash map< string, object>>
*/
@Override
public List<Map<String, Object>> optimizeAllocation(List<? extends Vm> vmList) {
List<Map<String, Object>> migrationMap = new ArrayList<Map<String, Object>>();
if (vmList.isEmpty()) {
return migrationMap;
}
saveAllocation(vmList);
List<Vm> vmsToRestore = new ArrayList<Vm>();
vmsToRestore.addAll(vmList);
List<Vm> vmsToMigrate = new ArrayList<Vm>();
for (Vm vm : vmList) {
if (vm.isInMigration()) {
continue;
}
vmsToMigrate.add(vm);
vm.getHost().vmDestroy(vm);
}
PowerVmList.sortByCpuUtilization(vmsToMigrate);
for (PowerHost host : this.<PowerHost> getHostList()) {
host.reallocateMigratingInVms();
}
for (Vm vm : vmsToMigrate) {
PowerHost oldHost = (PowerHost) getVmTable().get(vm.getUid());
PowerHost allocatedHost = findHostForVm(vm);
if (allocatedHost != null && allocatedHost.getId() != oldHost.getId()) {
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);
}
}
restoreAllocation(vmsToRestore, getHostList());
return migrationMap;
}
/**
* Save allocation.
*
* @param vmList the vm list
*/
protected void saveAllocation(List<? extends Vm> vmList) {
getSavedAllocation().clear();
for (Vm vm : vmList) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("vm", vm);
map.put("host", vm.getHost());
getSavedAllocation().add(map);
}
}
/**
* Restore allocation.
*
* @param vmsToRestore the vms to restore
*/
protected void restoreAllocation(List<Vm> vmsToRestore, List<Host> hostList) {
for (Host host : hostList) {
host.vmDestroyAll();
host.reallocateMigratingInVms();
}
for (Map<String, Object> map : getSavedAllocation()) {
Vm vm = (Vm) map.get("vm");
PowerHost host = (PowerHost) map.get("host");
if (!vmsToRestore.contains(vm)) {
continue;
}
if (!host.vmCreate(vm)) {
Log.printLine("Something is wrong, the VM can's be restored");
System.exit(0);
}
getVmTable().put(vm.getUid(), host);
Log.printLine("Restored VM #" + vm.getId() + " on host #" + host.getId());
}
}
/**
* 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) {
List<Double> allocatedMipsForVm = null;
PowerHost allocatedHost = (PowerHost) vm.getHost();
if (allocatedHost != null) {
allocatedMipsForVm = allocatedHost.getAllocatedMipsForVm(vm);
}
if (!host.allocatePesForVm(vm, vm.getCurrentRequestedMips())) {
return -1;
}
double power = host.getPower();
host.deallocatePesForVm(vm);
if (allocatedHost != null && allocatedMipsForVm != null) {
vm.getHost().allocatePesForVm(vm, allocatedMipsForVm);
}
return power;
}
/**
* Gets the power after allocation.
*
* @param host the host
* @param vm the vm
*
* @return the power after allocation
*/
protected double getMaxUtilizationAfterAllocation(PowerHost host, Vm vm) {
List<Double> allocatedMipsForVm = null;
PowerHost allocatedHost = (PowerHost) vm.getHost();
if (allocatedHost != null) {
allocatedMipsForVm = vm.getHost().getAllocatedMipsForVm(vm);
}
if (!host.allocatePesForVm(vm, vm.getCurrentRequestedMips())) {
return -1;
}
double maxUtilization = host.getMaxUtilizationAmongVmsPes(vm);
host.deallocatePesForVm(vm);
if (allocatedHost != null && allocatedMipsForVm != null) {
vm.getHost().allocatePesForVm(vm, allocatedMipsForVm);
}
return maxUtilization;
}
/**
* Gets the saved allocation.
*
* @return the saved allocation
*/
protected List<Map<String, Object>> getSavedAllocation() {
return savedAllocation;
}
/**
* Sets the saved allocation.
*
* @param savedAllocation the saved allocation
*/
protected void setSavedAllocation(List<Map<String, Object>> savedAllocation) {
this.savedAllocation = savedAllocation;
}
/**
* Gets the utilization bound.
*
* @return the utilization bound
*/
protected double getUtilizationThreshold() {
return utilizationThreshold;
}
/**
* Sets the utilization bound.
*
* @param utilizationThreshold the new utilization bound
*/
protected void setUtilizationThreshold(double utilizationThreshold) {
this.utilizationThreshold = utilizationThreshold;
}
}
/*
* Title: CloudSim Toolkit Description: CloudSim (Cloud Simulation) Toolkit for Modeling and
* Simulation of Parallel and Distributed Systems such as Clusters and Clouds Licence: GPL -
* http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2008, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim.power;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.power.lists.PowerVmList;
// TODO: rewrite this as a child of PolicyMigrationAbstract, remove doubleThresholdAbstract, single
// threshold and policy simple
/**
* PowerVmAllocationPolicySingleThresholdFixed is an VMAllocationPolicy that chooses, as the host
* for a VM, the host with the least power increase due to utilization increase.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 4.3
* @invariant $none
*/
public class PowerVmAllocationPolicySingleThresholdFixed extends
PowerVmAllocationPolicyDoubleThresholdAbstract {
/**
* Instantiates a new vM provisioner mpp.
*
* @param list the list
* @param utilizationThreshold the utilization bound
*/
public PowerVmAllocationPolicySingleThresholdFixed(
List<? extends PowerHost> list,
double utilizationThreshold) {
super(list, 0, utilizationThreshold);
}
/**
* Optimize allocation of the VMs according to current utilization.
*
* @param vmList the vm list
* @param utilizationThreshold the utilization bound
*
* @return the array list< hash map< string, object>>
*/
@Override
public List<Map<String, Object>> optimizeAllocation(List<? extends Vm> vmList) {
List<Map<String, Object>> migrationMap = new ArrayList<Map<String, Object>>();
if (vmList.isEmpty()) {
return migrationMap;
}
saveAllocation(vmList);
List<Vm> vmsToRestore = new ArrayList<Vm>();
vmsToRestore.addAll(vmList);
List<Vm> vmTmpList = new ArrayList<Vm>();
vmTmpList.addAll(vmList);
PowerVmList.sortByCpuUtilization(vmTmpList);
for (PowerHost host : this.<PowerHost> getHostList()) {
// host.vmDestroyAll();
host.reallocateMigratingInVms();
}
for (Vm vm : vmTmpList) {
// Log.printLine("VM #" + vm.getId() + " utilization: " + String.format("%.2f;",
// vm.getTotalUtilization(CloudSim.clock()) * 100));
if (vm.isInMigration()) {
continue;
}
/**
* TODO: some VMs are still not migrated to the destination but, but migration takes
* long time and before the end new optimization happens. Some new Vms are allocated to
* that host, because there is no knowledge that some VMs are being migrated to that
* host. Therefore, some allocations fail.
*/
PowerHost oldHost = (PowerHost) getVmTable().get(vm.getUid());
// if (oldHost.getId() == 375 && vm.getId() == 383) {
// Log.printLine("found");
// }
// PowerHost oldHost = vm.getHost();
PowerHost allocatedHost = findHostForVm(vm);
// if (allocatedHost.getId() == 235 && vm.getId() == 383) {
// Log.printLine("found");
// }
if (allocatedHost != null) {
// if (vm.getId() == 60 && allocatedHost.getId() == 51) {
// Log.printLine(vm.getId());
// }
Log.printLine("VM #" + vm.getId() + " allocated to host #" + allocatedHost.getId());
allocatedHost.vmCreate(vm);
if (allocatedHost.getId() != oldHost.getId()) {
Map<String, Object> migrate = new HashMap<String, Object>();
migrate.put("vm", vm);
migrate.put("host", allocatedHost);
migrationMap.add(migrate);
// getVmTable().put(vm.getUid(), allocatedHost);
// vmsToRestore.remove(vm);
// Log.printLine("Skip restore of VM #" + vm.getId());
}
}
}
restoreAllocation(vmsToRestore, getHostList());
return migrationMap;
}
}
......@@ -147,7 +147,7 @@ public class TimeSharedProblemDetector {
Log.printLine("CloudSimExample1 finished!");
} catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment