Skip to content

Commit

Permalink
- Moves VmCost from testbeds module to cloudsim-plus module, inside t…
Browse files Browse the repository at this point in the history
…he vms package.

- Changes order of parameters in ResourceLoader methods for consistence.
- Refactors CloudletTaskCompletionTimeMinimization experiments to remove code duplication.

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
  • Loading branch information
manoelcampos committed Nov 23, 2018
1 parent 9133a79 commit 981b8df
Show file tree
Hide file tree
Showing 28 changed files with 447 additions and 668 deletions.
2 changes: 1 addition & 1 deletion cloudsim-plus-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.cloudsimplus</groupId>
<artifactId>cloudsim-plus-benchmarks</artifactId>
<version>4.0.4</version>
<version>4.0.5</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>
Expand Down
2 changes: 1 addition & 1 deletion cloudsim-plus-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.cloudsimplus</groupId>
<artifactId>cloudsim-plus-examples</artifactId>
<version>4.0.4</version>
<version>4.0.5</version>
<name>CloudSim Plus Examples</name>
<description>
Ready-to-run examples of how to use CloudSim Plus API.
Expand Down
2 changes: 1 addition & 1 deletion cloudsim-plus-testbeds/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.cloudsimplus</groupId>
<artifactId>cloudsim-plus-testbeds</artifactId>
<version>4.0.4</version>
<version>4.0.5</version>
<name>CloudSim Plus Testbeds</name>
<description>
A set of more complex and comprehensive CloudSim Plus testbeds used to assess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
*
* @param <T> the class of experiment the runner will execute
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.0
*/
public abstract class ExperimentRunner<T extends SimulationExperiment> implements Runnable {
private boolean verbose;
Expand All @@ -53,6 +54,7 @@ public abstract class ExperimentRunner<T extends SimulationExperiment> implement
private long baseSeed;

private List<Long> seeds;

/**
* @see #getSimulationRuns()
*/
Expand Down Expand Up @@ -81,15 +83,17 @@ public abstract class ExperimentRunner<T extends SimulationExperiment> implement
/**
* Creates an experiment runner, setting the
* {@link #getBaseSeed() base seed} as the current time.
* @param antitheticVariatesTechnique indicates if it's to be applied the <a href="https://en.wikipedia.org/wiki/Antithetic_variates">antithetic variates technique</a>.
* @param antitheticVariatesTechnique indicates if it's to be applied the
* <a href="https://en.wikipedia.org/wiki/Antithetic_variates">antithetic variates technique</a>.
*/
public ExperimentRunner(final boolean antitheticVariatesTechnique) {
this(antitheticVariatesTechnique, System.currentTimeMillis());
}

/**
* Creates an experiment runner with a given {@link #getBaseSeed() base seed}.
* @param antitheticVariatesTechnique indicates if it's to be applied the <a href="https://en.wikipedia.org/wiki/Antithetic_variates">antithetic variates technique</a>.
* @param antitheticVariatesTechnique indicates if it's to be applied the
* <a href="https://en.wikipedia.org/wiki/Antithetic_variates">antithetic variates technique</a>.
* @param baseSeed the seed to be used as base for each experiment seed
*/
public ExperimentRunner(final boolean antitheticVariatesTechnique, final long baseSeed) {
Expand Down Expand Up @@ -433,21 +437,20 @@ long getSeed(final int experimentIndex) {
* Creates a pseudo random number generator (PRNG) for a experiment run that
* generates uniform values between [min and max[. If it is to apply the
* {@link #isApplyAntitheticVariatesTechnique() "Antithetic Variates Technique"}
* to reduce results variance, the second half of experiments will use the
* to reduce results' variance, the second half of experiments will use the
* seeds from the first half.
*
* @param experimentIndex
* @param experimentIndex index of the experiment run to create a PRNG
* @param minValue the minimum value the generator will return (inclusive)
* @param maxValue the maximum value the generator will return (exclusive)
* @return the created PRNG
*
* @see UniformDistr#isApplyAntitheticVariates()
*/
public ContinuousDistribution createRandomGen(int experimentIndex, double minValue, double maxValue) {
protected ContinuousDistribution createRandomGen(final int experimentIndex, final double minValue, final double maxValue) {
if (isToReuseSeedFromFirstHalfOfExperiments(experimentIndex)) {
final int expIndexFromFirstHalf = experimentIndex - halfSimulationRuns();
return new UniformDistr(minValue, maxValue, seeds.get(expIndexFromFirstHalf))
.setApplyAntitheticVariates(true);
return new UniformDistr(minValue, maxValue, seeds.get(expIndexFromFirstHalf)).setApplyAntitheticVariates(true);
}

return new UniformDistr(minValue, maxValue, seeds.get(experimentIndex));
Expand All @@ -460,16 +463,16 @@ public ContinuousDistribution createRandomGen(int experimentIndex, double minVal
* to reduce results variance, the second half of experiments will used the
* seeds from the first half.
*
* @param experimentIndex
* @param experimentIndex index of the experiment run to create a PRNG
* @return the created PRNG
*
* @see UniformDistr#isApplyAntitheticVariates()
*/
public ContinuousDistribution createRandomGen(int experimentIndex) {
protected ContinuousDistribution createRandomGen(final int experimentIndex) {
return createRandomGen(experimentIndex, 0, 1);
}

public boolean isToReuseSeedFromFirstHalfOfExperiments(int currentExperimentIndex) {
public boolean isToReuseSeedFromFirstHalfOfExperiments(final int currentExperimentIndex) {
return isApplyAntitheticVariatesTechnique() &&
simulationRuns > 1 && currentExperimentIndex >= halfSimulationRuns();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,19 @@
import org.cloudbus.cloudsim.datacenters.DatacenterSimple;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.vms.Vm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.IntStream;

/**
* A base class to implement simulation experiments.
*
* @author Manoel Campos da Silva Filho
*/
public abstract class SimulationExperiment implements Runnable {
protected static final Logger logger = LoggerFactory.getLogger(SimulationExperiment.class.getSimpleName());

private final ExperimentRunner runner;
private final List<Cloudlet> cloudletList;
private final long seed;
Expand Down Expand Up @@ -140,10 +135,6 @@ public List<Vm> getVmList() {
return Collections.unmodifiableList(vmList);
}

protected void setVmList(final List<Vm> vmList) {
this.vmList = Objects.requireNonNull(vmList);
}

/**
* Defines if simulation results of the experiment have to be output or not.
*
Expand Down Expand Up @@ -233,11 +224,9 @@ protected final void buildScenario() {
}

protected void createBrokers() {
IntStream
.range(0, numBrokersToCreate)
.forEach(i -> {
DatacenterBroker broker = createBrokerAndAddToList();
});
for (int i = 0; i < numBrokersToCreate; i++) {
createBrokerAndAddToList();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package org.cloudsimplus.testbeds.sla.taskcompletiontime;

import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
import org.cloudbus.cloudsim.brokers.DatacenterBroker;
import org.cloudbus.cloudsim.brokers.DatacenterBrokerSimple;
import org.cloudbus.cloudsim.cloudlets.Cloudlet;
import org.cloudbus.cloudsim.core.Machine;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple;
import org.cloudbus.cloudsim.resources.Pe;
import org.cloudbus.cloudsim.resources.PeSimple;
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudsimplus.builders.tables.CloudletsTableBuilder;
import org.cloudsimplus.testbeds.ExperimentRunner;
import org.cloudsimplus.testbeds.SimulationExperiment;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import static java.util.Comparator.comparingDouble;

public abstract class AbstractCloudletTaskCompletionTimeExperiment extends SimulationExperiment {
private static final int HOST_PES = 32;
private int hostsNumber;
private int vmsNumber;

protected AbstractCloudletTaskCompletionTimeExperiment(final int index, final ExperimentRunner runner, final long seed) {
super(index, runner, seed);
}

protected DatacenterBroker getFirstBroker() {
return getBrokerList().stream().findFirst().orElse(DatacenterBroker.NULL);
}

protected final void printBrokerFinishedCloudlets(final DatacenterBroker broker) {
final List<Cloudlet> finishedCloudlets = broker.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();
}

/**
* Gets the total number of vPEs (VM PEs) across all existing VMs.
* @return
*/
protected final double getSumPesVms() {
return getVmList().stream()
.mapToDouble(Machine::getNumberOfPes)
.sum();
}

protected final double getSumPesCloudlets() {
return getCloudletList().stream()
.mapToDouble(Cloudlet::getNumberOfPes)
.sum();
}

/**
* Shows the average wait time of all cloudlets
*
* @param cloudletList list of cloudlets
*/
protected final void waitTimeAverage(final List<Cloudlet> cloudletList) {
final double averageWaitTime = cloudletList.stream().mapToDouble(Cloudlet::getWaitingTime).average().orElse(0);
System.out.println("\n# The wait time is: " + averageWaitTime);
}

/**
* Computes the Task Completion Time average for all finished Cloudlets on this
* experiment.
*
* @return the Task Completion Time average
*/
protected double getTaskCompletionTimeAverage() {
final SummaryStatistics cloudletTaskCompletionTime = new SummaryStatistics();
final DatacenterBroker broker = getBrokerList().stream()
.findFirst()
.orElse(DatacenterBroker.NULL);

broker.getCloudletFinishedList().stream()
.map(c -> c.getFinishTime() - c.getLastDatacenterArrivalTime())
.forEach(cloudletTaskCompletionTime::addValue);

return cloudletTaskCompletionTime.getMean();
}


@Override
protected final List<Vm> createVms(final DatacenterBroker broker) {
List<Vm> vmList = new ArrayList<>(vmsNumber);
for (int i = 0; i < vmsNumber; i++) {
Vm vm = createVm();
vmList.add(vm);
}
return vmList;
}

@Override
protected final List<Host> createHosts() {
final List<Host> hostList = new ArrayList<>(hostsNumber);
for (int i = 0; i < hostsNumber; i++) {
hostList.add(createHost());
}
return hostList;
}

@Override
protected final DatacenterBroker createBroker() {
return new DatacenterBrokerSimple(getCloudSim());
}

protected final Host createHost() {
final List<Pe> pesList = new ArrayList<>(HOST_PES);
for (int i = 0; i < HOST_PES; i++) {
pesList.add(new PeSimple(100000, new PeProvisionerSimple()));
}

final Host h = new HostSimple(40960, 10000000, 10000000, pesList)
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
.setVmScheduler(new VmSchedulerTimeShared());
return h;
}

protected abstract Vm createVm();

protected final void setHostsNumber(final int hostsNumber) {
this.hostsNumber = hostsNumber;
}

protected final void setVmsNumber(final int vmsNumber) {
this.vmsNumber = vmsNumber;
}
}

0 comments on commit 981b8df

Please sign in to comment.