Skip to content

Commit

Permalink
refactor: Refactor VerticalVmRamScalingExample
Browse files Browse the repository at this point in the history
- Update docs
- Introduce new constant
- Format resource allocation message

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
  • Loading branch information
manoelcampos committed Oct 25, 2024
1 parent 6177b3b commit e0655c3
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ public class VerticalVmRamScalingExample {
private static final int VM_RAM = 1000;
private static final int VM_PES = 5;
private static final int VM_MIPS = 1000;

/**
* The percentage (in scale from 0 to 1) to scale VM RAM capacity up/down
* when it becomes under/overloaded.
* @see #createVerticalRamScalingForVm(Vm)
*/
private static final double VM_RAM_SCALING_FACTOR = 0.1;

private final CloudSimPlus simulation;
private final DatacenterBroker broker0;
private final List<Host> hostList;
Expand Down Expand Up @@ -172,7 +180,7 @@ private void onClockTickListener(final EventInfo event) {
event.getTime(), vm.getId(), vm.getRam().getPercentUtilization() * 100.0,
vm.getRam().getAllocatedResource(), vm.getRam().getCapacity());

System.out.printf(" | Host Ram Allocation: %6.2f%% (%5d of %5d MB). Running Cloudlets: %d",
System.out.printf(" | Host Ram Allocation: %6.2f%% (%5d of %5d MB). Running Cloudlets: %d%n",
vm.getHost().getRam().getPercentUtilization() * 100,
vm.getHost().getRam().getAllocatedResource(),
vm.getHost().getRam().getCapacity(), vm.getCloudletScheduler().getCloudletExecList().size());
Expand Down Expand Up @@ -241,14 +249,16 @@ private Vm createVm() {
* @see #createListOfScalableVms(int)
*/
private void createVerticalRamScalingForVm(final Vm vm) {
final var verticalRamScaling = new VerticalVmScalingSimple(Ram.class, 0.1);
final var verticalRamScaling = new VerticalVmScalingSimple(Ram.class, VM_RAM_SCALING_FACTOR);

/* By uncommenting the line below, you will see that, instead of gradually
* increasing or decreasing the RAM when the scaling object detects
* the RAM usage is up or down the defined thresholds,
* it will automatically calculate the amount of RAM to add/remove to
* move the VM from the over or under-load condition.
*/
//verticalRamScaling.setResourceScaling(new ResourceScalingInstantaneous());

verticalRamScaling.setLowerThresholdFunction(this::lowerRamUtilizationThreshold)
.setUpperThresholdFunction(this::upperRamUtilizationThreshold);
vm.setRamVerticalScaling(verticalRamScaling);
Expand Down Expand Up @@ -287,13 +297,16 @@ private double upperRamUtilizationThreshold(final Vm vm) {
private void createCloudletList() {
final int initialRamUtilization1 = 100; //MB

// A constant RAM utilization model
final var ramModel1 = new UtilizationModelDynamic(Unit.ABSOLUTE, initialRamUtilization1);
for (long length: CLOUDLET_LENGTHS) {
cloudletList.add(createCloudlet(ramModel1, length));
}

final int initialRamUtilization2 = 10; //MB
final int maxRamUtilization = 500; //MB

// An increasing RAM utilization model
final var ramModel2 = new UtilizationModelDynamic(Unit.ABSOLUTE, initialRamUtilization2);
ramModel2
.setMaxResourceUtilization(maxRamUtilization)
Expand Down

0 comments on commit e0655c3

Please sign in to comment.