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

Updating Info-Aware simulation code

parent 0f82c270
......@@ -10,6 +10,7 @@ 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.cloudlets.Cloudlet.Status;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.datacenters.DatacenterSimple;
......@@ -25,6 +26,7 @@ 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.schedulers.vm.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.util.Log;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModel;
......@@ -115,10 +117,10 @@ public class InfoAwareSimulation {
* Cloudlet of the vm IO-Bound
*/
private static final int CLOUDLET_IO_BOUND_ID = 2;
private static final double CLOUDLET_IO_BOUND_DELAY = 0.0;
private static final int CLOUDLET_IO_BOUND_LENGTH = 0;
private static final double CLOUDLET_IO_BOUND_DELAY = 0;
private static final int CLOUDLET_IO_BOUND_LENGTH = 11250;
private static final int CLOUDLET_IO_BOUND_PES = 1;
private static final int CLOUDLET_IO_BOUND_IOPS = 1000000; // IO-Bound workload (Set a high duration time)
private static final int CLOUDLET_IO_BOUND_IOPS = 5000000; // IO-Bound workload (Set a high duration time)
private static final int NUMBER_VMS_LAUNCHED = 4;
......@@ -140,7 +142,7 @@ public class InfoAwareSimulation {
*/
private static final double CLOUDLET_LAUNCHED_DELAY = 0;
private static final int CLOUDLET_LAUNCHED_LENGTH = 11250;
private static final int CLOUDLET_LAUNCHED_PES = 4;
private static final int CLOUDLET_LAUNCHED_PES = 2; // 4 ou 2? duvida lucas
private static final int CLOUDLET_LAUNCHED_IOPS = 900000; // IO-Bound workload
......@@ -156,6 +158,7 @@ public class InfoAwareSimulation {
}
public InfoAwareSimulation() {
Log.printFormattedLine("Starting %s ...", getClass().getSimpleName());
simulation = new CloudSim();
datacenter = createDatacenter(2);
......@@ -165,9 +168,9 @@ public class InfoAwareSimulation {
// Setting Initial Setup
vmList = new ArrayList<>(NUMBER_VMS);
vmList.add(createVmSimple(VM_CPU_BOUND_ID, VM_CPU_BOUND_DELAY, VM_CPU_BOUND_PES, VM_CPU_BOUND_MIPS, VM_CPU_BOUND_RAM,
vmList.add(createVmCPU(VM_CPU_BOUND_ID, VM_CPU_BOUND_DELAY, VM_CPU_BOUND_PES, VM_CPU_BOUND_MIPS, VM_CPU_BOUND_RAM,
VM_CPU_BOUND_BW, VM_CPU_BOUND_STORAGE, VM_CPU_BOUND_IOPS));
vmList.add(createVmSimple(VM_IO_BOUND_ID, VM_IO_BOUND_DELAY, VM_IO_BOUND_PES, VM_IO_BOUND_MIPS, VM_IO_BOUND_RAM,
vmList.add(createVmIO(VM_IO_BOUND_ID, VM_IO_BOUND_DELAY, VM_IO_BOUND_PES, VM_IO_BOUND_MIPS, VM_IO_BOUND_RAM,
VM_IO_BOUND_BW, VM_IO_BOUND_STORAGE, VM_IO_BOUND_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));
......@@ -177,7 +180,7 @@ public class InfoAwareSimulation {
cloudletList = new ArrayList<>(NUMBER_CLOUDLETS);
cloudletList.add(createCloudlets(CLOUDLET_CPU_BOUND_ID, CLOUDLET_CPU_BOUND_DELAY, CLOUDLET_CPU_BOUND_LENGTH,
CLOUDLET_CPU_BOUND_PES, CLOUDLET_CPU_BOUND_IOPS));
CLOUDLET_CPU_BOUND_PES, CLOUDLET_CPU_BOUND_IOPS));
cloudletList.add(createCloudlets(CLOUDLET_IO_BOUND_ID, 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,
......@@ -246,18 +249,15 @@ public class InfoAwareSimulation {
/* Checks if the time specified in the scheduling interval has passed. */
if(time == SCHEDULING_INTERVAL) {
Log.printLine("\n" + info.getTime() + ": # Changing Vm Allocation Policy to: Info-Aware");
datacenter = ((DatacenterSimple) datacenter).setVmAllocationPolicy(new VmAllocationPolicyInfoAware());
//Log.printLine("\n" + info.getTime() + ": # Changing Vm Allocation Policy to: Info-Aware");
//datacenter = ((DatacenterSimple) datacenter).setVmAllocationPolicy(new VmAllocationPolicyInfoAware());
List<Vm> listVmsLaunched = new ArrayList<>(NUMBER_VMS_LAUNCHED);
for (int i = 3; i < NUMBER_VMS_LAUNCHED + 3; i++) {
Vm vm =
new VmWithMetadata(i, VM_LAUNCHED_MIPS, VM_LAUNCHED_PES, new HashMap<VmLabel,VmData>())
.setRam(VM_LAUNCHED_RAM).setBw(VM_LAUNCHED_BW).setSize(VM_LAUNCHED_DISK).setIops(VM_LAUNCHED_IOPS)
.setCloudletScheduler(new CloudletSchedulerTimeShared());
((VmWithMetadata) vm).putMetadata(VmLabel.TYPE, VmData.IO);
Vm vm = createVmCPU(i, VM_LAUNCHED_DELAY, VM_LAUNCHED_PES, VM_LAUNCHED_MIPS,
VM_LAUNCHED_RAM, VM_LAUNCHED_BW, VM_LAUNCHED_DISK, VM_LAUNCHED_IOPS);
vm.setSubmissionDelay(VM_LAUNCHED_DELAY);
listVmsLaunched.add(vm);
......@@ -281,7 +281,6 @@ public class InfoAwareSimulation {
}
}
private Datacenter createDatacenter(int numberOfHosts) {
hostList = new ArrayList<>(numberOfHosts);
for(int i = 0; i < numberOfHosts; i++) {
......@@ -308,7 +307,7 @@ public class InfoAwareSimulation {
ResourceProvisioner ramProvisioner = new ResourceProvisionerSimple();
ResourceProvisioner bwProvisioner = new ResourceProvisionerSimple();
ResourceProvisioner iopsProvisioner = new ResourceProvisionerShared();
VmScheduler vmScheduler = new VmSchedulerTimeShared();
VmScheduler vmScheduler = new VmSchedulerSpaceShared();
Host host = new HostSimple(ram, iops, bw, storage, peList);
host.setPowerModel(powerModel);
host
......@@ -319,6 +318,32 @@ public class InfoAwareSimulation {
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)
......
......@@ -12,6 +12,7 @@ import org.apache.commons.lang3.tuple.Triple;
import org.cloudbus.cloudsim.resources.Pe;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudbus.cloudsim.resources.ResourceManageable;
import org.cloudbus.cloudsim.util.Log;
import java.util.ArrayList;
import java.util.Collections;
......@@ -57,6 +58,7 @@ public class ResourceProvisionerShared extends ResourceProvisionerAbstract {
@Override
public boolean allocateResourceForVm(final Vm vm, final long newTotalVmResourceCapacity) {
Objects.requireNonNull(vm);
if (!isSuitableForVm(vm, newTotalVmResourceCapacity)) {
return false;
......@@ -72,11 +74,21 @@ public class ResourceProvisionerShared extends ResourceProvisionerAbstract {
//Deallocates any amount of the resource assigned to the Vm in order to allocate a new capacity
deallocateResourceForVm(vm);
}
/*
Pe resources are not stored in the VM resource List.
Only the provisioner keeps track of Pe allocation for VM.
This way, if the resource is not found inside the VM
and it is a Pe, it's OK (as it is expected)
*/
//if(!getResource().isObjectSubClassOf(Pe.class) && !vm.getResource(getResourceClass()).setCapacity(newTotalVmResourceCapacity)){
// return false;
//}
//Allocates the requested resource from the physical resource
getResource().allocateResource(newTotalVmResourceCapacity);
getResourceAllocationMap().put(vm, newTotalVmResourceCapacity);
vm.getResource(getResourceClass()).setAllocatedResource(prevVmResourceAllocation);
vm.getResource(getResourceClass()).setAllocatedResource(newTotalVmResourceCapacity);
return true;
}
}
......
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