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

Merge branch 'dev'

parents d975e756 8dcc6b67
......@@ -4,7 +4,7 @@
<groupId>org.cloudsimplus</groupId>
<artifactId>cloudsim-plus-benchmarks</artifactId>
<version>1.3.0</version>
<version>1.3.1</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.0</version>
<version>1.3.1</version>
<name>CloudSim Plus Examples</name>
<description>
Ready-to-run examples of how to use CloudSim Plus API.
......
......@@ -117,7 +117,11 @@ public class VmDestructionExample {
vmList = createVms();
cloudletList = createCloudlets();
/*Adds a Listener to track the execution update of VM 1*/
/*Adds a Listener to track the execution update of VM 1.
* If you want to track the update processing of multiple VMs, you can
* add this event listener for each desired VM that it will work
* transparently for any VM.
*/
vmList.get(1).addOnUpdateProcessingListener(this::vmProcessingUpdate);
broker0.submitVmList(vmList);
......
......@@ -31,8 +31,6 @@ import org.cloudbus.cloudsim.cloudlets.CloudletSimple;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.Simulation;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.datacenters.DatacenterCharacteristics;
import org.cloudbus.cloudsim.datacenters.DatacenterCharacteristicsSimple;
import org.cloudbus.cloudsim.datacenters.DatacenterSimple;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple;
......@@ -45,7 +43,9 @@ import org.cloudbus.cloudsim.schedulers.cloudlet.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.util.Log;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModel;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelDynamic;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelFull;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelStochastic;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudbus.cloudsim.vms.VmSimple;
import org.cloudsimplus.autoscaling.HorizontalVmScaling;
......@@ -64,10 +64,10 @@ import static java.util.Comparator.comparingDouble;
/**
* An example that scales VM PEs up or down, according to the arrival of Cloudlets.
* A {@link VerticalVmScaling}
* is set to each {@link #createListOfScalableVms(int) initially created VM},
* which will check at {@link #SCHEDULING_INTERVAL specific time intervals}
* if VM PEs {@link #upperCpuUtilizationThreshold(Vm) are over or underloaded} to then
* request such PEs to be scaled up or down.
* is set to each {@link #createListOfScalableVms(int) initially created VM}.
* Every VM will check at {@link #SCHEDULING_INTERVAL specific time intervals}
* if its PEs {@link #upperCpuUtilizationThreshold(Vm) are over or underloaded} to then
* request such PEs to be up or down scaled.
*
* <p>The example uses the CloudSim Plus {@link EventListener} feature
* to enable monitoring the simulation and dynamically create objects such as Cloudlets and VMs at runtime.
......@@ -162,9 +162,9 @@ public class VerticalVmCpuScalingExample {
}
private void printSimulationResults() {
List<Cloudlet> finishedCloudlets = broker0.getCloudletFinishedList();
Comparator<Cloudlet> sortByVmId = comparingDouble(c -> c.getVm().getId());
Comparator<Cloudlet> sortByStartTime = comparingDouble(c -> c.getExecStartTime());
final List<Cloudlet> finishedCloudlets = broker0.getCloudletFinishedList();
final Comparator<Cloudlet> sortByVmId = comparingDouble(c -> c.getVm().getId());
final Comparator<Cloudlet> sortByStartTime = comparingDouble(Cloudlet::getExecStartTime);
finishedCloudlets.sort(sortByVmId.thenComparing(sortByStartTime));
new CloudletsTableBuilder(finishedCloudlets).build();
......@@ -341,34 +341,56 @@ public class VerticalVmCpuScalingExample {
}
/**
* Creates a single Cloudlet.
* Creates a single Cloudlet with no delay, which means the Cloudlet arrival time will
* be zero (exactly when the simulation starts).
*
* @param length the length of the cloudlet to create.
* @param numberOfPes the number of PEs the Cloudlets requires.
* @param delay the delay that defines the arrival time of the Cloudlet at the Cloud infrastructure.
* @param length the Cloudlet length
* @param numberOfPes the number of PEs the Cloudlets requires
* @return the created Cloudlet
*/
private Cloudlet createCloudlet(long length, int numberOfPes, double delay) {
final int id = createdCloudlets++;
//randomly selects a length for the cloudlet
UtilizationModel utilizationFull = new UtilizationModelFull();
Cloudlet cl = new CloudletSimple(id, length, numberOfPes);
cl.setFileSize(1024)
.setOutputSize(1024)
.setUtilizationModel(utilizationFull)
.setSubmissionDelay(delay);
return cl;
private Cloudlet createCloudlet(final long length, final int numberOfPes) {
return createCloudlet(length, numberOfPes, 0);
}
/**
* Creates a single Cloudlet with no delay, which means the Cloudlet arrival time will
* be zero (exactly when the simulation starts).
* Creates a single Cloudlet.
*
* @param length the Cloudlet length
* @param numberOfPes the number of PEs the Cloudlets requires
* @param length the length of the cloudlet to create.
* @param numberOfPes the number of PEs the Cloudlets requires.
* @param delay the delay that defines the arrival time of the Cloudlet at the Cloud infrastructure.
* @return the created Cloudlet
*/
private Cloudlet createCloudlet(long length, int numberOfPes) {
return createCloudlet(length, numberOfPes, 0);
private Cloudlet createCloudlet(final long length, final int numberOfPes, final double delay) {
/*
Since a VM PE isn't used by two Cloudlets at the same time,
the Cloudlet can used 100% of that CPU capacity at the time
it is running. Even if a CloudletSchedulerTimeShared is used
to share the same VM PE among multiple Cloudlets,
just one Cloudlet uses the PE at a time.
Then it is preempted to enable other Cloudlets to use such a VM PE.
*/
final UtilizationModel utilizationCpu = new UtilizationModelFull();
/**
* Since BW e RAM are shared resources that don't enable preemption,
* two Cloudlets can't use the same portion of such resources at the same time
* (unless virtual memory is enabled, but such a feature is not available in simulation).
* This way, the total capacity of such resources is being evenly split among created Cloudlets.
* If there are 10 Cloudlets, each one will use just 10% of such resources.
* This value can be defined in different ways, as you want. For instance, some Cloudlets
* can require more resources than other ones.
* To enable that, you would need to instantiate specific {@link UtilizationModelDynamic} for each Cloudlet,
* use a {@link UtilizationModelStochastic} to define resource usage randomly,
* or use any other {@link UtilizationModel} implementation.
*/
final UtilizationModel utilizationModelDynamic = new UtilizationModelDynamic(1.0/CLOUDLETS);
Cloudlet cl = new CloudletSimple(length, numberOfPes);
cl.setFileSize(1024)
.setOutputSize(1024)
.setUtilizationModelBw(utilizationModelDynamic)
.setUtilizationModelRam(utilizationModelDynamic)
.setUtilizationModelCpu(utilizationCpu)
.setSubmissionDelay(delay);
return cl;
}
}
......@@ -64,14 +64,17 @@ import java.util.List;
import static java.util.Comparator.comparingDouble;
/**
* An example that scale VM RAM up, according to the arrival of Cloudlets.
* An example that scales VM RAM up or down, according to current Cloudlets requests.
* It is used a {@link UtilizationModelDynamic} object to
* define Vm RAM usage that will increment along the time.
* A {@link VerticalVmScaling}
* define Vm RAM usage increasingly along the time.
* Cloudlets are created with different length, so that they will finish gradually.
* This way, it's possible to check that RAM usage decreases along the time.
*
* <p>A {@link VerticalVmScaling}
* is set to each {@link #createListOfScalableVms(int) initially created VM},
* that will check at {@link #SCHEDULING_INTERVAL specific time intervals}
* if a VM RAM {@link #upperRamUtilizationThreshold(Vm) is overloaded or not} to then
* request the RAM to be scaled up.
* request the RAM to be scaled up.</p>
*
* <p>The example uses the CloudSim Plus {@link EventListener} feature
* to enable monitoring the simulation and dynamically creating objects such as Cloudlets and VMs.
......@@ -159,21 +162,22 @@ public class VerticalVmRamScalingExample {
}
private void onClockTickListener(EventInfo eventInfo) {
vmList.forEach(vm -> {
for (Vm vm : vmList) {
Log.printFormatted("\t\tTime %6.1f: Vm %d Ram Usage: %6.2f%% (%4d of %4d MB)",
eventInfo.getTime(), vm.getId(), vm.getRam().getPercentUtilization()*100.0,
eventInfo.getTime(), vm.getId(), vm.getRam().getPercentUtilization() * 100.0,
vm.getRam().getAllocatedResource(), vm.getRam().getCapacity());
Log.printFormattedLine(" | Host Ram Allocation: %6.2f%% (%5d of %5d MB). Running Cloudlets: %d",
vm.getHost().getRam().getPercentUtilization()*100,
vm.getHost().getRam().getPercentUtilization() * 100,
vm.getHost().getRam().getAllocatedResource(),
vm.getHost().getRam().getCapacity(), vm.getCloudletScheduler().getCloudletExecList().size());
});
}
}
private void printSimulationResults() {
List<Cloudlet> finishedCloudlets = broker0.getCloudletFinishedList();
Comparator<Cloudlet> sortByVmId = comparingDouble(c -> c.getVm().getId());
Comparator<Cloudlet> sortByStartTime = comparingDouble(c -> c.getExecStartTime());
final List<Cloudlet> finishedCloudlets = broker0.getCloudletFinishedList();
final Comparator<Cloudlet> sortByVmId = comparingDouble(c -> c.getVm().getId());
final Comparator<Cloudlet> sortByStartTime = comparingDouble(Cloudlet::getExecStartTime);
finishedCloudlets.sort(sortByVmId.thenComparing(sortByStartTime));
new CloudletsTableBuilder(finishedCloudlets).build();
......@@ -192,7 +196,7 @@ public class VerticalVmRamScalingExample {
}
private Host createHost() {
List<Pe> peList = new ArrayList<>(HOST_PES);
final List<Pe> peList = new ArrayList<>(HOST_PES);
for (int i = 0; i < HOST_PES; i++) {
peList.add(new PeSimple(1000, new PeProvisionerSimple()));
}
......@@ -200,7 +204,6 @@ public class VerticalVmRamScalingExample {
final long ram = 20000; //in Megabytes
final long bw = 100000; //in Megabytes
final long storage = 10000000; //in Megabites/s
final int id = hostList.size();
return new HostSimple(ram, bw, storage, peList)
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
......@@ -216,7 +219,7 @@ public class VerticalVmRamScalingExample {
* @see #createVerticalRamScalingForVm(Vm)
*/
private List<Vm> createListOfScalableVms(final int numberOfVms) {
List<Vm> newList = new ArrayList<>(numberOfVms);
final List<Vm> newList = new ArrayList<>(numberOfVms);
for (int i = 0; i < numberOfVms; i++) {
Vm vm = createVm();
createVerticalRamScalingForVm(vm);
......
/*
* CloudSim Plus: A modern, highly-extensible and easier-to-use Framework for
* Modeling and Simulation of Cloud Computing Infrastructures and Services.
* http://cloudsimplus.org
*
* Copyright (C) 2015-2018 Universidade da Beira Interior (UBI, Portugal) and
* the Instituto Federal de Educação Ciência e Tecnologia do Tocantins (IFTO, Brazil).
*
* This file is part of CloudSim Plus.
*
* CloudSim Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CloudSim Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CloudSim Plus. If not, see <http://www.gnu.org/licenses/>.
*/
package org.cloudsimplus.examples.brokers;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicySimple;
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.DatacenterSimple;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisioner;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple;
import org.cloudbus.cloudsim.resources.Pe;
import org.cloudbus.cloudsim.resources.PeSimple;
import org.cloudbus.cloudsim.schedulers.cloudlet.CloudletSchedulerTimeShared;
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.Vm;
import org.cloudbus.cloudsim.vms.VmSimple;
import org.cloudsimplus.builders.tables.CloudletsTableBuilder;
import org.cloudsimplus.listeners.EventInfo;
import org.cloudsimplus.listeners.EventListener;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
/**
*
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.3.1
*/
public class MultipleBrokers3 {
private static final int HOSTS = 2;
private static final int HOST_PES = 8;
private static final int BROKERS = 2;
private static final int VMS = 2;
private static final int VM_PES = 4;
private static final int CLOUDLETS = 2;
private static final int CLOUDLET_PES = 2;
private static final int CLOUDLET_LENGTH = 10000;
private final CloudSim simulation;
private final List<DatacenterBroker> brokers;
private final List<Vm> vmList;
private final List<Cloudlet> cloudletList;
private final Datacenter datacenter0;
public static void main(String[] args) {
new MultipleBrokers3();
}
public MultipleBrokers3() {
simulation = new CloudSim();
datacenter0 = createDatacenter();
brokers = createBrokers();
vmList = new ArrayList<>(BROKERS*VMS);
cloudletList = new ArrayList<>(CLOUDLETS*VMS);
createVmsAndCloudlets();
simulation.start();
printResults();
}
private void createVmsAndCloudlets() {
int i = 0;
for (DatacenterBroker broker : brokers) {
vmList.addAll(createAndSubmitVms(broker));
cloudletList.addAll(createAndSubmitCloudlets(broker));
}
}
private void printResults() {
for (DatacenterBroker broker : brokers) {
new CloudletsTableBuilder(broker.getCloudletFinishedList())
.setTitle(broker.getName())
.build();
}
System.out.println();
for (Vm vm : vmList) {
System.out.printf("%s -> Start Time: %.0f Stop Time: %.0f Total Execution Time: %.0f\n",
vm, vm.getStartTime(), vm.getStopTime(), vm.getTotalExecutionTime());
}
System.out.println();
}
private List<DatacenterBroker> createBrokers() {
final List<DatacenterBroker> list = new ArrayList<>(BROKERS);
for(int i = 0; i < BROKERS; i++) {
list.add(new DatacenterBrokerSimple(simulation));
}
return list;
}
/**
* Creates a Datacenter and its Hosts.
*/
private Datacenter createDatacenter() {
final List<Host> hostList = new ArrayList<>(HOSTS);
for(int i = 0; i < HOSTS; i++) {
hostList.add(createHost());
}
return new DatacenterSimple(simulation, hostList, new VmAllocationPolicySimple());
}
private Host createHost() {
final List<Pe> peList = new ArrayList<>(HOST_PES);
for (int i = 0; i < HOST_PES; i++) {
peList.add(new PeSimple(1000, new PeProvisionerSimple()));
}
final long ram = 2048; //in Megabytes
final long bw = 10000; //in Megabits/s
final long storage = 1000000; //in Megabytes
Host host = new HostSimple(ram, bw, storage, peList);
host
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
.setVmScheduler(new VmSchedulerTimeShared());
return host;
}
private List<Vm> createAndSubmitVms(DatacenterBroker broker) {
final List<Vm> list = new ArrayList<>(VMS);
for (int i = 0; i < VMS; i++) {
Vm vm =
new VmSimple(1000, VM_PES)
.setRam(512).setBw(1000).setSize(10000)
.setCloudletScheduler(new CloudletSchedulerTimeShared());
list.add(vm);
}
broker.submitVmList(list);
return list;
}
private List<Cloudlet> createAndSubmitCloudlets(DatacenterBroker broker) {
final List<Cloudlet> list = new ArrayList<>(CLOUDLETS);
for (int i = 1; i <= CLOUDLETS; i++) {
final UtilizationModel utilization = new UtilizationModelFull();
final Cloudlet cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES);
cloudlet
.setFileSize(1024)
.setOutputSize(1024)
.setUtilizationModel(utilization);
list.add(cloudlet);
}
broker.submitCloudletList(list);
return list;
}
}
......@@ -55,8 +55,9 @@ import java.util.List;
* An example showing how to pause the simulation at a given time in order to collect
* some partial results. In this example, such results are the cloudlets that have finished so far.
* The example creates 4 Cloudlets that will run sequentially using a {@link CloudletSchedulerSpaceShared}.
* The pause is scheduled before the simulation starts, that is the easier way to perform
* such an action.
*
* <p>The pause is scheduled before the simulation starts, which is the <b>easiest way</b> to perform
* such an action.</p>
*
* <p>This example uses CloudSim Plus Listener features to intercept when
* the simulation was paused, allowing to collect the desired data.
......@@ -98,9 +99,6 @@ public class PauseSimulationAtGivenTimeExample1 {
private final DatacenterBrokerSimple broker;
private List<Cloudlet> cloudletList;
private List<Vm> vmList;
private int numberOfCreatedCloudlets = 0;
private int numberOfCreatedVms = 0;
private int numberOfCreatedHosts = 0;
/**
* Starts the simulation.
......@@ -155,7 +153,7 @@ public class PauseSimulationAtGivenTimeExample1 {
* that will be executed only when the simulation is paused.
* */
this.simulation
.addOnSimulationPausedListener(pauseInfo -> printCloudletsFinishedSoFarAndResumeSimulation(pauseInfo));
.addOnSimulationPausedListener(this::printCloudletsFinishedSoFarAndResumeSimulation);
/* Starts the simulation and waits all cloudlets to be executed. */
this.simulation.start();
......@@ -180,19 +178,6 @@ public class PauseSimulationAtGivenTimeExample1 {
.build();
}
/**
* Checks if the Cloudlet that had its processing updated reached 50% of execution.
* If so, request the simulation interruption.
* @param event object containing data about the happened event
*/
private void onClouletProcessingUpdate(CloudletVmEventInfo event) {
if(event.getCloudlet().getFinishedLengthSoFar() >= event.getCloudlet().getLength()/2.0){
Log.printFormattedLine("Cloudlet %d reached 50% of execution. Intentionally requesting termination of the simulation at time %.2f",
event.getCloudlet().getId(), simulation.clock());
simulation.terminate();
}
}
private DatacenterSimple createDatacenter() {
List<Host> hostList = new ArrayList<>();
Host host0 = createHost();
......@@ -204,12 +189,12 @@ public class PauseSimulationAtGivenTimeExample1 {
}
private Host createHost() {
long mips = 1000; // capacity of each CPU core (in Million Instructions per Second)
long ram = 2048; // host memory (MEGABYTE)
long storage = 1000000; // host storage (MEGABYTE)
long bw = 10000; //in Megabits/s
final long mips = 1000; // capacity of each CPU core (in Million Instructions per Second)
final long ram = 2048; // host memory (MEGABYTE)
final long storage = 1000000; // host storage (MEGABYTE)
final long bw = 10000; //in Megabits/s
List<Pe> peList = new ArrayList<>(); //List of CPU cores
final List<Pe> peList = new ArrayList<>(); //List of CPU cores
/*Creates the Host's CPU cores and defines the provisioner
used to allocate each core for requesting VMs.*/
......@@ -218,38 +203,22 @@ public class PauseSimulationAtGivenTimeExample1 {
return new HostSimple(ram, bw, storage, peList)
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
.setVmScheduler(new VmSchedulerTimeShared());
.setVmScheduler(new VmSchedulerTimeShared());
}
private Vm createVm() {
long mips = 1000;
long storage = 10000; // vm image size (MEGABYTE)
int ram = 512; // vm memory (MEGABYTE)
long bw = 1000; // vm bandwidth (Megabits/s)
int pesNumber = 1; // number of CPU cores
return new VmSimple(numberOfCreatedVms++, mips, pesNumber)
.setRam(ram)
.setBw(bw)
.setSize(storage)
return new VmSimple(1000, 1)
.setRam(512)
.setBw(1000)
.setSize(10000)
.setCloudletScheduler(new CloudletSchedulerSpaceShared());
}
private Cloudlet createCloudlet(Vm vm) {
long length = 10000; //in Million Structions (MI)
long fileSize = 300; //Size (in bytes) before execution
long outputSize = 300; //Size (in bytes) after execution
long numberOfCpuCores = vm.getNumberOfPes(); //cloudlet will use all the VM's CPU cores
//Defines how CPU, RAM and Bandwidth resources are used
//Sets the same utilization model for all these resources.
UtilizationModel utilization = new UtilizationModelFull();
return new CloudletSimple(
numberOfCreatedCloudlets++, length, numberOfCpuCores)
.setFileSize(fileSize)
.setOutputSize(outputSize)
.setUtilizationModel(utilization)
return new CloudletSimple(10000, vm.getNumberOfPes())
.setFileSize(300)
.setOutputSize(300)
.setUtilizationModel(new UtilizationModelFull())
.setVm(vm);
}
......
......@@ -28,6 +28,7 @@ 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.core.Simulation;
import org.cloudbus.cloudsim.core.events.SimEvent;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.datacenters.DatacenterSimple;
......@@ -56,7 +57,10 @@ import java.util.List;
* An example showing how to pause the simulation at a given time in order to collect
* some partial results. In this example, such results are the cloudlets that have finished so far.
* The example creates 4 Cloudlets that will run sequentially using a {@link CloudletSchedulerSpaceShared}.
* The pause is scheduled after the simulation starts.
*
* <p>The pause is scheduled after the simulation starts, by adding an