Commit c387e015 authored by Eduardo Falcão's avatar Eduardo Falcão
Browse files

merging branch with development (and resolving conflicts)

parents e61ead91 e14d9e54
......@@ -15,6 +15,7 @@ dependency-reduced-pom.xml
*.iml
*.ipr
*.iws
*.orig
#Eclipse project files
.classpath
......
package org.cloudbus.cloudsim.examples.autonomic;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicyInfoAware;
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.CloudletSchedulerSpaceShared;
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.util.Log;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModel;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelFull;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudbus.cloudsim.vms.VmWithMetadata;
import org.cloudbus.cloudsim.vms.VmWithMetadata.VmData;
import org.cloudbus.cloudsim.vms.VmWithMetadata.VmLabel;
import org.cloudsimplus.builders.tables.CloudletsTableBuilder;
import org.cloudsimplus.listeners.EventInfo;
/**
* A CloudSim Plus example which shows the Info-Aware placement
*
* Initially, we have a datacenter managing two hosts.
* After that two VMs, one that will be running a memory bound
* workload and the other one a network bound workload, will be
* allocated (using the VMAllocationPolicySimple), one in each of
* the hosts, and two cloudlets will be launched in each VM, one
* cloudlet with the double of the duration time in comparison with
* the another one. Finally, a third VM (with Memory Bound metadata)
* will be launched in the datacenter using the VmAllocationPolicyInfoAware,
* and it is expected that this VM will be allocated into the host
* with more memory available.
*
* @author Rafael Falcao
*/
public class InfoAwareAllocationExample {
private static final int SCHEDULING_INTERVAL = 0;
private static final int HOSTS = 2;
private static final int HOST_PES = 4;
private static final int VMS = 2;
private static final int VM1_PES = 1;
private static final int VM2_PES = 2;
private static final int VM3_PES = 2;
private static final int CLOUDLETS = 2;
private static final int CLOUDLET_PES = 1;
private static final int CLOUDLET_LENGTH = 10000;
private final CloudSim simulation;
private DatacenterBroker broker0;
private List<Vm> vmList;
private List<Cloudlet> cloudletList;
private Datacenter datacenter0;
public static void main(String[] args) {
new InfoAwareAllocationExample();
}
public InfoAwareAllocationExample() {
simulation = new CloudSim();
datacenter0 = createDatacenter();
//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 = createVms();
cloudletList = createCloudlets();
broker0.submitVmList(vmList);
broker0.submitCloudletList(cloudletList);
simulation.addOnClockTickListener(this::clockTickListener);
simulation.start();
//datacenter0 = ((DatacenterSimple) datacenter0).setVmAllocationPolicy(new VmAllocationPolicyInfoAware());
final List<Cloudlet> finishedCloudlets = broker0.getCloudletFinishedList();
new CloudletsTableBuilder(finishedCloudlets).build();
}
/**
* Event listener which is called every time the simulation clock advances.
* @param info information about the event happened.
*/
private void clockTickListener(final EventInfo info) {
final int time = (int)info.getTime();
/* Checks if the time specified in the scheduling interval has passed. */
if(time == SCHEDULING_INTERVAL) {
Log.printLine("\n" + info.getTime() + ": # Vm Allocation Policy changed to Info-Aware");
datacenter0 = ((DatacenterSimple) datacenter0).setVmAllocationPolicy(new VmAllocationPolicyInfoAware());
Vm vm2 =
new VmWithMetadata(2, 1000, VM3_PES, new HashMap<VmLabel,VmData>())
.setRam(512).setBw(5000).setSize(500000)
.setCloudletScheduler(new CloudletSchedulerTimeShared());
((VmWithMetadata) vm2).putMetadata(VmLabel.TYPE, VmData.RAM);
Log.printLine(info.getTime() + ": # Created " + vm2 + "\n");
broker0.submitVm(vm2);
simulation.removeOnClockTickListener(info.getListener());
}
}
/**
* Creates a Datacenter and its Hosts.
*/
private Datacenter createDatacenter() {
final List<Host> hostList = new ArrayList<>(HOSTS);
for(int i = 0; i < HOSTS; i++) {
Host host = createHost();
hostList.add(host);
}
final Datacenter dc = new DatacenterSimple(simulation, hostList, new VmAllocationPolicySimple());
return dc;
}
private Host createHost() {
List<Pe> peList = new ArrayList<>(HOST_PES);
//List of Host's CPUs (Processing Elements, 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
ResourceProvisioner ramProvisioner = new ResourceProvisionerSimple();
ResourceProvisioner bwProvisioner = new ResourceProvisionerSimple();
VmScheduler vmScheduler = new VmSchedulerTimeShared();
Host host = new HostSimple(ram, bw, storage, peList);
host
.setRamProvisioner(ramProvisioner)
.setBwProvisioner(bwProvisioner)
.setVmScheduler(vmScheduler);
return host;
}
/**
* Creates a list of VMs.
*/
private List<Vm> createVms() {
final List<Vm> list = new ArrayList<>(VMS);
Vm vm0 =
new VmWithMetadata(0, 1000, VM1_PES, new HashMap<VmLabel,VmData>())
.setRam(1526).setBw(2500).setSize(250000)
.setCloudletScheduler(new CloudletSchedulerSpaceShared());
((VmWithMetadata) vm0).putMetadata(VmLabel.TYPE, VmData.RAM);
list.add(vm0);
Vm vm1 =
new VmWithMetadata(1, 1000, VM2_PES, new HashMap<VmLabel,VmData>())
.setRam(1024).setBw(5000).setSize(500000)
.setCloudletScheduler(new CloudletSchedulerSpaceShared());
((VmWithMetadata) vm1).putMetadata(VmLabel.TYPE, VmData.BW);
list.add(vm1);
return list;
}
/**
* Creates a list of Cloudlets.
*/
private List<Cloudlet> createCloudlets() {
final List<Cloudlet> list = new ArrayList<>(CLOUDLETS);
UtilizationModel utilization = new UtilizationModelFull();
for (int i = 0; i < CLOUDLETS; i++) {
Cloudlet cloudlet =
new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_PES)
.setFileSize(1024)
.setOutputSize(1024)
.setUtilizationModel(utilization);
list.add(cloudlet);
}
for (int i = 0; i < CLOUDLETS; i++) {
Cloudlet cloudlet =
new CloudletSimple(i+2, 20000, CLOUDLET_PES)
.setFileSize(1024)
.setOutputSize(1024)
.setUtilizationModel(utilization);
list.add(cloudlet);
}
return list;
}
}
\ No newline at end of file
......@@ -40,6 +40,7 @@ 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.CloudletSchedulerSpaceShared;
import org.cloudbus.cloudsim.schedulers.cloudlet.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.schedulers.vm.VmScheduler;
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerTimeShared;
......@@ -70,9 +71,10 @@ public class BasicFirstExample {
private static final int VMS = 2;
private static final int VM_PES = 4;
private static final int CLOUDLETS = 4;
private static final int CLOUDLET_PES = 2;
private static final int CLOUDLETS = 2;
private static final int CLOUDLET_PES = 4;
private static final int CLOUDLET_LENGTH = 10000;
private static final int CLOUDLET_IOPS = 10000;
private final CloudSim simulation;
private DatacenterBroker broker0;
......@@ -144,9 +146,10 @@ public class BasicFirstExample {
final List<Vm> list = new ArrayList<>(VMS);
for (int i = 0; i < VMS; i++) {
Vm vm =
new VmSimple(i, 1000, VM_PES)
new VmSimple(i,1000, VM_PES)
.setRam(512).setBw(1000).setSize(10000)
.setCloudletScheduler(new CloudletSchedulerTimeShared());
.setCloudletScheduler(new CloudletSchedulerTimeShared())
.setIops(333);
list.add(vm);
}
......@@ -165,7 +168,8 @@ public class BasicFirstExample {
new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_PES)
.setFileSize(1024)
.setOutputSize(1024)
.setUtilizationModel(utilization);
.setUtilizationModel(utilization)
.setIops(CLOUDLET_IOPS);
list.add(cloudlet);
}
......
/*
* 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;
import java.util.ArrayList;
import java.util.List;
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.power.models.PowerModel;
import org.cloudbus.cloudsim.power.models.PowerModelLinear;
import org.cloudbus.cloudsim.power.models.PowerModelSpecPowerLowPowerMode;
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;
/**
* 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.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. Half of
* these cloudlets are created with the length defined by
* {@link #CLOUDLET_LENGTH} and the other half will have the double of this
* length. This way, it's possible to see that for the last half of the
* simulation time, a Host doesn't use the entire CPU capacity, and therefore
* doesn't consume the maximum power.
* </p>
*
* <p>
* However, you may notice in this case that the power usage isn't half of the
* maximum consumption, because there is a minimum amount of power to use, even
* if the Host is idle, which is defined by {@link #STATIC_POWER_PERCENT}. In
* the case of the {@link PowerModelLinear}, there is a constant power which is
* computed 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
*/
public class PowerExampleAutonomic {
/**
* Defines, between other things, the time intervals to keep Hosts CPU
* utilization history records.
*/
private static final int SCHEDULING_INTERVAL = 10;
private static final int HOSTS = 2;
private static final int HOST_PES = 8;
private static final int VMS = 4;
private static final int VM_PES = 4;
private static final int CLOUDLETS = 8;
private static final int CLOUDLET_PES = 2;
private static final int CLOUDLET_LENGTH = 50000;
/**
* Defines the minimum percentage of power a Host uses, even it it's idle.
*/
public static final double STATIC_POWER_PERCENT = 0.7;
/**
* The max number of watt-second (Ws) of power a Host uses.
*/
public static final int MAX_POWER = 100;
private final CloudSim simulation;
private DatacenterBroker broker0;
private List<Vm> vmList;
private List<Cloudlet> cloudletList;
private Datacenter datacenter0;
private final List<Host> hostList;
public static void main(String[] args) {
new PowerExampleAutonomic();
}
public PowerExampleAutonomic() {
simulation = new CloudSim();
hostList = new ArrayList<>(HOSTS);
datacenter0 = createDatacenterSimple();
// Creates a broker that is a software acting on behalf of a cloud customer to
// manage his/her VMs and Cloudlets
broker0 = new DatacenterBrokerSimple(simulation);
vmList = createVms();
cloudletList = createCloudlets();
broker0.submitVmList(vmList);
broker0.submitCloudletList(cloudletList);
simulation.start();
final List<Cloudlet> finishedCloudlets = broker0.getCloudletFinishedList();
new CloudletsTableBuilder(finishedCloudlets).build();
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 (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.
*/
final double[] utilizationPercentHistory = host.getUtilizationHistory();
double totalPower = 0;
double time = simulation.clock();
for (int i = 0; i < utilizationPercentHistory.length; i++) {
final double utilizationPercent = utilizationPercentHistory[i];
/**
* The power consumption is returned in Watt-second, but it's measured the
* continuous consumption before a given time, according to the time interval
* defined by {@link #SCHEDULING_INTERVAL} set to the Datacenter.
*/
final double wattsPerInterval = host.getPowerModel().getPower(utilizationPercent) * SCHEDULING_INTERVAL;
totalPower += wattsPerInterval;
System.out.printf(
"\tTime %6.0f | CPU Utilization %6.2f%% | Power Consumption: %8.2f Watt-Second in %d Seconds\n",
time, utilizationPercent * 100, wattsPerInterval, SCHEDULING_INTERVAL);
time -= SCHEDULING_INTERVAL;
}
System.out.printf(
"Total Host %d Power Consumption in %.0f seconds: %.2f Watt-Second (mean of %.2f Watt-Second) \n",
host.getId(), simulation.clock(), totalPower, totalPower / simulation.clock());
System.out.println(
"-------------------------------------------------------------------------------------------\n");
}
}
/**
* Creates a {@link Datacenter} and its {@link Host}s.
*/
private Datacenter createDatacenterSimple() {
for (int i = 0; i < HOSTS; i++) {
Host host = createPowerHost();
hostList.add(host);
}
final Datacenter dc = new DatacenterSimple(simulation, hostList, new VmAllocationPolicySimple());
dc.setSchedulingInterval(SCHEDULING_INTERVAL);
return dc;
}
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++) {
peList.add(new PeSimple(1000, new PeProvisionerSimple()));
}
// final PowerModel powerModel = new PowerModelSpecPowerDvfsMode();
// final PowerModel powerModel = new PowerModelSpecPowerHighPowerMode();
final PowerModel powerModel = new PowerModelSpecPowerLowPowerMode();
final long ram = 2048; // in Megabytes
final long bw = 10000; // in Megabits/s
final long storage = 1000000; // in Megabytes
final ResourceProvisioner ramProvisioner = new ResourceProvisionerSimple();
final ResourceProvisioner bwProvisioner = new ResourceProvisionerSimple();
final VmScheduler vmScheduler = new VmSchedulerTimeShared();
final Host host = new HostSimple(ram, bw, storage, peList);
host.setPowerModel(powerModel);
host.setRamProvisioner(ramProvisioner).setBwProvisioner(bwProvisioner).setVmScheduler(vmScheduler);
return host;
}
/**
* Creates a list of VMs.
*/
private List<Vm> createVms() {
final List<Vm> list = new ArrayList<>(VMS);
for (int i = 0; i < VMS; i++) {
Vm vm = new VmSimple(i, 1000, VM_PES);
vm.setRam(512).setBw(1000).setSize(10000).setCloudletScheduler(new CloudletSchedulerTimeShared());
vm.getUtilizationHistory().enable();
list.add(vm);
}
return list;
}
/**
* Creates a list of Cloudlets.
*/
private List<Cloudlet> createCloudlets() {
final List<Cloudlet> list = new ArrayList<>(CLOUDLETS);
UtilizationModel utilization = new UtilizationModelFull();
for (int i = 0; i < CLOUDLETS; i++) {
// Sets half of the cloudlets with the defined length and the other half with
// the double of it
final long length = i < CLOUDLETS / 2 ? CLOUDLET_LENGTH : CLOUDLET_LENGTH * 2;
Cloudlet cloudlet = new CloudletSimple(i, length, CLOUDLET_PES).setFileSize(1024).setOutputSize(1024)
.setUtilizationModel(utilization);
list.add(cloudlet);
}
return list;
}
}
......@@ -139,6 +139,7 @@ public final class MigrationExample1 {
* will take 2 seconds to finish, as can be seen in the logs.
*/
private static final long HOST_BW = 16000L; //Mb/s
private static final long HOST_IOPS = 10000L;
/**
* The percentage of host CPU usage that trigger VM migration
......@@ -151,6 +152,7 @@ public final class MigrationExample1 {
private static final int VM_RAM = 10000; //VM memory (MB)
private static final double VM_BW = HOST_BW/(double)VMS;
private static final int VM_PES = 2;
private static final long VM_IOPS = 1000;
private static final long CLOUDLET_LENGHT = 20000;
private static final long CLOUDLET_FILESIZE = 300;
......@@ -261,6 +263,7 @@ public final class MigrationExample1 {
.setOutputSize(CLOUDLET_OUTPUTSIZE)
.setUtilizationModelCpu(cpuUtilizationModel)
.setUtilizationModelRam(utilizationModelFull)
.setUtilizationModelIops(utilizationModelFull)
.setUtilizationModelBw(utilizationModelFull);
broker.bindCloudletToVm(cloudlet, vm);
return cloudlet;
......@@ -280,7 +283,7 @@ public final class MigrationExample1 {
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)
.setRam(VM_RAM).setBw((long)VM_BW).setSize(VM_SIZE).setIops(VM_IOPS)
.setCloudletScheduler(new CloudletSchedulerTimeShared());
return vm;
}
......@@ -382,10 +385,11 @@ public final class MigrationExample1 {
public Host createHost(int numberOfPes, long mipsByPe) {