Unverified Commit c7aa88c9 authored by Manoel Campos's avatar Manoel Campos
Browse files

Closes #45



Redesigns Power Module to enable any Host and VM to have power capacity.
Enables power-aware simulations using regular classes such as
`DatacenterSimple`, `HostSimple` and `VmSimple`.
This way, it automatically allows creating simulations that are both
network- and power-aware by using the network versions of such classes.

- Merges PowerDatacenter into the DatacenterSimple and removes the first one.
  Removes useless prints and code.
- Adds PowerSupply interface to concentrate all power consumption data
  and operations, enabling any Host to get such an information,
  including the PowerModel.
- Merges the PowerHost into the HostSimple and removes the first one.
- Adds VmUtilizationHistory class to store resource utilization history
  by a given VM.
- Removes PowerVm and adds an attribute of this class
  inside the Vm, in order to store utilization data.
  The VmUtilizationHistory.enabled
  attribute allows enabling/disabling the data collection
  (which is disabled by default to save memory)
- Moves StateHistory from HostDynamicWorkloadSimple to HostSimple
  and adds attribute stateHistoryEnabled to allow
  enabling or disabling collection and storage of such states
  (it is disabled by default).
- Renamed package org.cloudbus.cloudsim.allocationpolicies.power to
  org.cloudbus.cloudsim.allocationpolicies.migration and removed
  the prefix Power from its classes and interfaces, since these
  allocation policies aren't used just for power-aware simulations
  anymore, but to enable VM migrations in general.
