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

Merge branch 'sla-simulation' of...

Merge branch 'sla-simulation' of https://git.lsd.ufcg.edu.br/lenovo-autonomic/cloudsimplus into sla-simulation
parents 17dd17f5 fbe358a8
......@@ -75,7 +75,8 @@ public class VerticalVmIopsScalingExample {
// Cloudlets
private static final int CLOUDLETS = 1;
private static final int CLOUDLETS_INITIAL_LENGTH = 100_000;
private static final int CLOUDLETS_INITIAL_LENGTH = 1;
private static final int CLOUDLETS_INITIAL_LENGTH_IOPS = 500_000;
private static final int CLOUDLET_PES = 1;
private final CloudSim simulation;
......@@ -84,7 +85,6 @@ public class VerticalVmIopsScalingExample {
private List<Vm> vmList;
private List<Cloudlet> cloudletList;
private int createdCloudlets;
private int createdVms;
public static void main(String[] args) {
......@@ -106,7 +106,7 @@ public class VerticalVmIopsScalingExample {
// cloudletList = new ArrayList<>(CLOUDLETS);
cloudletList = createCloudlets();
simulation = new CloudSim();
simulation = new CloudSim(SCHEDULING_INTERVAL);
simulation.addOnClockTickListener(this::onClockTickListener);
createDatacenter();
......@@ -133,9 +133,8 @@ public class VerticalVmIopsScalingExample {
*/
private void onClockTickListener(EventInfo evt) {
vmList.forEach(vm -> {
Log.printFormatted("\t\tTime %6.1f: Vm %d Disk Usage: %6.2f%% (%2d IOPS. Running Cloudlets: #%d)\n",
Log.printFormatted("\t\tTime %6.1f: Vm %d (%2d IOPS. Running Cloudlets: #%d)\n",
evt.getTime(), vm.getId(),
vm.getIopsVerticalScaling().getResource().getPercentUtilization() * 100.0,
vm.getIops().getCapacity(), vm.getCloudletScheduler().getCloudletExecList().size());
});
}
......@@ -154,7 +153,9 @@ public class VerticalVmIopsScalingExample {
*/
private void createDatacenter() {
for (int i = 0; i < HOSTS; i++) {
hostList.add(createHost());
Host host = createHost();
host.setId(i);
hostList.add(host);
}
Datacenter dc0 = new DatacenterSimple(simulation, hostList, new VmAllocationPolicySimple());
......@@ -309,7 +310,7 @@ public class VerticalVmIopsScalingExample {
UtilizationModel utilization = new UtilizationModelFull();
for (int i = 0; i < CLOUDLETS; i++) {
Cloudlet cloudlet = new CloudletSimple(i, CLOUDLETS_INITIAL_LENGTH, CLOUDLET_PES).setFileSize(1024)
Cloudlet cloudlet = new CloudletSimple(i, CLOUDLETS_INITIAL_LENGTH, CLOUDLETS_INITIAL_LENGTH_IOPS, CLOUDLET_PES).setFileSize(1024)
.setOutputSize(1024).setUtilizationModel(utilization).setUtilizationModelIops(utilization);
list.add(cloudlet);
}
......
......@@ -280,19 +280,24 @@ public abstract class VmAllocationPolicyAbstract implements VmAllocationPolicy {
final ResourceProvisioner provisioner = scaling.getVm().getHost().getProvisioner(resourceClass);
final ResourceManageable vmResource = scaling.getVm().getResource(resourceClass);
final double utilization = vmResource.getPercentUtilization()*100;
final double newTotalVmResource = (double) vmResource.getCapacity() + extraAmountToAllocate;
if(!provisioner.allocateResourceForVm(scaling.getVm(), newTotalVmResource)){
showResourceIsUnavailable(scaling);
return false;
}
scaling.getVm().setIops((long) newTotalVmResource);
Log.printFormattedLine(
"%.2f: %s: %.0f more %s allocated to Vm %d: new capacity is %d. Current resource usage is %.2f%%",
scaling.getVm().getSimulation().clock(),
scaling.getClass().getSimpleName(),
extraAmountToAllocate, resourceClass.getSimpleName(),
scaling.getVm().getId(), vmResource.getCapacity(),
vmResource.getPercentUtilization()*100);
utilization);
return true;
}
......
......@@ -203,8 +203,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
for (Host h : looseSlaHosts) {
for (Vm vm : h.getVmList()) {
// TODO (IF) Create method with code bellow
if (vm.getMonitor().getCumulativeVmViolationTime(clock) + MIGRATION_TIME <=
vm.getMonitor().getMaximumAllowedSlaViolationTime()) {
if (vm.getMonitor().getCumulativeCredit(clock) - MIGRATION_TIME >= 0) {
candidateVmsToMigrate.add(vm);
}
}
......
......@@ -83,7 +83,7 @@ public class VmAllocationPolicyMigrationSlaFixedTightHost extends VmAllocationPo
// Check how good candidate this host is
int creditVms = 0;
for (Vm vm : host.getVmList()) {
if (vm.getMonitor().getVmCredit(clock) - getMIGRATION_TIME() > 0) {
if (vm.getMonitor().getCumulativeCredit(clock) - getMIGRATION_TIME() > 0) {
creditVms++;
}
}
......
......@@ -13,8 +13,6 @@ import org.cloudbus.cloudsim.vms.Vm;
final class ResourceProvisionerNull implements ResourceProvisioner {
public ResourceProvisionerNull() {
// TODO Auto-generated constructor stub
System.out.println("Null created");
}
@Override public boolean allocateResourceForVm(Vm vm, long newTotalVmResourceCapacity) {
......
......@@ -163,7 +163,7 @@ public class CsvGenerator {
writer.append(',');
writer.append(String.valueOf(cl.getVm().getMonitor().getCumulativeVmViolationTime(i)));
writer.append(',');
writer.append(String.valueOf(cl.getVm().getMonitor().getVmCredit(i)));
writer.append(String.valueOf(cl.getVm().getMonitor().getCumulativeCredit(i)));
writer.append('\n');
}
}
......
......@@ -171,8 +171,6 @@ public class VerticalVmScalingSimple extends VmScalingAbstract implements Vertic
@Override
public boolean isVmUnderloaded() {
Vm vm = getVm();
Resource r = getResource();
return getResource().getPercentUtilization() < lowerUtilizationThresholdFunction.apply(getVm());
}
......
package org.cloudsimplus.slametrics;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import org.cloudbus.cloudsim.vms.Vm;
......@@ -10,6 +12,7 @@ import org.cloudbus.cloudsim.vms.VmStateHistoryEntry;
* A class that uses the history and SLA of a VM to monitor
* its credit and/or SLA violation time.
* @author Eduardo de Lucena Falcao (@eduardolfalcao)
* @author Lucas Medeiros Cavalcante (@lcavalcante)
*/
public class SlaMonitor {
......@@ -19,10 +22,118 @@ public class SlaMonitor {
private Vm vm;
private Map<Integer,Boolean> violations;
private Map<Integer,Double> credits;
private int lastElement;
public SlaMonitor(Vm vm) {
this.vm = vm;
this.credits = new HashMap<Integer,Double>();
this.violations = new HashMap<Integer,Boolean>();
this.lastElement = 0;
}
public double getCumulativeCredit(double time) {
double availability = vm.getContract().getAvailabilityMetric().getMinDimension().getValue();
List<VmStateHistoryEntry> stateList = vm.getStateHistory();
double cumulativeCredit = 0;
ListIterator<VmStateHistoryEntry> it = vm.getStateHistory().listIterator(lastElement);
double provisioned = vm.getContract().getIopsProvisioned().getMinDimension().getValue();
if((int) time <= 0) {
return 0;
}
while(it.hasNext()) {
VmStateHistoryEntry state = it.next();
if((int) state.getTime() < (int) time) {
if(credits.containsKey((int) time)) {
cumulativeCredit = credits.get((int) time);
} else {
double dif = calculateMissingCredit((int) state.getTime(), availability, provisioned);
cumulativeCredit = putCredits(state, provisioned, dif, availability);
lastElement = it.nextIndex();
}
}
if ((int) state.getTime() == (int) time){
if(credits.containsKey((int) time)) {
cumulativeCredit = credits.get((int) time);
} else {
double dif = calculateMissingCredit((int) state.getTime(), availability, provisioned);
cumulativeCredit = putCredits(state, provisioned, dif, availability);
lastElement = it.nextIndex();
}
}
}
if(stateList.get(lastElement - 1).getTime() < time) {
VmStateHistoryEntry last = stateList.get(lastElement - 1);
Double previous = credits.get((int) last.getTime());
if (last.getAllocatedIops() < provisioned) {
cumulativeCredit = previous - (((int) time - stateList.get(lastElement - 1).getTime())) * (1 / availability);
} else {
cumulativeCredit = previous + (((int) time - stateList.get(lastElement - 1).getTime())) * (1 / availability);
}
}
return cumulativeCredit;
}
private Double putCredits(VmStateHistoryEntry state, double provisioned, double dif, double availability) {
Double cumulativeCredit;
if(state.getAllocatedIops() < provisioned) {
credits.put((int) state.getTime(), dif - (1 / availability));
}
else {
credits.put((int) state.getTime(), dif + (1 / availability));
}
cumulativeCredit = credits.get((int) state.getTime());
return cumulativeCredit;
}
private double calculateMissingCredit(int time, double availability, double provisioned) {
double prevTime;
VmStateHistoryEntry state;
if(lastElement - 1 > 0) {
if(lastElement - 1 == 0) {
state = vm.getStateHistory().get(lastElement);
} else {
state = vm.getStateHistory().get(lastElement - 1);
}
}
else
state = vm.getStateHistory().get(0);
prevTime = state.getTime();
double previous = previousCredit(time);
double preprevious = previousCredit((int) prevTime);
Double dif;
if (previous == preprevious) {
return previous;
}
if(state.getAllocatedIops() > provisioned)
dif = previous + (1 / availability) * (int )(time - prevTime - 1);
else
dif = previous - (1 / availability) * (int )(time - prevTime - 1);
return dif;
}
private Double previousCredit(int time) {
Double credit = 0.0;
while(time >= 0) {
time--;
if(this.credits.containsKey(time)) {
credit = this.credits.get(time);
break;
}
}
return credit;
}
public boolean isTheIopsSlaBeingViolated(double time){
......@@ -50,10 +161,6 @@ public class SlaMonitor {
return false;
}
public double getVmCredit(double time){
return Math.max(0, getMaximumAllowedSlaViolationTime() - getCumulativeVmViolationTime(time));
}
public long getInstantaneousVmViolationTime(int time){
if(violations.containsKey(time)){
return violations.get(time)?1:0;
......
......@@ -18,7 +18,8 @@ public class SlaMonitorTest {
private static final long MINIMUM_IOPS = 500;
private static final double MINIMUM_AVAILABILITY = 99.9;
private static final long INITIAL_CREDIT = (long) ((100-MINIMUM_AVAILABILITY)*SlaMonitor.SECONDS_OF_A_MONTH);
private static final double STEP_CREDIT = 1 / MINIMUM_AVAILABILITY;
private static SlaContract contract;
private static double imprecision = 0.0001;
......@@ -75,27 +76,30 @@ public class SlaMonitorTest {
}
@Test
public void getVmCredit_test() {
Vm vm = new VmSimple(0, 0);
vm.addStateHistoryEntry(new VmStateHistoryEntry(1,0,0,400,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(2,0,0,500,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(3,0,0,500,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(4,0,0,600,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(5,0,0,600,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(11,0,0,400,0,false));
vm.setContract(contract);
assertEquals(INITIAL_CREDIT, vm.getMonitor().getVmCredit(0), imprecision);
assertEquals(INITIAL_CREDIT-1, vm.getMonitor().getVmCredit(1), imprecision);
assertEquals(INITIAL_CREDIT-1, vm.getMonitor().getVmCredit(2), imprecision);
assertEquals(INITIAL_CREDIT-1, vm.getMonitor().getVmCredit(3), imprecision);
assertEquals(INITIAL_CREDIT-1, vm.getMonitor().getVmCredit(4), imprecision);
assertEquals(INITIAL_CREDIT-1, vm.getMonitor().getVmCredit(5), imprecision);
assertEquals(INITIAL_CREDIT-2, vm.getMonitor().getVmCredit(11), imprecision);
assertEquals(INITIAL_CREDIT-6, vm.getMonitor().getVmCredit(15), imprecision);
assertEquals(0, vm.getMonitor().getVmCredit(INITIAL_CREDIT+10000), imprecision);
public void getVmCredit_test() {
Vm vm = new VmSimple(0, 0);
vm.addStateHistoryEntry(new VmStateHistoryEntry(1,0,0,400,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(2,0,0,500,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(3,0,0,500,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(4,0,0,600,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(5,0,0,600,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(11,0,0,400,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(16,0,0,500,0,false));
vm.setContract(contract);
assertEquals(0, vm.getMonitor().getCumulativeCredit(0), imprecision);
assertEquals(-1 * STEP_CREDIT, vm.getMonitor().getCumulativeCredit(1), imprecision);
assertEquals(0, vm.getMonitor().getCumulativeCredit(2), imprecision);
assertEquals(1 * STEP_CREDIT, vm.getMonitor().getCumulativeCredit(3), imprecision);
assertEquals(2 * STEP_CREDIT, vm.getMonitor().getCumulativeCredit(4), imprecision);
assertEquals(3 * STEP_CREDIT, vm.getMonitor().getCumulativeCredit(5), imprecision);
assertEquals(7 * STEP_CREDIT, vm.getMonitor().getCumulativeCredit(11), imprecision);
assertEquals(3 * STEP_CREDIT, vm.getMonitor().getCumulativeCredit(15), imprecision);
assertEquals(4 * STEP_CREDIT, vm.getMonitor().getCumulativeCredit(16), imprecision);
assertEquals(1184 * STEP_CREDIT, vm.getMonitor().getCumulativeCredit(1196), imprecision);
}
@Test
public void getVmCreditAfterOneMonth_test() {
Vm vm = new VmSimple(0, 0);
......@@ -104,11 +108,15 @@ public class SlaMonitorTest {
vm.addStateHistoryEntry(new VmStateHistoryEntry(SlaMonitor.SECONDS_OF_A_MONTH+5,0,0,400,0,false));
vm.setContract(contract);
assertEquals(INITIAL_CREDIT, vm.getMonitor().getVmCredit(0), imprecision);
assertEquals(0, vm.getMonitor().getVmCredit(INITIAL_CREDIT), imprecision);
assertEquals(INITIAL_CREDIT, vm.getMonitor().getVmCredit(SlaMonitor.SECONDS_OF_A_MONTH), imprecision);
assertEquals(INITIAL_CREDIT-1, vm.getMonitor().getVmCredit(SlaMonitor.SECONDS_OF_A_MONTH+5), imprecision);
assertEquals(INITIAL_CREDIT-101, vm.getMonitor().getVmCredit(SlaMonitor.SECONDS_OF_A_MONTH+105), imprecision);
assertEquals(0, vm.getMonitor().getCumulativeCredit(0), imprecision);
assertEquals(-1 * STEP_CREDIT, vm.getMonitor().getCumulativeCredit(1), 0); // starts indebted
assertEquals((-1 * STEP_CREDIT) * (SlaMonitor.SECONDS_OF_A_MONTH -1),vm.getMonitor().getCumulativeCredit((SlaMonitor.SECONDS_OF_A_MONTH -1)), imprecision);
assertEquals((-1 * STEP_CREDIT) * (SlaMonitor.SECONDS_OF_A_MONTH -2),vm.getMonitor().getCumulativeCredit((SlaMonitor.SECONDS_OF_A_MONTH)), imprecision);
assertEquals((-1 * STEP_CREDIT) * (SlaMonitor.SECONDS_OF_A_MONTH -6), vm.getMonitor().getCumulativeCredit(SlaMonitor.SECONDS_OF_A_MONTH + 4), imprecision);
assertEquals((STEP_CREDIT) * (-1 * SlaMonitor.SECONDS_OF_A_MONTH -5), vm.getMonitor().getCumulativeCredit(SlaMonitor.SECONDS_OF_A_MONTH + 5), 0.2);
assertEquals((STEP_CREDIT) * (-1 * SlaMonitor.SECONDS_OF_A_MONTH -15), vm.getMonitor().getCumulativeCredit(SlaMonitor.SECONDS_OF_A_MONTH + 15), 0.2);
assertEquals((STEP_CREDIT) * (-1 * SlaMonitor.SECONDS_OF_A_MONTH -55), vm.getMonitor().getCumulativeCredit(SlaMonitor.SECONDS_OF_A_MONTH + 55), 0.2);
assertEquals((STEP_CREDIT) * (-1 * SlaMonitor.SECONDS_OF_A_MONTH -101), vm.getMonitor().getCumulativeCredit(SlaMonitor.SECONDS_OF_A_MONTH + 101), 0.2);
}
@Test
......@@ -139,7 +147,7 @@ public class SlaMonitorTest {
vm.setContract(contract);
assertEquals(0, vm.getMonitor().getCumulativeVmViolationTime(0));
assertEquals(1, vm.getMonitor().getCumulativeVmViolationTime(1));
assertEquals(1, vm.getMonitor().getCumulativeVmViolationTime(1));
assertEquals(100, vm.getMonitor().getCumulativeVmViolationTime(100));
assertEquals(0, vm.getMonitor().getCumulativeVmViolationTime(SlaMonitor.SECONDS_OF_A_MONTH));
assertEquals(1, vm.getMonitor().getCumulativeVmViolationTime(SlaMonitor.SECONDS_OF_A_MONTH+5));
......
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