Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/main/java/org/cloudsimplus/examples/LoggingExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Supplier;

/// An example showing how CloudSim Plus
/// is flexible in managing logs of different entities.
Expand Down Expand Up @@ -109,14 +110,14 @@ private LoggingExample() {
broker0.submitVmList(vmList);

//Creates Cloudlets that uses 5% of all resources all the time
cloudletList = createCloudlets(new UtilizationModelDynamic(0.05));
cloudletList = createCloudlets(() -> new UtilizationModelDynamic(0.05));

//Creates Cloudlets that increase resource utilization along the time
cloudletList.addAll(createCloudlets(createDynamicUtilizationModel()));
cloudletList.addAll(createCloudlets(this::createDynamicUtilizationModel));

//Creates Cloudlets that increase resource utilization along the time,
//but are submitted just after some delay.
cloudletList.addAll(createCloudlets(createDynamicUtilizationModel(), 10));
cloudletList.addAll(createCloudlets(this::createDynamicUtilizationModel, 10));

Comparator<Cloudlet> hostComparator = Comparator.comparingLong(c -> c.getVm().getHost().getId());
cloudletList.sort(hostComparator.thenComparingLong(c -> c.getVm().getId()).thenComparingLong(Identifiable::getId));
Expand Down Expand Up @@ -195,19 +196,25 @@ private List<Vm> createVms() {
}

/// Creates a list of Cloudlets.
/// @param utilizationModel the UtilizationModel to be used for all Cloudlet resources (CPU, RAM and BW).
private List<Cloudlet> createCloudlets(final UtilizationModel utilizationModel) {
return createCloudlets(utilizationModel, 0);
/// @param utilizationModelSupplier creates the UtilizationModel for all resources (CPU, RAM and BW) of each Cloudlet
private List<Cloudlet> createCloudlets(final Supplier<UtilizationModel> utilizationModelSupplier) {
return createCloudlets(utilizationModelSupplier, 0);
}

/// Creates a list of Cloudlets.
/// @param utilizationModel the UtilizationModel to be used for all Cloudlet resources (CPU, RAM and BW).
/// Each Cloudlet gets its own UtilizationModel, since some of them are stateful,
/// such as a [UtilizationModelDynamic] that increases the utilization along the time:
/// it computes each utilization from the previous one and stores it.
/// If many Cloudlets shared such a model, a request from one Cloudlet would change
/// the utilization the others get, giving inaccurate results.
/// That's why CloudSim Plus throws an exception when a stateful model is shared.
/// @param utilizationModelSupplier creates the UtilizationModel for all resources (CPU, RAM and BW) of each Cloudlet
/// @param submissionDelay the delay to submit Cloudlets to the broker
private List<Cloudlet> createCloudlets(final UtilizationModel utilizationModel, final double submissionDelay) {
private List<Cloudlet> createCloudlets(final Supplier<UtilizationModel> utilizationModelSupplier, final double submissionDelay) {
final var list = new ArrayList<Cloudlet>(CLOUDLETS);

for (int i = 0; i < CLOUDLETS; i++) {
final var cloudlet = CloudletSimple.of(CLOUDLET_LENGTH, CLOUDLET_CORES, utilizationModel);
final var cloudlet = CloudletSimple.of(CLOUDLET_LENGTH, CLOUDLET_CORES, utilizationModelSupplier.get());
cloudlet.setSubmissionDelay(submissionDelay);
cloudlet.setSizes(1024);
list.add(cloudlet);
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/org/cloudsimplus/examples/VmDestructionExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,30 @@ private List<Vm> createVms() {
private List<Cloudlet> createCloudlets() {
final var list = new ArrayList<Cloudlet>(CLOUDLETS);
final var utilization = new UtilizationModelFull();

/*Creates a utilization model that enables increasing resource usage over time.
* It is used to define the CPU usage of VMs dynamically.*/
final var dynamicUtilization = new UtilizationModelDynamic();

/// Sets a [Function] that enables the utilization model to increment resource usage by 10% over time.
/// This function is defined using a Lambda Expression.
dynamicUtilization.setUtilizationUpdateFunction(um -> um.getUtilization() + um.getTimeSpan()*0.1);

for (int i = 0; i < CLOUDLETS; i++) {
final var cloudlet =
CloudletSimple.of(i, CLOUDLET_LENGTH, CLOUDLET_CORES)
.setFileSize(1024)
.setOutputSize(1024)
.setUtilizationModelRam(utilization)
.setUtilizationModelBw(utilization)
.setUtilizationModelCpu(dynamicUtilization);
.setUtilizationModelCpu(createDynamicUtilizationModel());
list.add(cloudlet);
}

return list;
}

/// Creates a utilization model that enables increasing resource usage over time.
/// It is used to define the CPU usage of Cloudlets dynamically.
///
/// Since the model has an update function, it's stateful: it computes each utilization
/// from the previous one and stores it. So each Cloudlet needs its own instance.
/// If many Cloudlets shared it, a request from one Cloudlet would change the utilization
/// the others get, giving inaccurate results (CloudSim Plus throws an exception in such a case).
private UtilizationModelDynamic createDynamicUtilizationModel() {
/// Sets a [Function] that enables the utilization model to increment resource usage by 10% over time.
/// This function is defined using a Lambda Expression.
return new UtilizationModelDynamic().setUtilizationUpdateFunction(um -> um.getUtilization() + um.getTimeSpan()*0.1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,12 @@ private void onVmsCreatedListener(final DatacenterBrokerEventInfo info) {

public void createAndSubmitCloudlets(final DatacenterBroker broker) {
final var cloudletList = new ArrayList<Cloudlet>(VM_CORES.length);
final UtilizationModelDynamic um = createCpuUtilizationModel(CLOUDLET_INITIAL_CPU_PERCENTAGE, 1);
for(final var vm: broker.getVmWaitingList()){
final var cloudlet = createCloudlet(vm, um);
/* Each Cloudlet needs its own model, since it increases the CPU usage along the time.
* Such a model is stateful: it computes each utilization from the previous one and stores it.
* If Cloudlets shared it, a request from one Cloudlet would change the utilization the others get,
* giving inaccurate results (CloudSim Plus throws an exception in such a case). */
final var cloudlet = createCloudlet(vm, createCpuUtilizationModel(CLOUDLET_INITIAL_CPU_PERCENTAGE, 1));
cloudletList.add(cloudlet);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,12 @@ private void showHostAllocatedMips(final double time, final Host host) {
public void createAndSubmitCloudlets(DatacenterBroker broker) {
final var newCloudletList = new ArrayList<Cloudlet>(VM_CORES.length);
var cloudlet = Cloudlet.NULL;
UtilizationModelDynamic um = createCpuUtilizationModel(CLOUDLET_INITIAL_CPU_PERCENTAGE, 1);
for(final var vm: vmList){
cloudlet = createCloudlet(vm, broker, um);
/* Each Cloudlet needs its own model, since it increases the CPU usage along the time.
* Such a model is stateful: it computes each utilization from the previous one and stores it.
* If Cloudlets shared it, a request from one Cloudlet would change the utilization the others get,
* giving inaccurate results (CloudSim Plus throws an exception in such a case). */
cloudlet = createCloudlet(vm, broker, createCpuUtilizationModel(CLOUDLET_INITIAL_CPU_PERCENTAGE, 1));
newCloudletList.add(cloudlet);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ public class UtilizationModelStochasticPerformance {
/// Defines if one [UtilizationModel] must be instantiated
/// for each Cloudlet or a single instance used by all Cloudlets.
///
/// Realize that if you use a single [UtilizationModel] for all
/// Cloudlets, the resource utilization will usually be the same
/// for all of them.
/// Using the [UtilizationModelStochastic], if two Cloudlets
/// consecutively request the current resource utilization for the same time,
/// it will be returned the same value. If they send consecutive requests for different times,
/// probably it will be returned distinct randomly generated values.
/// A single [UtilizationModelStochastic] can only be shared by all Cloudlets
/// if [#ALWAYS_GENERATE_NEW_RANDOM_UTILIZATION] is true.
/// Otherwise, the model is stateful: it stores the last utilization generated and returns it
/// to any Cloudlet requesting the utilization for the same time.
/// So Cloudlets sharing it would get the same random values, making their usage fully correlated.
/// That's why CloudSim Plus throws an exception when a stateful model is shared.
/// When using multiple models, each one gets a distinct seed, so that Cloudlets get different values.
private static final boolean MULTIPLE_UTILIZATION_MODELS = false;

/// See [UtilizationModelStochastic#isAlwaysGenNewRandUtilization()]
/// for details.
private static final boolean ALWAYS_GENERATE_NEW_RANDOM_UTILIZATION = false;
private static final boolean ALWAYS_GENERATE_NEW_RANDOM_UTILIZATION = true;

/// Indicates if the [UtilizationModelStochastic] instances
/// will keep a map that stores the resource utilization along simulation
Expand Down Expand Up @@ -219,7 +219,7 @@ private List<Cloudlet> createCloudlets() {
final var newCloudletList = new ArrayList<Cloudlet>(CLOUDLETS);
for (int i = 0; i < CLOUDLETS; i++) {
final var cloudlet = CloudletSimple.of(CLOUDLET_LENGTH, CLOUDLET_CORES);
this.um = MULTIPLE_UTILIZATION_MODELS || this.um == null ? new UtilizationModelStochastic(SEED) : this.um;
this.um = MULTIPLE_UTILIZATION_MODELS || this.um == null ? new UtilizationModelStochastic(SEED + i) : this.um;
this.um
.setHistoryEnabled(STORE_CLOUDLETS_CPU_UTILIZATION_HISTORY)
.setAlwaysGenNewRandUtilization(ALWAYS_GENERATE_NEW_RANDOM_UTILIZATION);
Expand Down
Loading