Commit 42b0c8f9 authored by Eduardo Falcão's avatar Eduardo Falcão
Browse files

fixing slamonitor and removed inability of changing IOPS resource

parent b46f40df
......@@ -9,6 +9,7 @@ import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicyAbstract;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicyInfoAware;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.allocationpolicies.migration.VmAllocationPolicyMigrationSla;
import org.cloudbus.cloudsim.allocationpolicies.migration.VmAllocationPolicyMigrationSlaDynamicTightHost;
import org.cloudbus.cloudsim.brokers.DatacenterBroker;
import org.cloudbus.cloudsim.brokers.DatacenterBrokerSimple;
import org.cloudbus.cloudsim.cloudlets.Cloudlet;
......@@ -76,10 +77,14 @@ public class SlaExploitationSimulation {
private static int VM_IOPS;
public static int MIGRATION_TIME;
// HOST
public static final int SCHEDULING_TIME = 10;
private static final int MAX_VMS_ON_TIGHT_HOST = 50;
// HOST
private static final int HOST_PES = 25;
public static final int HOST_MIPS = 1000;
public static final int HOST_RAM = 50 * 1024;
public static final int HOST_RAM = MAX_VMS_ON_TIGHT_HOST * 1024;
public static final int HOST_BW = 1000000;
public static final int HOST_BASE_STORAGE = 2 * 1024 * 1024;
......@@ -104,11 +109,11 @@ public class SlaExploitationSimulation {
public static void main(String[] args) {
//PATH = args[0];
SLA_TIGHT_HOSTS = 5;
SLA_LOOSE_HOSTS = 5;
HOST_IOPS = 2500;
SLA_TIGHT_HOSTS = 0;
SLA_LOOSE_HOSTS = 10;
HOST_IOPS = MAX_VMS_ON_TIGHT_HOST * 100;
MINIMUM_IOPS = 101;
LOW_AVAILABILITY = 99.9;
LOW_AVAILABILITY = 99;
VMS = 250;
CLOUDLETS = VMS;
VM_IOPS = 100;
......@@ -131,10 +136,14 @@ public class SlaExploitationSimulation {
}
public SlaExploitationSimulation() {
this.simulation = new CloudSim(10);
this.simulation = new CloudSim(SCHEDULING_TIME);
int vmThreshold = MAX_VMS_ON_TIGHT_HOST/2 +1;
int limitTightHosts = 1;
VmAllocationPolicy allocationPolicy = new VmAllocationPolicySimple();
VmAllocationPolicyMigrationSla allocationPolicyMigration = new VmAllocationPolicyMigrationSla(allocationPolicy, MIGRATION_TIME);
VmAllocationPolicyMigrationSlaDynamicTightHost allocationPolicyMigration = new VmAllocationPolicyMigrationSlaDynamicTightHost(allocationPolicy,
MIGRATION_TIME, SCHEDULING_TIME, vmThreshold, limitTightHosts);
this.datacenter = createDatacenter(allocationPolicyMigration);
allocationPolicyMigration.setDatacenter(datacenter);
allocationPolicy.setDatacenter(datacenter);
......@@ -190,7 +199,7 @@ public class SlaExploitationSimulation {
}
for(int i = 0; i < (SLA_LOOSE_HOSTS); i++) {
Host host = createHosts(new ResourceProvisionerSimple(), new VmSchedulerSpaceShared());
Host host = createHosts(new ResourceProvisionerSimple(), new VmSchedulerTimeShared());
hosts.add(host);
}
......@@ -247,7 +256,7 @@ public class SlaExploitationSimulation {
for (int i = 0; i < CLOUDLETS; i++) {
Cloudlet cloudlet = new CloudletSimple(i, NUM_INSTR, VM_PES).setFileSize(1000)
.setOutputSize(1000).setUtilizationModel(utilization)
// .setUtilizationModelIops(new UtilizationModelUneven(0, 100, random.nextLong()))
.setUtilizationModelIops(new UtilizationModelAbsolute(99))
.setIops(CLOUDLET_IOPS);
list.add(cloudlet);
......
......@@ -44,6 +44,8 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
private static final String TIGHT = "TIGHT";
private static final Double IMPRECISION = 0.001;
protected final int SCHEDULING_TIME;
private static final double UPPER_THRESHOLD = 0.8;
private static final double LOWER_THRESHOLD = 0.2;
......@@ -62,11 +64,12 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
*/
private Map<Host, Double> currentFragmentation;
public VmAllocationPolicyMigrationSla(VmAllocationPolicy allocationPolicy, int migrationTime) {
public VmAllocationPolicyMigrationSla(VmAllocationPolicy allocationPolicy, int migrationTime, int schedulingTime) {
this.allocationPolicy = allocationPolicy;
this.MIGRATION_TIME = migrationTime;
this.previousFragmentation = new HashMap<Host, Double>();
this.currentFragmentation = new HashMap<Host, Double>();
this.SCHEDULING_TIME = schedulingTime;
}
@Override
......@@ -151,10 +154,6 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
previousFragmentation.putAll(currentFragmentation);
if(!migrationMap.isEmpty()){
System.out.println(migrationMap);
}
return migrationMap;
}
......@@ -306,13 +305,15 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
protected List<Vm> getVmsWithEnoughCredit(List<Host> looseSlaHosts){
List<Vm> candidateVmsToMigrate = new ArrayList<Vm>();
final double clock = getDatacenter().getSimulation().clock();
final double clock = getDatacenter().getSimulation().clock();
for (Host h : looseSlaHosts) {
for (Vm vm : h.getVmList()) {
// TODO (IF) Create method with code bellow
if(vm.isInMigration() && !isLooseHost(vm.gethostInMigration()))
if(vm.isInMigration() && !isLooseHost(vm.gethostInMigration())){
continue;
}
if (vm.getMonitor().getCumulativeCredit(clock) - MIGRATION_TIME >= 0) {
candidateVmsToMigrate.add(vm);
}
......@@ -345,7 +346,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
for (Host h : tightSlaHosts) {
for (Vm vm : h.getVmList()) {
if (vm.getMonitor().getCumulativeCredit(clock) - MIGRATION_TIME >= 0) {
if (vm.getMonitor().getCumulativeCredit(clock) <= MIGRATION_TIME + SCHEDULING_TIME) {
vmList.add(vm);
}
}
......
......@@ -8,6 +8,7 @@ import java.util.Map;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicy;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerShared;
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.vms.Vm;
/**
......@@ -29,15 +30,16 @@ import org.cloudbus.cloudsim.vms.Vm;
* @author Rafael Vieira Falcao (@rafaelvfalc)
*/
public class VmAllocationPolicyMigrationSlaFixedTightHost extends VmAllocationPolicyMigrationSla {
public class VmAllocationPolicyMigrationSlaDynamicTightHost extends VmAllocationPolicyMigrationSla {
private int vmsThreshold = 0;
private int limitTightHosts = 0;
private int actualTightHosts = 0;
private int currentTightHosts = 0;
private int currentMigrations = 0;
public VmAllocationPolicyMigrationSlaFixedTightHost(VmAllocationPolicy allocationPolicy, int migrationTime, int vmTresshold, int limitTightHosts) {
super(allocationPolicy, migrationTime);
setVmsThreshold(vmTresshold);
public VmAllocationPolicyMigrationSlaDynamicTightHost(VmAllocationPolicy allocationPolicy, int migrationTime, int schedulingTime, int vmThreshold, int limitTightHosts) {
super(allocationPolicy, migrationTime, schedulingTime);
setVmsThreshold(vmThreshold);
setLimitTightHosts(limitTightHosts);
}
......@@ -47,23 +49,37 @@ public class VmAllocationPolicyMigrationSlaFixedTightHost extends VmAllocationPo
int numberCreditVms = getVmsWithEnoughCredit(getHostsWithLooseSla()).size();
System.out.println("Vms with credit: "+numberCreditVms);
// Check if the number of vms with credit also consider the vms with credit that are
// in the Tight hosts (Check vms that are current migrating)
if(numberCreditVms >= getVmsThreshold() && actualTightHosts < getLimitTightHosts()) {
if(numberCreditVms >= getVmsThreshold() && currentTightHosts < getLimitTightHosts()) {
System.out.println("INFERNO!!");
System.out.println("INFERNO!!");
System.out.println("INFERNO!!");
System.out.println("INFERNO!!");
// The Tight host can be created
// Select the Loose host with more credit Vms
Host bestCandidateHost = getHostCandidate();
Host bestCandidateHost = getTightHostCandidate();
// Make it a Tight host
bestCandidateHost.setIopsProvisioner(new ResourceProvisionerShared());
// Increse the number of Tight hosts
actualTightHosts++;
// bestCandidateHost.setVmScheduler(new VmSchedulerTimeShared());
// Increase the number of Tight hosts
currentTightHosts++;
}
// Run Migration Sla Algorithm
Map<Vm, Host> migrationMap = super.getOptimizedAllocationMap(vmList);
// Consolidate Loose hosts
migrationMap = optimisticConsolidation(migrationMap);
migrationMap = gradualConsolidation(migrationMap);
if(!migrationMap.isEmpty()){
System.out.println(migrationMap);
currentMigrations+= migrationMap.size();
System.out.println("#m# "+currentMigrations);
}
return migrationMap;
}
......@@ -73,33 +89,37 @@ public class VmAllocationPolicyMigrationSlaFixedTightHost extends VmAllocationPo
* in order to optimize the number of migrations to consolidate all
* Credit Vms in the Tight host.
*/
public Host getHostCandidate() {
public Host getTightHostCandidate() {
List<Host> looseHosts = getHostsWithLooseSla();
final double clock = getDatacenter().getSimulation().clock();
int currentHighestCreditVms = 0;
int numVmsWithCreditInBestCandidateHost = 0;
Host bestCandidateHost = null;
System.out.println(looseHosts);
for (Host host : looseHosts) {
// Check how good candidate this host is
int creditVms = 0;
for (Vm vm : host.getVmList()) {
if (vm.getMonitor().getCumulativeCredit(clock) - getMIGRATION_TIME() > 0) {
if (vm.getMonitor().getCumulativeCredit(clock) - getMIGRATION_TIME() >= 0) {
creditVms++;
}
}
if(creditVms > currentHighestCreditVms) {
currentHighestCreditVms = creditVms;
if(creditVms > numVmsWithCreditInBestCandidateHost) {
numVmsWithCreditInBestCandidateHost = creditVms;
bestCandidateHost = host;
}
}
System.out.println(bestCandidateHost);
return bestCandidateHost;
}
private Map<Vm, Host> optimisticConsolidation(Map<Vm, Host> actualMigrationMap) {
private Map<Vm, Host> gradualConsolidation(Map<Vm, Host> actualMigrationMap) {
List<Host> orderedLooseHosts = getLooseHostsSortedAscendingByFragmentation();
......@@ -117,26 +137,6 @@ public class VmAllocationPolicyMigrationSlaFixedTightHost extends VmAllocationPo
return actualMigrationMap;
}
// private Map<Vm, Host> optimisticConsolidation2(Map<Vm, Host> actualMigrationMap) {
//
// List<Host> sortedLooseHosts = getLooseHostsSortedAscendingByFragmentation();
// Iterator<Host> hostIt = sortedLooseHosts.listIterator();
//
// for (int j = sortedLooseHosts.size() - 1; j >= 0; j--) {
// for (int i = 0; i < sortedLooseHosts.size(); i++) {
// if(i == j || sortedLooseHosts.get(i).getVmList().isEmpty())
// continue;
// for (Vm vm : sortedLooseHosts.get(i).getVmList()) {
// if(sortedLooseHosts.get(j).isSuitableForVm(vm) && sortedLooseHosts.get(j).addMigratingInVm(vm)) {
// actualMigrationMap.put(vm, sortedLooseHosts.get(j));
// }
// }
// }
// }
//
// return actualMigrationMap;
// }
// Returns the list of loose hosts ordered (increase order) by the number of Vm
private List<Host> getLooseHostsSortedAscendingByFragmentation() {
......
......@@ -553,7 +553,7 @@ public class HostSimple implements Host {
@Override
public final Host setIopsProvisioner(final ResourceProvisioner iopsProvisioner) {
checkSimulationIsRunningAndAttemptedToChangeHost("IOPS");
// checkSimulationIsRunningAndAttemptedToChangeHost("IOPS");
this.iopsProvisioner = iopsProvisioner;
this.iopsProvisioner.setResource(iops);
return this;
......
......@@ -333,19 +333,19 @@ public interface CloudletScheduler extends Serializable {
*/
int runningCloudletsNumber();
/**
* Updates the processing of cloudlets inside the Vm running under management of this scheduler.
*
* @param currentTime current simulation time
* @param mipsShare list with MIPS share of each Pe available to the scheduler
* @param iops the iops of the vm available to the scheduler
* @return the predicted completion time of the earliest finishing cloudlet
* (which is a relative delay from the current simulation time),
* or {@link Double#MAX_VALUE} if there is no next Cloudlet to execute
* @pre currentTime >= 0
* @post $none
*/
double updateProcessing(double currentTime, List<Double> mipsShare, double iops);
// /**
// * Updates the processing of cloudlets inside the Vm running under management of this scheduler.
// *
// * @param currentTime current simulation time
// * @param mipsShare list with MIPS share of each Pe available to the scheduler
// * @param iops the iops of the vm available to the scheduler
// * @return the predicted completion time of the earliest finishing cloudlet
// * (which is a relative delay from the current simulation time),
// * or {@link Double#MAX_VALUE} if there is no next Cloudlet to execute
// * @pre currentTime >= 0
// * @post $none
// */
// double updateProcessing(double currentTime, List<Double> mipsShare, double iops);
/**
* Updates the processing of cloudlets inside the Vm running under management of this scheduler.
......
......@@ -514,28 +514,6 @@ public abstract class CloudletSchedulerAbstract implements CloudletScheduler {
.map(removeCloudletFromListAndUpdateItsStatus)
.orElse(Cloudlet.NULL);
}
// @Override
// public double updateProcessing(final double currentTime, final List<Double> mipsShare, double iops) {
// setCurrentMipsShare(mipsShare);
// setCurrentIopsAllocated(iops); //TODO remove?
//
// if (cloudletExecList.isEmpty() && cloudletWaitingList.isEmpty()) {
// setPreviousTime(currentTime);
// return Double.MAX_VALUE;
// }
//
// updateCloudletsProcessing(currentTime);
// updateVmRamAbsoluteUtilization();
// updateVmIopsAbsoluteUtilization(currentTime);
// removeFinishedCloudletsFromExecutionListAndAddToFinishedList();
// moveNextCloudletsFromWaitingToExecList();
//
// final double nextSimulationTime = getEstimatedFinishTimeOfSoonerFinishingCloudlet(currentTime);
// setPreviousTime(currentTime);
//
// return nextSimulationTime;
// }
@Override
public double updateProcessing(final double currentTime, final List<Double> mipsShare) {
......
......@@ -347,21 +347,6 @@ public final class CloudletSchedulerCompletelyFair extends CloudletSchedulerTime
return super.processCloudletSubmit(ce, fileTransferTime);
}
/**
* {@inheritDoc}
* @param currentTime {@inheritDoc}
* @param mipsShare {@inheritDoc}
* @return the shorter timeslice assigned to the running cloudlets (which defines
* the time of the next expiring Cloudlet, enabling the preemption process), or Double.MAX_VALUE if there is no next events
*/
@Override
public double updateProcessing(final double currentTime, final List<Double> mipsShare, final double iops) {
super.updateProcessing(currentTime, mipsShare, iops);
return getCloudletExecList().stream()
.mapToDouble(CloudletExecution::getTimeSlice)
.min().orElse(Double.MAX_VALUE);
}
@Override
public void updateCloudletProcessing(final CloudletExecution ce, final double currentTime) {
/*
......
......@@ -77,9 +77,6 @@ final class CloudletSchedulerNull implements CloudletScheduler {
@Override public int runningCloudletsNumber() {
return 0;
}
@Override public double updateProcessing(double currentTime, List<Double> mipsShare, double iops) {
return 0.0;
}
@Override public Vm getVm() {
return Vm.NULL;
}
......
......@@ -48,6 +48,11 @@ public double getCumulativeCredit(double time) {
return 0;
}
if(credits.containsKey((int) time)) {
cumulativeCredit = credits.get((int) time);
return cumulativeCredit;
}
while(it.hasNext() && ut.hasNext()) {
VmStateHistoryEntry state = it.next();
double utilization = ut.next();
......@@ -75,7 +80,7 @@ public double getCumulativeCredit(double time) {
}
}
if(stateList.get(lastElement - 1).getTime() < time) {
if((int) stateList.get(lastElement - 1).getTime() < (int) time) {
VmStateHistoryEntry last = stateList.get(lastElement - 1);
double utilization = utilizationList.get(lastUtilization - 1);
Double previous = credits.get((int) last.getTime());
......
......@@ -46,6 +46,7 @@ public class VmAllocationPolicyMigrationSlaTest {
public static final int HOST_BASE_STORAGE = 1000;
public static final int MIGRATION_TIME = 60;
public static final int SCHEDULING_TIME = 1;
public static final double IMPRECISION = 0.0001;
......@@ -57,7 +58,7 @@ public class VmAllocationPolicyMigrationSlaTest {
@Before
public void setUp() {
VmAllocationPolicy ap = new VmAllocationPolicySimple();
policy = new VmAllocationPolicyMigrationSla(ap, MIGRATION_TIME);
policy = new VmAllocationPolicyMigrationSla(ap, MIGRATION_TIME, SCHEDULING_TIME);
}
private Datacenter createMockedDatacenter(List<Host> hosts, double time) {
......
......@@ -108,6 +108,7 @@ public class SlaMonitorTest {
assertEquals(0, vm.getMonitor().getCumulativeCredit(0), imprecision);
assertEquals(-1 * STEP_CREDIT, vm.getMonitor().getCumulativeCredit(1), 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);
......
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