- Refactors VmAllocationPolicy implementations, mainly
  the VmAllocationPolicyAbstract and VmAllocationPolicySimple.
  Code duplication between different classes was fixed.
  Methods were moved to upper levels to provide a common
  implementation for several classes.
  Changed the method `Host findHostForVm(final Vm vm)
  to `Optional<Host> findHostForVm(final Vm vm)`, making it
  to return an Optional to explicitly indicate that a suitable Host
  may not be found for a given VM.
  The method was defined as protected abstract in the
  VmAllocationPolicyAbstract and it's the single method
  initially required to be implemented by subclasses of
  VmAllocationPolicyAbstract.
  These changes pave the way to close issue #76.
- Refactors migration examples and prints CPU utilization and
  power usage in MigrationExample2_PowerUsage.
- Exchanges all references from PowerVm to VmSimple
- Exchanged all references from PowerHost to HostSimple
- Exchanged all references from PowerDatacenter to DatacenterSimple
Signed-off-by: default avatarManoel Campos <manoelcampos@gmail.com>
parent 1dba262e
......@@ -5,6 +5,29 @@ Lists the main changes in the project.
## [Current Development Version]
- xxx
## [2.0.0] - 2018-04-20
- PowerVm class was removed and its methods were moved to a new VmUtilizationHistory class.
The Vm now has an attribute VmUtilizationHistory that enables collecting CPU utilization
data. The VmUtilizationHistory.enabled is set by default to false.
This way, the user have to manually enable the history to start collecting utilization
data. It was disabled by default to reduce memory usage.
- PowerHostUtilizationHistory class was removed and its single method getUtilizationHistory
was moved to the PowerHost. Since the method gets the history from VMs, the host
doesn't store any data. The VM utilization history must be enabled to allow
getting such data (as describe above).
- PowerHost class removed and its methods moved to Host.
A PowerSupply interface was introduced to group power
consumption data (including a PowerModel).
This way, any Host can extract power consumption data.
It's just required a PowerModel to be set in the
PowerSupply.
- Removes PowerVmAllocationPolicySimple because it was doing nothing
than other policies weren't doing.
## [1.2.3] - 2017-06-05
### Added / Changed
......
......@@ -57,6 +57,7 @@ CloudSim Plus provides a lot of exclusive features, from the most basic ones to
1. It is easier to use. A complete and easy-to-understand simulation scenario can be built in few lines of code. Check the [Examples Section](#a-minimal-and-complete-simulation-example);
1. [Vertical VM Scaling](/cloudsim-plus-examples/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingExample.java) that performs on-demand up and down allocation of VM resources such as Ram, Bandwidth and PEs (CPUs) ([#7](https://github.com/manoelcampos/cloudsim-plus/issues/7));
1. [Horizontal VM scaling](/cloudsim-plus-examples/src/main/java/org/cloudsimplus/examples/autoscaling/LoadBalancerByHorizontalVmScalingExample.java), allowing dynamic creation of VMs according to an overload condition. Such a condition is defined by a predicate that checks different VM resources usage such as CPU, RAM or BW ([#41](https://github.com/manoelcampos/cloudsim-plus/issues/41));
1. Enables power-aware simulations using regular classes such as `DatacenterSimple`, `HostSimple` and `VmSimple`. This way, it automatically enables creating simulations that are both network- and power-aware by using the network version of such classes ([#45](https://github.com/manoelcampos/cloudsim-plus/issues/45));
1. [Parallel execution of simulations](/cloudsim-plus-examples/src/main/java/org/cloudsimplus/examples/ParallelSimulationsExample.java), allowing several simulations to be run simultaneously, in a isolated way, inside a multi-core computer ([#38](https://github.com/manoelcampos/cloudsim-plus/issues/38));
1. Delay creation of submitted VMs and [Cloudlets](/cloudsim-plus-examples/src/main/java/org/cloudsimplus/examples/DynamicCloudletsArrival1.java), enabling simulation of dynamic arrival of tasks ([#11](https://github.com/manoelcampos/cloudsim-plus/issues/11), [#23](https://github.com/manoelcampos/cloudsim-plus/issues/23));
1. [Allow dynamic creation of VMs and Cloudlets without requiring creation of Datacenter Brokers at runtime](/cloudsim-plus-examples/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCreationOfVmsAndCloudletsExample.java), enabling VMs to be created on-demand according to arrived cloudlets ([#43](https://github.com/manoelcampos/cloudsim-plus/issues/43));
......@@ -231,6 +232,7 @@ The presented results are structured and clear to allow better understanding. Fo
<p align="right"><a href="#top">:arrow_up:</a></p>
# Documentation and Help
The project documentation originated from CloudSim was entirely updated and extended.
You can see the javadoc documentation for classes and their elements directly on your IDE.
......@@ -336,21 +338,22 @@ Additionally, the interface `Storage` was renamed to `FileStorage` and its imple
# General Features of the Framework
* Support for modeling and simulation of large scale Cloud computing data centers.
* Support for modeling and simulation of virtualized server hosts, with customizable policies for provisioning host resources to virtual machines.
* Support for modeling and simulation of energy-aware computational resources.
* Support for modeling and simulation of data center network topologies and message-passing applications.
* Support for modeling and simulation of federated clouds.
* Support for dynamic insertion of simulation elements, stop and resume of simulation.
* Support for user-defined policies for allocation of hosts to virtual machines and policies for allocation of host resources to virtual machines.
* Support for modeling and simulation of large scale Cloud computing data centers.
* Support for modeling and simulation of virtualized server hosts, with customizable policies for provisioning host resources to virtual machines.
* Support for modeling and simulation of energy-aware computational resources.
* Support for modeling and simulation of data center network topologies and message-passing applications.
* Support for modeling and simulation of federated clouds.
* Support for dynamic insertion of simulation elements, stop and resume of simulation.
* Support for user-defined policies for allocation of hosts to virtual machines and policies for allocation of host resources to virtual machines.
<p align="right"><a href="#top">:arrow_up:</a></p>
<a id="publications"></a>
# CloudSim Plus Publications
1. [M. C. Silva Filho, R. L. Oliveira, C. C. Monteiro, P. R. M. Inácio, and M. M. Freire, “CloudSim Plus: a Cloud Computing Simulation Framework Pursuing Software Engineering Principles for Improved Modularity, Extensibility and Correctness,” in IFIP/IEEE International Symposium on Integrated Network Management, 2017, p. 7](https://doi.org/10.23919/INM.2017.7987304). If you are using CloudSim Plus in your research, please make sure you cite that paper. You can check the paper presentation [here](http://cloudsimplus.org/docs/presentation/).
2. White Paper ["CloudSim Plus: A Modern Java 8 Framework for Modeling and Simulation of Cloud Computing Infrastructures and Services"](https://github.com/manoelcampos/cloudsim-plus/blob/master/docs/cloudsim-plus-white-paper.pdf)
1. [M. C. Silva Filho, R. L. Oliveira, C. C. Monteiro, P. R. M. Inácio, and M. M. Freire, “CloudSim Plus: a Cloud Computing Simulation Framework Pursuing Software Engineering Principles for Improved Modularity, Extensibility and Correctness,” in IFIP/IEEE International Symposium on Integrated Network Management, 2017, p. 7](https://doi.org/10.23919/INM.2017.7987304). If you are using CloudSim Plus in your research, please make sure you cite that paper. You can check the paper presentation [here](http://cloudsimplus.org/docs/presentation/).
2. White Paper ["CloudSim Plus: A Modern Java 8 Framework for Modeling and Simulation of Cloud Computing Infrastructures and Services"](https://github.com/manoelcampos/cloudsim-plus/blob/master/docs/cloudsim-plus-white-paper.pdf)
<p align="right"><a href="#top">:arrow_up:</a></p>
......
......@@ -4,7 +4,7 @@
<groupId>org.cloudsimplus</groupId>
<artifactId>cloudsim-plus-benchmarks</artifactId>
<version>1.3.3</version>
<version>2.0.0</version>
<name>CloudSim Plus Benchmarks</name>
<description>A module containing benchmarks created using JMH (Java Microbenchmark Harness framework) to assess CloudSim Plus performance</description>
<url>http://cloudsimplus.org</url>
......
......@@ -4,7 +4,7 @@
<groupId>org.cloudsimplus</groupId>
<artifactId>cloudsim-plus-examples</artifactId>
<version>1.3.3</version>
<version>2.0.0</version>
<name>CloudSim Plus Examples</name>
<description>
Ready-to-run examples of how to use CloudSim Plus API.
......
......@@ -30,11 +30,9 @@ import org.cloudbus.cloudsim.cloudlets.Cloudlet;
import org.cloudbus.cloudsim.cloudlets.CloudletSimple;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.datacenters.DatacenterCharacteristics;
import org.cloudbus.cloudsim.datacenters.DatacenterCharacteristicsSimple;
import org.cloudbus.cloudsim.datacenters.power.PowerDatacenter;
import org.cloudbus.cloudsim.hosts.power.PowerHost;
import org.cloudbus.cloudsim.hosts.power.PowerHostUtilizationHistory;
import org.cloudbus.cloudsim.datacenters.DatacenterSimple;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple;
import org.cloudbus.cloudsim.power.models.PowerModel;
import org.cloudbus.cloudsim.power.models.PowerModelLinear;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
......@@ -47,20 +45,17 @@ import org.cloudbus.cloudsim.schedulers.vm.VmScheduler;
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModel;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelFull;
import org.cloudbus.cloudsim.vms.power.PowerVm;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudbus.cloudsim.vms.VmSimple;
import org.cloudsimplus.builders.tables.CloudletsTableBuilder;
import java.util.ArrayList;
import java.util.List;
/**
* A example showing how to use the power module to
* compute power consumption of Hosts.
* Realize that for this goal, you must
* use all power-related objects such as
* {@link PowerDatacenter}, {@link PowerHost},
* {@link PowerVm} and a {@link PowerModel}
* for each Host.
* A example showing how to show Hosts power consumption.
* Realize that for this goal, you define a {@link PowerModel}
* for each Host by calling {@code host.getPowerSupply().setPowerModel(powerModel)}.
*
* <p>It creates the number of cloudlets defined in
* {@link #CLOUDLETS}. All cloudlets will required 100% of PEs they are using all the time.
......@@ -79,6 +74,10 @@ import java.util.List;
* and added to consumer power when it
* is lower or equal to the minimum usage percentage.</p>
*
* <p>Realize that the Host CPU Utilization History is only computed
* if VMs utilization history is enabled by calling
* {@code vm.getUtilizationHistory().enable()}</p>
*
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.2.4
*/
......@@ -109,10 +108,10 @@ public class PowerExample {
private final CloudSim simulation;
private DatacenterBroker broker0;
private List<PowerVm> vmList;
private List<Vm> vmList;
private List<Cloudlet> cloudletList;
private Datacenter datacenter0;
private final List<PowerHostUtilizationHistory> hostList;
private final List<Host> hostList;
public static void main(String[] args) {
new PowerExample();
......@@ -121,11 +120,11 @@ public class PowerExample {
public PowerExample() {
simulation = new CloudSim();
hostList = new ArrayList<>(HOSTS);
datacenter0 = createPowerDatacenter();
datacenter0 = createDatacenterSimple();
//Creates a broker that is a software acting on behalf a cloud customer to manage his/her VMs and Cloudlets
broker0 = new DatacenterBrokerSimple(simulation);
vmList = createPowerVms();
vmList = createVms();
cloudletList = createCloudlets();
broker0.submitVmList(vmList);
broker0.submitCloudletList(cloudletList);
......@@ -138,10 +137,17 @@ public class PowerExample {
printHostCpuUtilizationAndPowerConsumption();
}
/**
* <p>The Host CPU Utilization History is only computed
* if VMs utilization history is enabled by calling
* {@code vm.getUtilizationHistory().enable()}
* </p>*
*/
private void printHostCpuUtilizationAndPowerConsumption() {
System.out.println();
for (PowerHostUtilizationHistory host : hostList) {
System.out.printf("Host %4d CPU utilization and power consumption\n", host.getId());
for (Host host : hostList) {
System.out.printf("Host %d CPU utilization and power consumption\n", host.getId());
System.out.println("-------------------------------------------------------------------------------------------");
/*
Since the utilization history are stored in the reverse chronological order,
the values are presented in this way.
......@@ -162,33 +168,34 @@ public class PowerExample {
* This way, to get the total power consumed for each 10 seconds interval,
* the power consumption is multipled by the time interval.
*/
final double wattsPerInterval = host.getPowerModel().getPower(utilizationPercent)*SCHEDULING_INTERVAL;
final double wattsPerInterval = host.getPowerSupply().getPowerModel().getPower(utilizationPercent)*SCHEDULING_INTERVAL;
totalPower += wattsPerInterval;
System.out.printf("\tTime %6.0f | CPU Utilization %6.2f%% | Power Consumption: %8.2f Watts in %d Seconds\n",
time, utilizationPercent*100, wattsPerInterval, SCHEDULING_INTERVAL);
time -= SCHEDULING_INTERVAL;
}
System.out.printf(
"\t Total Host %4d Power Consumption in %6.0f seconds: %10.2f Watts (average of %.2f Watts/Second) \n\n",
"Total Host %d Power Consumption in %.0f seconds: %.2f Watts (mean of %.2f Watts/Second) \n",
host.getId(), simulation.clock(), totalPower, totalPower/simulation.clock());
System.out.println("-------------------------------------------------------------------------------------------\n");
}
}
/**
* Creates a {@link PowerDatacenter} and its {@link PowerHost}s.
* Creates a {@link Datacenter} and its {@link Host}s.
*/
private PowerDatacenter createPowerDatacenter() {
private Datacenter createDatacenterSimple() {
for(int i = 0; i < HOSTS; i++) {
PowerHostUtilizationHistory host = createPowerHost();
Host host = createPowerHost();
hostList.add(host);
}
final PowerDatacenter dc = new PowerDatacenter(simulation, hostList, new VmAllocationPolicySimple());
final Datacenter dc = new DatacenterSimple(simulation, hostList, new VmAllocationPolicySimple());
dc.setSchedulingInterval(SCHEDULING_INTERVAL);
return dc;
}
private PowerHostUtilizationHistory createPowerHost() {
private Host createPowerHost() {
final List<Pe> peList = new ArrayList<>(HOST_PES);
//List of Host's CPUs (Processing Elements, PEs)
for (int i = 0; i < HOST_PES; i++) {
......@@ -204,8 +211,8 @@ public class PowerExample {
final ResourceProvisioner bwProvisioner = new ResourceProvisionerSimple();
final VmScheduler vmScheduler = new VmSchedulerTimeShared();
final PowerHostUtilizationHistory host = new PowerHostUtilizationHistory(ram, bw, storage, peList);
host.setPowerModel(powerModel);
final Host host = new HostSimple(ram, bw, storage, peList);
host.getPowerSupply().setPowerModel(powerModel);
host
.setRamProvisioner(ramProvisioner)
.setBwProvisioner(bwProvisioner)
......@@ -216,12 +223,13 @@ public class PowerExample {
/**
* Creates a list of VMs.
*/
private List<PowerVm> createPowerVms() {
final List<PowerVm> list = new ArrayList<>(VMS);
private List<Vm> createVms() {
final List<Vm> list = new ArrayList<>(VMS);
for (int i = 0; i < VMS; i++) {
PowerVm vm = new PowerVm(i, 1000, VM_PES);
Vm vm = new VmSimple(i, 1000, VM_PES);
vm.setRam(512).setBw(1000).setSize(10000)
.setCloudletScheduler(new CloudletSchedulerTimeShared());
vm.getUtilizationHistory().enable();
list.add(vm);
}
......
......@@ -46,20 +46,17 @@
*/
package org.cloudsimplus.examples.migration;
import org.cloudbus.cloudsim.allocationpolicies.power.PowerVmAllocationPolicyMigration;
import org.cloudbus.cloudsim.allocationpolicies.power.PowerVmAllocationPolicyMigrationBestFitStaticThreshold;
import org.cloudbus.cloudsim.allocationpolicies.migration.VmAllocationPolicyMigration;
import org.cloudbus.cloudsim.allocationpolicies.migration.VmAllocationPolicyMigrationBestFitStaticThreshold;
import org.cloudbus.cloudsim.brokers.DatacenterBroker;
import org.cloudbus.cloudsim.brokers.DatacenterBrokerSimple;
import org.cloudbus.cloudsim.cloudlets.Cloudlet;
import org.cloudbus.cloudsim.cloudlets.CloudletSimple;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.datacenters.DatacenterCharacteristics;
import org.cloudbus.cloudsim.datacenters.DatacenterCharacteristicsSimple;
import org.cloudbus.cloudsim.datacenters.power.PowerDatacenter;
import org.cloudbus.cloudsim.hosts.power.PowerHost;
import org.cloudbus.cloudsim.hosts.power.PowerHostUtilizationHistory;
import org.cloudbus.cloudsim.power.models.PowerModelLinear;
import org.cloudbus.cloudsim.datacenters.DatacenterSimple;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple;
import org.cloudbus.cloudsim.resources.Pe;
......@@ -72,7 +69,7 @@ import org.cloudbus.cloudsim.utilizationmodels.UtilizationModel;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelDynamic;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelFull;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudbus.cloudsim.vms.power.PowerVm;
import org.cloudbus.cloudsim.vms.VmSimple;
import org.cloudsimplus.builders.tables.CloudletsTableBuilder;
import java.util.ArrayList;
......@@ -83,19 +80,19 @@ import java.util.List;
* An example showing how to create 1 Datacenter with 3 hosts,
* 1 VM by host and 1 cloudlet by VM and perform VM migration using
* a custom VmAllocationPolicy. Such a policy migrates VMs based on
* {@link PowerVmAllocationPolicyMigrationBestFitStaticThreshold
* {@link VmAllocationPolicyMigrationBestFitStaticThreshold
* static host CPU utilization threshold}.
* The VmAllocationPolicy used in this example ignores power usage of
* Hosts. This way, it isn't required to set a PowerModel for Hosts.
*
* <p>The created {@link PowerVmAllocationPolicyMigrationBestFitStaticThreshold policy}
* <p>The created {@link VmAllocationPolicyMigrationBestFitStaticThreshold policy}
* allows the definition of static under and over CPU utilization thresholds to
* enable VM migration.
* The example uses a custom UtilizationModel to define CPU usage of cloudlets which
* {@link UtilizationModelDynamic increases along the simulation time}.</p>
*
* It is used some constants to create simulation objects such as
* {@link PowerDatacenter}, {@link PowerHost} and {@link PowerVm}.
* {@link DatacenterSimple}, {@link Host} and {@link Vm}.
* The values of these constants were careful and accordingly chosen to allow
* migration of VMs due to either under and overloaded hosts and
* to allow one developer to know exactly how the simulation will run
......@@ -108,10 +105,14 @@ import java.util.List;
* define new appropriated ones to allow the simulation
* to run correctly.</p>
*
* <p>Realize that the Host State History is just collected
* if {@link Host#isStateHistoryEnabled() history is enabled}
* by calling {@link Host#enableStateHistory()}.</p>
*
* @author Manoel Campos da Silva Filho
*/
public final class MigrationExample1 {
private static final int SCHEDULE_TIME_TO_PROCESS_DATACENTER_EVENTS = 5;
private static final int SCHEDULE_INTERVAL = 5;
private static final int HOSTS = 5;
private static final int VMS = 3;
......@@ -125,11 +126,11 @@ public final class MigrationExample1 {
/**
* The time spent during VM migration depend on the
* bandwidth of the target Host.
* By default, a {@link PowerVmAllocationPolicyMigration}
* By default, a {@link Datacenter}
* uses only 50% of the BW to migrate VMs, while the
* remaining capacity is used for VM communication.
* This can be changed by calling
* {@link PowerDatacenter#setBandwidthForMigrationPercent(double)}.
* {@link DatacenterSimple#setBandwidthPercentForMigration(double)}.
*
* <p>The 16000 Mb/s is equal to 2000 MB/s. Since just half of this capacity
* is used for VM migration, only 1000 MB/s will be available for this process.
......@@ -178,8 +179,8 @@ public final class MigrationExample1 {
private final List<Vm> vmList = new ArrayList<>();
private CloudSim simulation;
private PowerVmAllocationPolicyMigrationBestFitStaticThreshold allocationPolicy;
private List<PowerHostUtilizationHistory> hostList;
private VmAllocationPolicyMigrationBestFitStaticThreshold allocationPolicy;
private List<Host> hostList;
/**
* Starts the example.
......@@ -220,7 +221,7 @@ public final class MigrationExample1 {
Log.printConcatLine(getClass().getSimpleName(), " finished!");
}
private void printHostHistory(PowerHost h) {
private void printHostHistory(Host h) {
System.out.printf("Host: %d\n", h.getId());
System.out.println("------------------------------------------------------------------------------------------");
h.getStateHistory().stream().forEach(System.out::print);
......@@ -268,7 +269,7 @@ public final class MigrationExample1 {
public void createAndSubmitVms(DatacenterBroker broker) {
List<Vm> list = new ArrayList<>(VMS);
for(int i = 0; i < VMS; i++){
PowerVm vm = createVm(broker, VM_PES);
Vm vm = createVm(broker, VM_PES);
list.add(vm);
}
......@@ -276,8 +277,8 @@ public final class MigrationExample1 {
broker.submitVmList(list);
}
public PowerVm createVm(DatacenterBroker broker, int pes) {
PowerVm vm = new PowerVm(VM_MIPS, pes);
public Vm createVm(DatacenterBroker broker, int pes) {
Vm vm = new VmSimple(VM_MIPS, pes);
vm
.setRam(VM_RAM).setBw((long)VM_BW).setSize(VM_SIZE)
.setCloudletScheduler(new CloudletSchedulerTimeShared());
......@@ -353,9 +354,8 @@ public final class MigrationExample1 {
this.hostList = new ArrayList<>();
for(int i = 0; i < HOSTS; i++){
final int pes = HOST_INITIAL_PES + i;
PowerHostUtilizationHistory host = createHost(pes, HOST_MIPS);
Host host = createHost(pes, HOST_MIPS);
hostList.add(host);
Log.printFormattedLine("#Created host %d with %d MIPS x %2d PEs. Powered on: %s", i, HOST_MIPS, pes, host.isActive());
}
Log.printLine();
......@@ -370,26 +370,24 @@ public final class MigrationExample1 {
* become overloaded in order to trigger the migration.
*/
this.allocationPolicy =
new PowerVmAllocationPolicyMigrationBestFitStaticThreshold(
new VmAllocationPolicyMigrationBestFitStaticThreshold(
new PowerVmSelectionPolicyMinimumUtilization(),
HOST_UTILIZATION_THRESHOLD_FOR_VM_MIGRATION+0.2);
PowerDatacenter dc = new PowerDatacenter(simulation, hostList, allocationPolicy);
dc.setMigrationsEnabled(true)
.setSchedulingInterval(SCHEDULE_TIME_TO_PROCESS_DATACENTER_EVENTS)
.setLog(true);
DatacenterSimple dc = new DatacenterSimple(simulation, hostList, allocationPolicy);
dc.setSchedulingInterval(SCHEDULE_INTERVAL).setLog(true);
return dc;
}
public PowerHostUtilizationHistory createHost(int numberOfPes, long mipsByPe) {
public Host createHost(int numberOfPes, long mipsByPe) {
List<Pe> peList = createPeList(numberOfPes, mipsByPe);
PowerHostUtilizationHistory host =
new PowerHostUtilizationHistory(HOST_RAM, HOST_BW, HOST_STORAGE, peList);
Host host =
new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList);
host
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
.setVmScheduler(new VmSchedulerTimeShared());
System.out.println("PowerModel: " + host.getPowerModel().getClass().getName());
host.enableStateHistory();
return host;
}
......
......@@ -46,21 +46,18 @@
*/
package org.cloudsimplus.examples.migration;
import org.cloudbus.cloudsim.allocationpolicies.power.PowerVmAllocationPolicyMigration;
import org.cloudbus.cloudsim.allocationpolicies.power.PowerVmAllocationPolicyMigrationBestFitStaticThreshold;
import org.cloudbus.cloudsim.allocationpolicies.power.PowerVmAllocationPolicyMigrationMedianAbsoluteDeviation;
import org.cloudbus.cloudsim.allocationpolicies.power.PowerVmAllocationPolicyMigrationStaticThreshold;
import org.cloudbus.cloudsim.allocationpolicies.migration.VmAllocationPolicyMigrationMedianAbsoluteDeviation;
import org.cloudbus.cloudsim.allocationpolicies.migration.VmAllocationPolicyMigrationStaticThreshold;
import org.cloudbus.cloudsim.brokers.DatacenterBroker;
import org.cloudbus.cloudsim.brokers.DatacenterBrokerSimple;
import org.cloudbus.cloudsim.cloudlets.Cloudlet;
import org.cloudbus.cloudsim.cloudlets.CloudletSimple;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.datacenters.DatacenterCharacteristics;
import org.cloudbus.cloudsim.datacenters.DatacenterCharacteristicsSimple;
import org.cloudbus.cloudsim.datacenters.power.PowerDatacenter;
import org.cloudbus.cloudsim.hosts.power.PowerHost;
import org.cloudbus.cloudsim.hosts.power.PowerHostUtilizationHistory;
import org.cloudbus.cloudsim.datacenters.DatacenterSimple;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple;
import org.cloudbus.cloudsim.hosts.HostStateHistoryEntry;
import org.cloudbus.cloudsim.power.models.PowerModelLinear;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple;
......@@ -74,7 +71,7 @@ import org.cloudbus.cloudsim.utilizationmodels.UtilizationModel;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelDynamic;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelFull;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudbus.cloudsim.vms.power.PowerVm;
import org.cloudbus.cloudsim.vms.VmSimple;
import org.cloudsimplus.builders.tables.CloudletsTableBuilder;
import java.util.ArrayList;
......@@ -84,18 +81,18 @@ import java.util.List;
/**
* An example showing how to create 1 Datacenter with 3 hosts,
* 1 VM by host and 1 cloudlet by VM and perform VM migration using
* a custom VmAllocationPolicy. Such a policy migrates VMs based on
* {@link PowerVmAllocationPolicyMigrationMedianAbsoluteDeviation
* a custom VmAllocationPolicy. Such a policy migrates VMs relying on a
* {@link VmAllocationPolicyMigrationMedianAbsoluteDeviation
* dynamic host CPU utilization threshold} based on CPU utilization.
* This VmAllocationPolicy considers the power usage of Hosts to place VMs.
* So that, a {@link org.cloudbus.cloudsim.power.models.PowerModel} is being
* set to every created Host.
* set to every created Host by means of {@code host.getPowerSupply().setPowerModel(powerModel)}.
*
* <p>The example uses a custom UtilizationModel to define CPU usage of cloudlets which
* {@link UtilizationModelDynamic increases along the simulation time}.
*
* It is used some constants to create simulation objects such as
* {@link PowerDatacenter}, {@link PowerHost} and {@link PowerVm}.
* {@link DatacenterSimple}, {@link Host} and {@link Vm}.
* The values of these constants were careful and accordingly chosen to allow
* migration of VMs due to either under and overloaded hosts and
* to allow one developer to know exactly how the simulation will run
......@@ -108,10 +105,17 @@ import java.util.List;
* define new appropriated ones to allow the simulation
* to run correctly.</p>
*
* <p>Realize that the Host State History is just collected
* if {@link Host#isStateHistoryEnabled() history is enabled}
* by calling {@link Host#enableStateHistory()}.
* The Host CPU Utilization History also is only computed
* if VMs utilization history is enabled by calling
* {@code vm.getUtilizationHistory().enable()}</p>
*
* @author Manoel Campos da Silva Filho
*/
public final class MigrationExample2 {
private static final int SCHEDULE_TIME_TO_PROCESS_DATACENTER_EVENTS = 5;
public final class MigrationExample2_PowerUsage {
private static final int SCHEDULE_INTERVAL = 5;
private static final int HOSTS = 5;
private static final int VMS = 3;
......@@ -125,11 +129,11 @@ public final class MigrationExample2 {
/**
* The time spent during VM migration depend on the
* bandwidth of the target Host.
* By default, a {@link PowerVmAllocationPolicyMigration}
* By default, a {@link Datacenter}
* uses only 50% of the BW to migrate VMs, while the
* remaining capacity is used for VM communication.
* This can be changed by calling
* {@link PowerDatacenter#setBandwidthForMigrationPercent(double)}.
* {@link Datacenter#setBandwidthPercentForMigration(double)}.
*
* <p>The 16000 Mb/s is equal to 2000 MB/s. Since just half of this capacity
* is used for VM migration, only 1000 MB/s will be available for this process.
......@@ -178,8 +182,8 @@ public final class MigrationExample2 {
private final List<Vm> vmList = new ArrayList<>();
private CloudSim simulation;
private PowerVmAllocationPolicyMigrationMedianAbsoluteDeviation allocationPolicy;
private List<PowerHostUtilizationHistory> hostList;
private VmAllocationPolicyMigrationMedianAbsoluteDeviation allocationPolicy;
private List<Host> hostList;
/**
* Starts the example.
......@@ -187,10 +191,10 @@ public final class MigrationExample2 {
* @param args
*/
public static void main(String[] args) {
new MigrationExample2();
new MigrationExample2_PowerUsage();
}
public MigrationExample2(){
public MigrationExample2_PowerUsage(){
Log.printConcatLine("Starting ", getClass().getSimpleName(), "...");
simulation = new CloudSim();
......@@ -208,16 +212,57 @@ public final class MigrationExample2 {
Comparator.comparingInt((Cloudlet c) -> c.getVm().getHost().getId())
.thenComparingInt(c -> c.getVm().getId()));
new CloudletsTableBuilder(finishedList).build();
System.out.println("\nHosts CPU usage History (when the allocated MIPS is lower than the requested, it is due to VM migration overhead)");
System.out.println("\n WHEN A HOST CPU ALLOCATED MIPS IS LOWER THAN THE REQUESTED, IT'S DUE TO VM MIGRATION OVERHEAD)\n");
hostList.stream().filter(h -> h.getId() <= 2).forEach(this::printHostHistory);
hostList.stream().forEach(this::printHistory);
Log.printConcatLine(getClass().getSimpleName(), " finished!");
}
private void printHostHistory(PowerHost h) {
System.out.printf("Host: %d\n", h.getId());
System.out.println("------------------------------------------------------------------------------------------");
h.getStateHistory().stream().forEach(System.out::print);
private void printHistory(Host host){
if(printHostStateHistory(host)) {
printHostCpuUsageAndPowerConsumption(host);
}
}
/**
* Prints Host state history
* @param host the host to print information
* @return true if the Host was powered on during simulation, false otherwise
*/