Permalink
Browse files

Closes #81

  • Loading branch information...
RaysaOliveira committed May 15, 2017
1 parent 9aa3e06 commit 8bd5436f8b515ceef1e9ac218be96954cee9caf1
@@ -40,6 +40,8 @@
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.datacenters.DatacenterSimple;
import org.cloudbus.cloudsim.distributions.ContinuousDistribution;
import org.cloudbus.cloudsim.distributions.PoissonDistr;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
@@ -61,7 +63,6 @@
* @since CloudSim Plus 1.2.0
*/
public final class HostFaultInjectionExample1 {
private static final int SCHEDULE_TIME_TO_PROCESS_DATACENTER_EVENTS = 5;
private static final double DATACENTER_COST_PER_CPU = 3.0;
private static final double DATACENTER_COST_PER_RAM = 0.05;
@@ -88,7 +89,7 @@
private static final int VM_PES = 2; //number of cpus
private static final int CLOUDLET_PES = 2;
private static final long CLOUDLET_LENGHT = 200000;
private static final long CLOUDLET_LENGHT = 20_000_000;
private static final long CLOUDLET_FILESIZE = 300;
private static final long CLOUDLET_OUTPUTSIZE = 300;
@@ -99,10 +100,11 @@
private static final int HOSTS = 2;
private static final int VMS = 4;
private static final int CLOUDLETS_BY_VM = 2;
private static final int CLOUDLETS = 4;
private final List<Vm> vmlist = new ArrayList<>();
private CloudSim simulation;
private final DatacenterBroker broker;
/**
* Starts the example.
@@ -121,37 +123,26 @@ public HostFaultInjectionExample1() {
Datacenter datacenter = createDatacenter(HOSTS);
createFaultInjectionForHosts(datacenter);
DatacenterBroker broker = new DatacenterBrokerSimple(simulation);
createAndSubmitVms(broker);
createAndSubmitCloudlets(broker);
broker = new DatacenterBrokerSimple(simulation);
createAndSubmitVms();
createAndSubmitCloudlets();
simulation.start();
new CloudletsTableBuilder(broker.getCloudletsFinishedList()).build();
Log.printConcatLine(getClass().getSimpleName(), " finished!");
//@todo ver a mensagem abaixo
System.out.println("A cloudlet 2 deveria terminar no segundo 40, pois ela iniciou em 10, mas ela não termina");
}
public void createAndSubmitVms(DatacenterBroker broker) {
public void createAndSubmitVms() {
for (int i = 0; i < VMS; i++) {
Vm vm = createVm(broker);
Vm vm = createVm();
vmlist.add(vm);
}
broker.submitVmList(vmlist);
}
/**
*
* @param broker
* @return
*
* @todo @author manoelcampos The use of other CloudletScheduler instead of
* CloudletSchedulerDynamicWorkload makes the Host CPU usage not be updated
* (and maybe VM CPU usage too).
*/
public Vm createVm(DatacenterBroker broker) {
public Vm createVm() {
Vm vm = new VmSimple(vmlist.size(), VM_MIPS, VM_PES);
vm
.setRam(VM_RAM).setBw(VM_BW).setSize(VM_SIZE)
@@ -161,17 +152,15 @@ public Vm createVm(DatacenterBroker broker) {
/**
* Creates the number of Cloudlets defined in
* {@link #CLOUDLETS_BY_VM} and submits them to the
* given broker.
* {@link #CLOUDLETS} and submits them to the
* created broker.
*
* @param broker the broker that the created Cloudlets belong to
* @return the List of created Cloudlets
*/
public List<Cloudlet> createAndSubmitCloudlets(
DatacenterBroker broker) {
final List<Cloudlet> list = new ArrayList<>(CLOUDLETS_BY_VM);
public List<Cloudlet> createAndSubmitCloudlets() {
final List<Cloudlet> list = new ArrayList<>(CLOUDLETS);
UtilizationModel utilizationModel = new UtilizationModelFull();
for (int i = 0; i < CLOUDLETS_BY_VM; i++) {
for (int i = 0; i < CLOUDLETS; i++) {
Cloudlet c
= new CloudletSimple(CLOUDLET_LENGHT, CLOUDLET_PES)
.setFileSize(CLOUDLET_FILESIZE)
@@ -243,12 +232,17 @@ public Host createHost() {
private void createFaultInjectionForHosts(Datacenter datacenter) {
//final long seed = System.currentTimeMillis();
long seed = 3412125;
final double meanFailureNumberPerMinute = 0.4;
HostFaultInjection fault = new HostFaultInjection(host, meanFailureNumberPerMinute, seed++);
/*The average number of failures expected to happen each minute
in a Poisson Process, which is also called event rate or rate parameter.*/
final double meanFailureNumberPerMinute = 0.01;
PoissonDistr poisson = new PoissonDistr(meanFailureNumberPerMinute, seed);
HostFaultInjection fault = new HostFaultInjection(datacenter, poisson);
fault.setVmCloner(this::cloneVm);
fault.setCloudletsCloner(this::cloneCloudlets);
Log.printFormattedLine("\tFault Injection created for %s.", datacenter);
Log.printFormattedLine(
"\tFault Injection created for %s.\n\tMean Number of Failures per Minute: %.2f (1 failure expected at each %.2f minutes).",
datacenter, meanFailureNumberPerMinute, poisson.getInterarrivalMeanTime());
}
/**
@@ -260,6 +254,12 @@ private void createFaultInjectionForHosts(Datacenter datacenter) {
*/
private Vm cloneVm(Vm vm){
Vm clone = new VmSimple((long)vm.getMips(), (int)vm.getNumberOfPes());
/*It' not required to set an ID for the clone.
It is being set here just to make it easy to
relate the ID of the vm to its clone,
since the clone ID will be 10 times the id of its
source VM.*/
clone.setId(vm.getId()*10);
clone.setDescription("Clone of VM " + vm.getId());
clone
.setSize(vm.getStorage().getCapacity())
@@ -296,17 +296,25 @@ private Vm cloneVm(Vm vm){
/**
* Creates a clone from a given Cloudlet.
* @param sourceCloudlet the Cloudlet to be cloned.
* @param source the Cloudlet to be cloned.
* @return the cloned (new) cloudlet
*/
private Cloudlet cloneCloudlet(Cloudlet sourceCloudlet) {
Cloudlet clone = new CloudletSimple(sourceCloudlet.getLength(), (int)sourceCloudlet.getNumberOfPes());
private Cloudlet cloneCloudlet(Cloudlet source) {
Cloudlet clone =
new CloudletSimple(
source.getLength(),
(int)source.getNumberOfPes());
/*It' not required to set an ID for the clone.
It is being set here just to make it easy to
relate the ID of the cloudlet to its clone,
since the clone ID will be 10 times the id of its
source cloudlet.*/
clone.setId(source.getId()*10);
clone
.setUtilizationModelBw(sourceCloudlet.getUtilizationModelBw())
.setUtilizationModelCpu(sourceCloudlet.getUtilizationModelCpu())
.setUtilizationModelRam(sourceCloudlet.getUtilizationModelRam());
.setUtilizationModelBw(source.getUtilizationModelBw())
.setUtilizationModelCpu(source.getUtilizationModelCpu())
.setUtilizationModelRam(source.getUtilizationModelRam());
return clone;
}
}
@@ -28,7 +28,7 @@
*/
package org.cloudsimplus.sla;
import org.cloudbus.cloudsim.distributions.PoissonProcess;
import org.cloudbus.cloudsim.distributions.PoissonDistr;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.cloudlets.Cloudlet;
@@ -147,7 +147,7 @@ public CreateCloudletRandomlyExample() {
long seed = System.currentTimeMillis();
//creates a poisson process that checks the arrival of 1 (k) cloudlet
//1 is the default value for k
PoissonProcess poisson = new PoissonProcess(MEAN_CUSTOMERS_ARRIVAL_PER_MINUTE, seed);
PoissonDistr poisson = new PoissonDistr(MEAN_CUSTOMERS_ARRIVAL_PER_MINUTE, seed);
int totalArrivedCustomers = 0;
int cloudletId = 0;
for (int minute = 0; minute < MAX_TIME_FOR_CLOUDLET_ARRIVAL; minute++) {
@@ -71,8 +71,8 @@ public boolean allocateHostForVm(Vm vm) {
getHostFreePesMap().put(host, hostFreePes - vm.getNumberOfPes());
if(!hostsWhereVmCreationFailed.isEmpty()){
Log.printFormattedLine(
"%.2f: %s: VM #%d was successfully allocated to Host #%d",
vm.getSimulation().clock(), getClass().getSimpleName(), vm.getId(), host.getId());
"%.2f: %s: %s was successfully allocated to %s",
vm.getSimulation().clock(), getClass().getSimpleName(), vm, host);
}
return true;
} else {
@@ -180,7 +180,7 @@ public void submitVmList(List<? extends Vm> list) {
if (isStarted() && !list.isEmpty()) {
Log.printFormattedLine(
"%.2f: %s: List of %d VMs submitted to the broker during simulation execution. VMs creation request sent to Datacenter.",
"%.2f: %s: List of %d VMs submitted to the broker during simulation execution.\n\t VMs creation request sent to Datacenter.",
getSimulation().clock(), getName(), list.size());
requestDatacenterToCreateWaitingVms();
}
@@ -29,7 +29,8 @@
import org.apache.commons.math3.util.CombinatoricsUtils;
/**
* Represents a Poisson Process which models the probability of an event
* A pseudo random number generator which returns numbers
* following a Poisson Distribution, modeling the probability of an event
* to happen a number of times in a given time interval.
*
* @see <a href="https://en.wikipedia.org/wiki/Poisson_distribution">Poisson Distribution</a>
@@ -38,11 +39,12 @@
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.2.0
*/
public class PoissonProcess {
public class PoissonDistr implements ContinuousDistribution {
/**
* A random number generator which returns values between [0 and 1[.
* A Uniform Pseudo Random Number Generator used
* internally to generate Poisson numbers.
*/
private ContinuousDistribution rand;
private UniformDistr rand;
/**
* @see #getLambda()
@@ -55,7 +57,7 @@
private int k;
/**
* Creates a new Poisson process to check
* Creates a new Poisson random number generator to check
* the probability of 1 event ({@link #getK() k}) to happen at each time
* interval.
*
@@ -64,7 +66,7 @@
* @see #setK(int)
* @see #setLambda(double)
*/
public PoissonProcess(double lambda, long seed){
public PoissonDistr(double lambda, long seed){
this.rand = new UniformDistr(seed);
this.k = 1;
this.setLambda(lambda);
@@ -74,11 +76,14 @@ public PoissonProcess(double lambda, long seed){
* Creates a new Poisson process that considers you want to check
* the probability of 1 event ({@link #getK() k}) to happen at each time.
*
* @param lambda average number of events by interval
* @param lambda average number of events by interval.
* For instance, if it was defined 1 event to be expected at
* each 2.5 minutes, it means that 0.4 event is expected
* at each minute (1/2.5).
*
* @see #setK(int)
*/
public PoissonProcess(double lambda){
public PoissonDistr(double lambda){
this(lambda, -1);
}
@@ -132,14 +137,20 @@ public boolean eventsHappened(){
}
/**
* Gets the next time for an event to happen,
* Gets a random number that represents the next time for an event to happen,
* considering the {@link #getLambda() events arrival rate (lambda)}.
* @return
*/
public double getNextArrivalTime(){
@Override
public double sample() {
return Math.exp(1.0 - rand.sample()) / getLambda();
}
@Override
public long getSeed() {
return rand.getSeed();
}
/**
* Gets the number of events to check the probability for them to happen
* in a time interval (default 1).
@@ -198,7 +209,7 @@ public static void main(String args[]){
*/
final int NUMBER_OF_SIMULATIONS = 100;
BiConsumer<PoissonProcess, Integer> printArrivals = (poisson, minute) -> {
BiConsumer<PoissonDistr, Integer> printArrivals = (poisson, minute) -> {
if(showCustomerArrivals)
System.out.printf("%d customers arrived at minute %d\n", poisson.getK(), minute);
};
@@ -207,10 +218,10 @@ public static void main(String args[]){
* A {@link Function} to simulate the arrival of customers for a given time period.
* This is just a method to test the implementation.
*
* @param poisson the PoissonProcess object that will compute the customer arrivals probabilities
* @param poisson the PoissonDistr object that will compute the customer arrivals probabilities
* @return the number of arrived customers
*/
Function<PoissonProcess, Integer> runSimulation = poisson -> {
Function<PoissonDistr, Integer> runSimulation = poisson -> {
/*We want to check the probability of 1 customer to arrive at each
single minute. The default k value is 1, so we dont need to set it.*/
final int totalArrivedCustomers =
@@ -229,10 +240,10 @@ public static void main(String args[]){
};
double customersArrivedInAllSimulations = 0;
PoissonProcess poisson = null;
PoissonDistr poisson = null;
final long seed=System.currentTimeMillis();
for(int i = 0; i < NUMBER_OF_SIMULATIONS; i++){
poisson = new PoissonProcess(MEAN_CUSTOMERS_ARRIVAL_PER_MINUTE, seed+i);
poisson = new PoissonDistr(MEAN_CUSTOMERS_ARRIVAL_PER_MINUTE, seed+i);
System.out.printf("Simulation number %d\n", i);
customersArrivedInAllSimulations += runSimulation.apply(poisson);
}
@@ -247,4 +258,5 @@ public static void main(String args[]){
poisson.getInterarrivalMeanTime());
}
}
}
@@ -254,7 +254,7 @@ private boolean allocateResourcesForVm(Vm vm, boolean inMigration){
if (!getVmScheduler().isSuitableForVm(vm)) {
Log.printFormattedLine(
"%.2f: %s: [%s] Allocation of %s to %s failed due to lack of PEs. Required %.0f MIPS (%d PEs * %.0f MIPS) but there is just %.0f MIPS available.",
"%.2f: %s: [%s] Allocation of %s to %s failed due to lack of PEs.\n\t Required %.0f MIPS (%d PEs * %.0f MIPS) but there is just %.0f MIPS available.",
getSimulation().clock(), getClass().getSimpleName(), msg, vm, this,
vm.getTotalMipsCapacity(), vm.getNumberOfPes(), vm.getMips(),
vmScheduler.getAvailableMips());
@@ -118,13 +118,30 @@ private void allocatePesListForVm(Map.Entry<Vm, List<Double>> entry) {
for (final double requestedMipsForVmPe : entry.getValue()) {
final double allocatedMipsForVmPe = allocateMipsFromHostPesToGivenVirtualPe(vm, requestedMipsForVmPe, hostPesIterator);
if(requestedMipsForVmPe > 0.1 && allocatedMipsForVmPe <= 0.1){
Log.printFormattedLine(
"%s is requiring a total of %.0f MIPS but the PEs of %s currently don't have such an available MIPS amount. Only %.0f MIPS were allocated.",
vm, requestedMipsForVmPe, getHost(), allocatedMipsForVmPe);
logMipsUnavailable(vm, requestedMipsForVmPe, allocatedMipsForVmPe);
}
}
}
/**
* Prints a log showing that the total requested MIPS is not available
* and that just a fraction or zero MIPS were allocated.
*
* @param vm the VM requesting the MIPS
* @param requestedMipsForVmPe the the MIPS requested for a vPE
* @param allocatedMipsForVmPe the actually allocated MIPS for the vPE
*/
private void logMipsUnavailable(final Vm vm, final double requestedMipsForVmPe, final double allocatedMipsForVmPe) {
final String msg = allocatedMipsForVmPe > 0 ?
String.format("Only %.0f MIPS were allocated.", allocatedMipsForVmPe)
: "No MIPS were allocated.";
Log.printFormattedLine(
"%.2f: %s: %s is requiring a total of %.0f MIPS but the PEs of %s\n\t currently don't have such an available MIPS amount. %s",
getHost().getSimulation().clock(),
getClass().getSimpleName(), vm,
requestedMipsForVmPe, getHost(), msg);
}
/**
* Try to allocate MIPS from one or more Host PEs to a specific Virtual PE (PE of a VM).
*
Oops, something went wrong.

0 comments on commit 8bd5436

Please sign in to comment.