Commit 0d5fcc7c authored by Rafael Vieira Falcão's avatar Rafael Vieira Falcão
Browse files

Modification in the Info-Aware allocation policy and new simulation implementation

parent 887a7ae9
package org.cloudbus.cloudsim.examples.autonomic.simulations;
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.ResourceProvisionerShared;
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.VmSchedulerSpaceShared;
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.VmSimple;
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;
public class InfoAwareWithUserError {
private static final int INFO_AWARE_INTERVAL = 1;
private static boolean flagInfoAware = true;
private static int placementInterval = 1;
private static final double HIT_RATE = 0.4;
private static int vmsPlacedID = 60;
private static final int NUMBER_HOSTS = 10;
private static final int HOSTS_PES = 13;
private static final long HOSTS_RAM = Integer.MAX_VALUE;
private static final long HOSTS_STORAGE = Integer.MAX_VALUE;
private static final long HOSTS_BW = Integer.MAX_VALUE;
private static final double HOSTS_MIPS = 100000;
private static final long HOSTS_IOPS = 500;
private static final int NUMBER_VMS_INITIAL = 60;
private static final double VMS_DELAY = 0.0;
private static final int VMS_PES = 1;
private static final long VMS_RAM = 1; //1333;
private static final long VMS_STORAGE = 1; //47500;
private static final long VMS_BW = 1; //10000;
private static final long VMS_CPU_MIPS = 100000;
private static final long VMS_IO_MIPS = 1;
private static final long VMS_CPU_IOPS = 1;
private static final long VMS_IO_IOPS = 500;
private static final int NUMBER_CLOUDLETS_INITIAL = 60;
private static final double CLOUDLET_CPU_BOUND_DELAY = 0.0;
private static final long CLOUDLET_CPU_BOUND_LENGTH = 8640000000L;//500000000; //1000000000;
private static final int CLOUDLET_CPU_BOUND_PES = 1;
private static final int CLOUDLET_CPU_BOUND_IOPS = 0;
private static final double CLOUDLET_IO_BOUND_DELAY = 0.0;
private static final int CLOUDLET_IO_BOUND_LENGTH = 0;
private static final int CLOUDLET_IO_BOUND_PES = 1;
private static final int CLOUDLET_IO_BOUND_IOPS = 3600000;//500000;//1000000;//1666666;//5000000;
// private static final int VM_TOY_ID = 121;
// private static final double VM_TOY_DELAY = 0;
// private static final int VM_TOY_PES = 1;
// private static final long VM_TOY_RAM = 0;
// private static final long VM_TOY_STORAGE = 0;
// private static final long VM_TOY_BW = 100;
// private static final long VM_TOY_MIPS = 1;
// private static final long VM_TOY_IOPS = 0;
//
// private static final int CLOUDLET_TOY_ID = 0;
// private static final double CLOUDLET_TOY_DELAY = 0;
// private static final int CLOUDLET_TOY_LENGTH = 1;
// private static final int CLOUDLET_TOY_PES = 1;
// private static final int CLOUDLET_TOY_IOPS = 0;
private final CloudSim simulation;
private Datacenter datacenter;
private DatacenterBroker broker;
private List<Vm> vmList;
private List<Cloudlet> cloudletList;
private List<Host> hostList;
public static void main(String[] args) {
new InfoAwareWithUserError();
}
public InfoAwareWithUserError() {
Log.printFormattedLine("Starting %s ...", getClass().getSimpleName());
simulation = new CloudSim();
datacenter = createDatacenter(NUMBER_HOSTS);
//Creates a broker that is a software acting on behalf a cloud customer to manage his/her VMs and Cloudlets
broker = new DatacenterBrokerSimple(simulation);
vmList = new ArrayList<>(NUMBER_VMS_INITIAL);
int vmId = 0;
for (int i = 0; i < NUMBER_VMS_INITIAL/10; i++) {
for (int j = vmId; j < vmId + 5; j++) {
vmList.add(createVmSimple(j, VMS_DELAY, VMS_PES, VMS_CPU_MIPS, VMS_RAM,
VMS_BW, VMS_STORAGE, VMS_CPU_IOPS));
}
vmId += 5;
for (int j = vmId; j < vmId + 5; j++) {
vmList.add(createVmSimple(j, VMS_DELAY, VMS_PES, VMS_IO_MIPS, VMS_RAM,
VMS_BW, VMS_STORAGE, VMS_IO_IOPS));
}
vmId += 5;
}
// for (int i = 0; i < NUMBER_VMS_INITIAL/2; i++) {
// vmList.add(createVmSimple(i, VMS_DELAY, VMS_PES, VMS_CPU_MIPS, VMS_RAM,
// VMS_BW, VMS_STORAGE, VMS_CPU_IOPS));
// }
//
// for (int i = NUMBER_VMS_INITIAL/2; i < NUMBER_VMS_INITIAL; i++) {
// vmList.add(createVmSimple(i, VMS_DELAY, VMS_PES, VMS_IO_MIPS, VMS_RAM,
// VMS_BW, VMS_STORAGE, VMS_IO_IOPS));
// }
// vmList.add(createVmSimple(VM_TOY_ID, VM_TOY_DELAY, VM_TOY_PES, VM_TOY_MIPS, VM_TOY_RAM,
// VM_TOY_BW, VM_TOY_STORAGE, VM_TOY_IOPS));
broker.submitVmList(vmList);
cloudletList = new ArrayList<>(NUMBER_CLOUDLETS_INITIAL);
int cloudletId = 0;
for (int i = 0; i < NUMBER_CLOUDLETS_INITIAL/10; i++) {
for (int j = cloudletId; j < cloudletId + 5; j++) {
cloudletList.add(createCloudlets(j, CLOUDLET_CPU_BOUND_DELAY, CLOUDLET_CPU_BOUND_LENGTH,
CLOUDLET_CPU_BOUND_PES, CLOUDLET_CPU_BOUND_IOPS));
}
cloudletId += 5;
for (int j = cloudletId; j < cloudletId + 5; j++) {
cloudletList.add(createCloudlets(j, CLOUDLET_IO_BOUND_DELAY, CLOUDLET_IO_BOUND_LENGTH,
CLOUDLET_IO_BOUND_PES, CLOUDLET_IO_BOUND_IOPS));
}
cloudletId += 5;
}
// for (int i = 0; i < NUMBER_CLOUDLETS_INITIAL/2; i++) {
// cloudletList.add(createCloudlets(i, CLOUDLET_CPU_BOUND_DELAY, CLOUDLET_CPU_BOUND_LENGTH,
// CLOUDLET_CPU_BOUND_PES, CLOUDLET_CPU_BOUND_IOPS));
// }
//
// for (int i = NUMBER_CLOUDLETS_INITIAL/2; i < NUMBER_CLOUDLETS_INITIAL; i++) {
// cloudletList.add(createCloudlets(i, CLOUDLET_IO_BOUND_DELAY, CLOUDLET_IO_BOUND_LENGTH,
// CLOUDLET_IO_BOUND_PES, CLOUDLET_IO_BOUND_IOPS));
// }
// cloudletList.add(createCloudlets(CLOUDLET_TOY_ID, CLOUDLET_TOY_DELAY, CLOUDLET_TOY_LENGTH,
// CLOUDLET_TOY_PES, CLOUDLET_TOY_IOPS));
broker.submitCloudletList(cloudletList);
simulation.addOnClockTickListener(this::clockTickListener);
simulation.start();
final List<Cloudlet> finishedCloudlets = broker.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();
if(time == INFO_AWARE_INTERVAL && flagInfoAware) {
Log.printLine("\n" + info.getTime() + ": # Changing Vm Allocation Policy to: Info-Aware\n");
datacenter = ((DatacenterSimple) datacenter).setVmAllocationPolicy(new VmAllocationPolicyInfoAware());
flagInfoAware = false;
}
/* Checks if the time specified in the scheduling interval has passed. */
if(time == placementInterval) {
// fullHitRatting(info);
variantHitRattingIO(info, HIT_RATE);
variantHitRattingCPU(info, HIT_RATE);
}
if(vmsPlacedID == 120) {
simulation.removeOnClockTickListener(info.getListener());
}
}
private void variantHitRattingIO(EventInfo info, double hitRatting) {
double randomNumber = Math.random();
if(randomNumber <= hitRatting) {
Log.printLine("\n" + info.getTime() + ": # *CORRECT* Placement of one IO-Bound Vm running a IO-Bound Workload\n");
Vm vmIo = createVmIO(vmsPlacedID, VMS_DELAY, VMS_PES, VMS_IO_MIPS,
VMS_RAM, VMS_BW, VMS_STORAGE, VMS_IO_IOPS);
broker.submitVm(vmIo);
Cloudlet cloudletIo = createCloudlets(vmsPlacedID, CLOUDLET_IO_BOUND_DELAY, CLOUDLET_IO_BOUND_LENGTH,
CLOUDLET_IO_BOUND_PES, CLOUDLET_IO_BOUND_IOPS);
broker.submitCloudlet(cloudletIo);
vmsPlacedID++;
placementInterval += 1;
} else {
Log.printLine("\n" + info.getTime() + ": # *WRONG* Placement of one IO-Bound Vm running a CPU-Bound Workload\n");
Vm vmCPU = createVmIO(vmsPlacedID, VMS_DELAY, VMS_PES, VMS_CPU_MIPS,
VMS_RAM, VMS_BW, VMS_STORAGE, VMS_CPU_IOPS);
broker.submitVm(vmCPU);
Cloudlet cloudletCPU = createCloudlets(vmsPlacedID, CLOUDLET_CPU_BOUND_DELAY, CLOUDLET_CPU_BOUND_LENGTH,
CLOUDLET_CPU_BOUND_PES, CLOUDLET_CPU_BOUND_IOPS);
broker.submitCloudlet(cloudletCPU);
vmsPlacedID++;
placementInterval += 1;
}
}
private void variantHitRattingCPU(EventInfo info, double hitRatting) {
double randomNumber = Math.random();
if(randomNumber <= hitRatting) {
Log.printLine("\n" + info.getTime() + ": # *CORRECT* Placement of one CPU-Bound Vm running a CPU-Bound Workload\n");
Vm vmCPU = createVmCPU(vmsPlacedID, VMS_DELAY, VMS_PES, VMS_CPU_MIPS,
VMS_RAM, VMS_BW, VMS_STORAGE, VMS_CPU_IOPS);
broker.submitVm(vmCPU);
Cloudlet cloudletCPU = createCloudlets(vmsPlacedID, CLOUDLET_CPU_BOUND_DELAY, CLOUDLET_CPU_BOUND_LENGTH,
CLOUDLET_CPU_BOUND_PES, CLOUDLET_CPU_BOUND_IOPS);
broker.submitCloudlet(cloudletCPU);
vmsPlacedID++;
placementInterval += 1;
} else {
Log.printLine("\n" + info.getTime() + ": # *WRONG* Placement of one CPU-Bound Vm running a IO-Bound Workload\n");
Vm vmIO = createVmCPU(vmsPlacedID, VMS_DELAY, VMS_PES, VMS_IO_MIPS,
VMS_RAM, VMS_BW, VMS_STORAGE, VMS_IO_IOPS);
broker.submitVm(vmIO);
Cloudlet cloudletIO = createCloudlets(vmsPlacedID, CLOUDLET_IO_BOUND_DELAY, CLOUDLET_IO_BOUND_LENGTH,
CLOUDLET_IO_BOUND_PES, CLOUDLET_IO_BOUND_IOPS);
broker.submitCloudlet(cloudletIO);
vmsPlacedID++;
placementInterval += 1;
}
}
private void fullHitRatting(EventInfo info) {
Log.printLine("\n" + info.getTime() + ": # Placement of one IO-Bound and one CPU-Bound VM\n");
Vm vmIo = createVmIO(vmsPlacedID, VMS_DELAY, VMS_PES, VMS_IO_MIPS,
VMS_RAM, VMS_BW, VMS_STORAGE, VMS_IO_IOPS);
broker.submitVm(vmIo);
Cloudlet cloudletIo = createCloudlets(vmsPlacedID, CLOUDLET_IO_BOUND_DELAY, CLOUDLET_IO_BOUND_LENGTH,
CLOUDLET_IO_BOUND_PES, CLOUDLET_IO_BOUND_IOPS);
broker.submitCloudlet(cloudletIo);
vmsPlacedID++;
Vm vmCPU = createVmCPU(vmsPlacedID, VMS_DELAY, VMS_PES, VMS_CPU_MIPS,
VMS_RAM, VMS_BW, VMS_STORAGE, VMS_CPU_IOPS);
broker.submitVm(vmCPU);
Cloudlet cloudletCPU = createCloudlets(vmsPlacedID, CLOUDLET_CPU_BOUND_DELAY, CLOUDLET_CPU_BOUND_LENGTH,
CLOUDLET_CPU_BOUND_PES, CLOUDLET_CPU_BOUND_IOPS);
broker.submitCloudlet(cloudletCPU);
vmsPlacedID++;
placementInterval += 1;
}
private Datacenter createDatacenter(int numberOfHosts) {
hostList = new ArrayList<>(numberOfHosts);
for (int i = 0; i < numberOfHosts/2; i++) {
Host host = createHostShared(HOSTS_PES, HOSTS_MIPS, HOSTS_RAM, HOSTS_IOPS, HOSTS_BW, HOSTS_STORAGE);
hostList.add(host);
}
for(int i = 0; i < numberOfHosts/2; i++) {
Host host = createHostShared(HOSTS_PES, HOSTS_MIPS, HOSTS_RAM, HOSTS_IOPS, HOSTS_BW, HOSTS_STORAGE);
hostList.add(host);
}
final int SCHEDULING_INTERVAL = 1;
final Datacenter dc = new DatacenterSimple(simulation, hostList, new VmAllocationPolicySimple());
dc.setSchedulingInterval(SCHEDULING_INTERVAL);
return dc;
}
// private Host createHostSimple(int hostPes, double mipsPerPe, long ram, long iops, long bw, long storage) {
// List<Pe> peList = new ArrayList<>(hostPes);
// for (int i = 0; i < hostPes; i++) {
// peList.add(new PeSimple(mipsPerPe, new PeProvisionerSimple()));
// }
//
// ResourceProvisioner ramProvisioner = new ResourceProvisionerSimple();
// ResourceProvisioner bwProvisioner = new ResourceProvisionerSimple();
// ResourceProvisioner iopsProvisioner = new ResourceProvisionerSimple();
// VmScheduler vmScheduler = new VmSchedulerSpaceShared();
// Host host = new HostSimple(ram, iops, bw, storage, peList);
// host
// .setRamProvisioner(ramProvisioner)
// .setBwProvisioner(bwProvisioner)
// .setIopsProvisioner(iopsProvisioner)
// .setVmScheduler(vmScheduler);
// return host;
// }
private Host createHostShared(int hostPes, double mipsPerPe, long ram, long iops, long bw, long storage) {
List<Pe> peList = new ArrayList<>(hostPes);
for (int i = 0; i < hostPes; i++) {
peList.add(new PeSimple(mipsPerPe, new PeProvisionerSimple()));
}
ResourceProvisioner ramProvisioner = new ResourceProvisionerSimple();
ResourceProvisioner bwProvisioner = new ResourceProvisionerSimple();
ResourceProvisioner iopsProvisioner = new ResourceProvisionerShared();
VmScheduler vmScheduler = new VmSchedulerSpaceShared();
Host host = new HostSimple(ram, iops, bw, storage, peList);
host
.setRamProvisioner(ramProvisioner)
.setBwProvisioner(bwProvisioner)
.setIopsProvisioner(iopsProvisioner)
.setVmScheduler(vmScheduler);
return host;
}
private Vm createVmIO(int id, double delayTime, int pes, long mipsCapacity, long ram, long bw, long storage, long iops) {
Vm vm =
new VmWithMetadata(id, mipsCapacity, pes, new HashMap<VmLabel,VmData>())
.setRam(ram).setBw(bw).setSize(storage).setIops(iops)
.setCloudletScheduler(new CloudletSchedulerTimeShared());
((VmWithMetadata) vm).putMetadata(VmLabel.TYPE, VmData.IO);
vm.getUtilizationHistory().enable();
vm.setSubmissionDelay(delayTime);
return vm;
}
private Vm createVmCPU(int id, double delayTime, int pes, long mipsCapacity, long ram, long bw, long storage, long iops) {
Vm vm =
new VmWithMetadata(id, mipsCapacity, pes, new HashMap<VmLabel,VmData>())
.setRam(ram).setBw(bw).setSize(storage).setIops(iops)
.setCloudletScheduler(new CloudletSchedulerTimeShared());
((VmWithMetadata) vm).putMetadata(VmLabel.TYPE, VmData.CPU);
vm.getUtilizationHistory().enable();
vm.setSubmissionDelay(delayTime);
return vm;
}
private Vm createVmSimple(int id, double delayTime, int pes, long mipsCapacity, long ram, long bw, long storage, long iops) {
Vm vm =
new VmSimple(id, mipsCapacity, pes)
.setRam(ram).setBw(bw).setSize(storage)
.setCloudletScheduler(new CloudletSchedulerTimeShared())
.setIops(iops);
vm.getUtilizationHistory().enable();
vm.setSubmissionDelay(delayTime);
return vm;
}
private Cloudlet createCloudlets(int id, double delayTime, long length, long pes, long iops) {
UtilizationModel utilization = new UtilizationModelFull();
Cloudlet cloudlet =
new CloudletSimple(id, length, pes)
.setFileSize(1024)
.setOutputSize(1024)
.setUtilizationModel(utilization)
.setIops(iops);
cloudlet.setSubmissionDelay(delayTime);
return cloudlet;
}
}
......@@ -34,7 +34,7 @@ public class VmAllocationPolicyInfoAware extends VmAllocationPolicyAbstract{
Host chosenHost = null;
long totalResourceUsageChosenHost = Long.MAX_VALUE;
for(Host h : this.getHostList()){
long totalResourceUsage = 0;
long totalResourceUsage = h.getVmList().size();
for(Vm vmAux : h.getVmList()){
switch(resourceRequired){
case CPU:
......
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