Commit 4fd3fdf9 authored by Eduardo Falcão's avatar Eduardo Falcão
Browse files

fixing the change of host heaven into hell

parent 42b0c8f9
......@@ -77,12 +77,12 @@ public class SlaExploitationSimulation {
private static int VM_IOPS;
public static int MIGRATION_TIME;
public static final int SCHEDULING_TIME = 10;
public static final int SCHEDULING_TIME = 1;
private static final int MAX_VMS_ON_TIGHT_HOST = 50;
private static final int MAX_VMS_ON_TIGHT_HOST = 2;
// HOST
private static final int HOST_PES = 25;
private static final int HOST_PES = 1;
public static final int HOST_MIPS = 1000;
public static final int HOST_RAM = MAX_VMS_ON_TIGHT_HOST * 1024;
public static final int HOST_BW = 1000000;
......@@ -110,16 +110,19 @@ public class SlaExploitationSimulation {
public static void main(String[] args) {
//PATH = args[0];
SLA_TIGHT_HOSTS = 0;
SLA_LOOSE_HOSTS = 10;
HOST_IOPS = MAX_VMS_ON_TIGHT_HOST * 100;
MINIMUM_IOPS = 101;
SLA_LOOSE_HOSTS = 2;
VM_IOPS = 100;
HOST_IOPS = VM_IOPS;
LOW_AVAILABILITY = 99;
VMS = 250;
VMS = 2;
CLOUDLETS = VMS;
VM_IOPS = 100;
CLOUDLET_IOPS = 2 * 60 * 60 * VM_IOPS;
MIGRATION_TIME = 5;
CLOUDLET_IOPS = 3 * 60 * 60 * VM_IOPS;
MIGRATION_TIME = 10;
random = new Random(1);
//1000 migra pro inferno
//1001 migra de volta pro céu
FILEID = "tight"+SLA_TIGHT_HOSTS+"-"+
......@@ -203,7 +206,7 @@ public class SlaExploitationSimulation {
hosts.add(host);
}
final Datacenter dc = new DatacenterSimple(simulation, hosts, vmAllocationpolicy);
final Datacenter dc = new DatacenterSimple(simulation, hosts, vmAllocationpolicy, MIGRATION_TIME);
return dc;
}
......@@ -256,7 +259,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 UtilizationModelAbsolute(99))
.setUtilizationModelIops(new UtilizationModelAbsolute(100))
.setIops(CLOUDLET_IOPS);
list.add(cloudlet);
......
......@@ -157,97 +157,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
return migrationMap;
}
/**
* Creates a {@link VerticalVmScaling} for scaling VM's IOPS when it's under or
* overloaded.
*
* <p>
* Realize the lower and upper thresholds are defined inside this method by
* using references to the methods {@link #lowerIopsUtilizationThreshold(Vm)}
* and {@link #upperIopsUtilizationThreshold(Vm)}. These methods enable defining
* thresholds in a dynamic way and even different thresholds for distinct VMs.
* Therefore, it's a powerful mechanism.
* </p>
*
* <p>
* However, if you are defining thresholds in a static way, and they are the
* same for all VMs, you can use a Lambda Expression like below, for instance,
* instead of creating a new method that just returns a constant value:<br>
* {@code verticalIopsScaling.setLowerThresholdFunction(vm -> 0.4);}
* </p>
*
* @see #createListOfScalableVms(int)
*/
private VerticalVmScaling createVerticalIopsScaling() {
// The percentage in which the amount of IOPS has to be scaled
final double scalingFactor = 0.25;
VerticalVmScalingSimple verticalIopsScaling = new VerticalVmScalingSimple(Iops.class, scalingFactor);
/*
* Instead of gradually increasing or decreasing the amount of IOPS, when the
* scaling object detects the Disk usage is above or below the defined
* thresholds, it will automatically calculate the amount of IOPS to add/remove
* to move the VM from the over or underload condition.
*/
verticalIopsScaling.setResourceScaling(new ResourceScalingInstantaneous());
/**
* Different from the line above, the line below implements a ResourceScaling
* using a Lambda Expression. It is just an example which scales the resource
* twice the amount defined by the scaling factor defined in the constructor.
*
* Realize that if the setResourceScaling method is not called, a
* ResourceScalingGradual will be used, which scales the resource according to
* the scaling factor. The lower and upper thresholds after this line can also
* be defined using a Lambda Expression.
*
* So, here we are defining our own {@link ResourceScaling} instead of using the
* available ones such as the {@link ResourceScalingGradual} or
* {@link ResourceScalingInstantaneous}.
*/
// verticalIopsScaling.setResourceScaling(vs ->
// 2*vs.getScalingFactor()*vs.getAllocatedResource());
verticalIopsScaling.setLowerThresholdFunction(this::lowerIopsUtilizationThreshold);
verticalIopsScaling.setUpperThresholdFunction(this::upperIopsUtilizationThreshold);
return verticalIopsScaling;
}
/**
* Defines the minimum Disk utilization percentage that indicates a Vm is
* underloaded. This function is using a statically defined threshold, but it
* would be defined a dynamic threshold based on any condition you want. A
* reference to this method is assigned to each Vertical VM Scaling created.
*
* @param vm
* the VM to check if its Disk is underloaded. <b>The parameter is
* not being used internally, which means the same threshold is used
* for any Vm.</b>
* @return the lower Disk utilization threshold
* @see #createVerticalIopsScaling()
*/
private double lowerIopsUtilizationThreshold(Vm vm) {
return LOWER_THRESHOLD;
}
/**
* Defines the maximum Disk utilization percentage that indicates a Vm is
* overloaded. This function is using a statically defined threshold, but it
* would be defined a dynamic threshold based on any condition you want. A
* reference to this method is assigned to each Vertical VM Scaling created.
*
* @param vm
* the VM to check if its Disk is overloaded. The parameter is not
* being used internally, that means the same threshold is used for
* any Vm.
* @return the upper Disk utilization threshold
* @see #createVerticalIopsScaling()
*/
private double upperIopsUtilizationThreshold(Vm vm) {
return UPPER_THRESHOLD;
}
/**
* Sorts a list of VMs from high to low fragmentation,
......@@ -310,6 +220,9 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
for (Host h : looseSlaHosts) {
for (Vm vm : h.getVmList()) {
System.out.println("#$#Heaven#$# vm id("+vm.getId()+"): "+vm.getMonitor().getCumulativeCredit(clock));
// TODO (IF) Create method with code bellow
if(vm.isInMigration() && !isLooseHost(vm.gethostInMigration())){
continue;
......@@ -346,6 +259,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
for (Host h : tightSlaHosts) {
for (Vm vm : h.getVmList()) {
System.out.println("#$#Hell#$# vm id("+vm.getId()+"): "+vm.getMonitor().getCumulativeCredit(clock));
if (vm.getMonitor().getCumulativeCredit(clock) <= MIGRATION_TIME + SCHEDULING_TIME) {
vmList.add(vm);
}
......@@ -401,9 +315,100 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
return allocationPolicy.findHostForVm(vm);
}
//TODO Rename method name
public int getMIGRATION_TIME() {
public int getMigrationTime() {
return MIGRATION_TIME;
}
/**
* Creates a {@link VerticalVmScaling} for scaling VM's IOPS when it's under or
* overloaded.
*
* <p>
* Realize the lower and upper thresholds are defined inside this method by
* using references to the methods {@link #lowerIopsUtilizationThreshold(Vm)}
* and {@link #upperIopsUtilizationThreshold(Vm)}. These methods enable defining
* thresholds in a dynamic way and even different thresholds for distinct VMs.
* Therefore, it's a powerful mechanism.
* </p>
*
* <p>
* However, if you are defining thresholds in a static way, and they are the
* same for all VMs, you can use a Lambda Expression like below, for instance,
* instead of creating a new method that just returns a constant value:<br>
* {@code verticalIopsScaling.setLowerThresholdFunction(vm -> 0.4);}
* </p>
*
* @see #createListOfScalableVms(int)
*/
private VerticalVmScaling createVerticalIopsScaling() {
// The percentage in which the amount of IOPS has to be scaled
final double scalingFactor = 0.25;
VerticalVmScalingSimple verticalIopsScaling = new VerticalVmScalingSimple(Iops.class, scalingFactor);
/*
* Instead of gradually increasing or decreasing the amount of IOPS, when the
* scaling object detects the Disk usage is above or below the defined
* thresholds, it will automatically calculate the amount of IOPS to add/remove
* to move the VM from the over or underload condition.
*/
verticalIopsScaling.setResourceScaling(new ResourceScalingInstantaneous());
/**
* Different from the line above, the line below implements a ResourceScaling
* using a Lambda Expression. It is just an example which scales the resource
* twice the amount defined by the scaling factor defined in the constructor.
*
* Realize that if the setResourceScaling method is not called, a
* ResourceScalingGradual will be used, which scales the resource according to
* the scaling factor. The lower and upper thresholds after this line can also
* be defined using a Lambda Expression.
*
* So, here we are defining our own {@link ResourceScaling} instead of using the
* available ones such as the {@link ResourceScalingGradual} or
* {@link ResourceScalingInstantaneous}.
*/
// verticalIopsScaling.setResourceScaling(vs ->
// 2*vs.getScalingFactor()*vs.getAllocatedResource());
verticalIopsScaling.setLowerThresholdFunction(this::lowerIopsUtilizationThreshold);
verticalIopsScaling.setUpperThresholdFunction(this::upperIopsUtilizationThreshold);
return verticalIopsScaling;
}
/**
* Defines the minimum Disk utilization percentage that indicates a Vm is
* underloaded. This function is using a statically defined threshold, but it
* would be defined a dynamic threshold based on any condition you want. A
* reference to this method is assigned to each Vertical VM Scaling created.
*
* @param vm
* the VM to check if its Disk is underloaded. <b>The parameter is
* not being used internally, which means the same threshold is used
* for any Vm.</b>
* @return the lower Disk utilization threshold
* @see #createVerticalIopsScaling()
*/
private double lowerIopsUtilizationThreshold(Vm vm) {
return LOWER_THRESHOLD;
}
/**
* Defines the maximum Disk utilization percentage that indicates a Vm is
* overloaded. This function is using a statically defined threshold, but it
* would be defined a dynamic threshold based on any condition you want. A
* reference to this method is assigned to each Vertical VM Scaling created.
*
* @param vm
* the VM to check if its Disk is overloaded. The parameter is not
* being used internally, that means the same threshold is used for
* any Vm.
* @return the upper Disk utilization threshold
* @see #createVerticalIopsScaling()
*/
private double upperIopsUtilizationThreshold(Vm vm) {
return UPPER_THRESHOLD;
}
}
......@@ -49,21 +49,19 @@ public class VmAllocationPolicyMigrationSlaDynamicTightHost extends VmAllocation
int numberCreditVms = getVmsWithEnoughCredit(getHostsWithLooseSla()).size();
System.out.println("Vms with credit: "+numberCreditVms);
System.out.println("Vms with credit in Heaven: "+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() && currentTightHosts < getLimitTightHosts()) {
System.out.println("INFERNO!!");
System.out.println("INFERNO!!");
System.out.println("INFERNO!!");
System.out.println("INFERNO!!");
System.out.println("INFERNO!! "+getDatacenter().getSimulation().clock());
// The Tight host can be created
// Select the Loose host with more credit Vms
Host bestCandidateHost = getTightHostCandidate();
// Make it a Tight host
bestCandidateHost.setIopsProvisioner(new ResourceProvisionerShared());
reprovisionIopsForVmsInHell(bestCandidateHost);
// bestCandidateHost.setVmScheduler(new VmSchedulerTimeShared());
// Increase the number of Tight hosts
currentTightHosts++;
......@@ -104,7 +102,7 @@ public class VmAllocationPolicyMigrationSlaDynamicTightHost extends VmAllocation
// 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) - getMigrationTime() >= 0) {
creditVms++;
}
}
......@@ -114,7 +112,7 @@ public class VmAllocationPolicyMigrationSlaDynamicTightHost extends VmAllocation
}
}
System.out.println(bestCandidateHost);
System.out.println("bestCandidateHost: "+bestCandidateHost);
return bestCandidateHost;
}
......@@ -146,6 +144,12 @@ public class VmAllocationPolicyMigrationSlaDynamicTightHost extends VmAllocation
return looseHosts;
}
private void reprovisionIopsForVmsInHell(Host hellHost){
for(Vm vm : hellHost.getVmList()){
hellHost.getIopsProvisioner().allocateResourceForVm(vm, vm.getCurrentRequestedIops());
}
}
private int getVmsThreshold() {
return vmsThreshold;
}
......
......@@ -71,6 +71,44 @@ public class DatacenterSimple extends CloudSimEntity implements Datacenter {
/** @see #getSchedulingInterval() */
private double schedulingInterval;
private int migrationTime;
/**
* Creates a Datacenter.
*
* @param simulation The CloudSim instance that represents the simulation the Entity is related to
* @param hostList list of {@link Host}s that will compound the Datacenter
* @param vmAllocationPolicy the policy to be used to allocate VMs into hosts
* @param migrationTime the duration of the migration
* @throws IllegalArgumentException when this entity has <tt>zero</tt> number of PEs (Processing Elements).
* <br>
* No PEs mean the Cloudlets can't be processed. A CloudResource must
* contain one or more Machines. A Machine must contain one or more PEs.
*
* @post $none
*/
public DatacenterSimple(
final Simulation simulation,
final List<? extends Host> hostList,
final VmAllocationPolicy vmAllocationPolicy,
final int migrationTime)
{
super(simulation);
setHostList(hostList);
setLastProcessTime(0.0);
setSchedulingInterval(0);
setStorageList(new ArrayList<>());
this.characteristics = new DatacenterCharacteristicsSimple(this);
this.bandwidthPercentForMigration = DEF_BANDWIDTH_PERCENT_FOR_MIGRATION;
migrationsEnabled = true;
setVmAllocationPolicy(vmAllocationPolicy);
this.migrationTime = migrationTime;
}
/**
* Creates a Datacenter.
*
......@@ -712,7 +750,10 @@ public class DatacenterSimple extends CloudSimEntity implements Datacenter {
final Host sourceHost = entry.getKey().getHost();
final Host targetHost = entry.getValue();
final double delay = timeToMigrateVm(entry.getKey(), targetHost);
//FIXME this was done in the context of the autonomics project
// final double delay = timeToMigrateVm(entry.getKey(), targetHost);
final double delay = migrationTime;
if (sourceHost == Host.NULL) {
Log.printFormattedLine(
"%.2f: Migration of %s to %s is started.",
......@@ -722,8 +763,12 @@ public class DatacenterSimple extends CloudSimEntity implements Datacenter {
"%.2f: Migration of %s from %s to %s is started.",
currentTime, entry.getKey(), sourceHost, targetHost);
}
// Log.printFormattedLine(
// "\tIt's expected to finish in %.2f seconds, considering the %.0f%% of bandwidth allowed for migration and the VM RAM size.",
// delay, getBandwidthPercentForMigration()*100);
Log.printFormattedLine(
"\tIt's expected to finish in %.2f seconds, considering the %.0f%% of bandwidth allowed for migration and the VM RAM size.",
"\tIt's expected to finish in %.2f seconds. This is a fixed time in the context of the Autonomics project.",
delay, getBandwidthPercentForMigration()*100);
......
......@@ -85,10 +85,10 @@ public double getCumulativeCredit(double time) {
double utilization = utilizationList.get(lastUtilization - 1);
Double previous = credits.get((int) last.getTime());
if (last.getAllocatedIops() <= utilization) {
cumulativeCredit = previous - (((int) time - stateList.get(lastElement - 1).getTime())) * (1 / availability);
if (last.getAllocatedIops() < utilization) {
cumulativeCredit = previous - (((int) (time - stateList.get(lastElement - 1).getTime()))) * (1 / availability);
} else {
cumulativeCredit = previous + (((int) time - stateList.get(lastElement - 1).getTime())) * (1 / availability);
cumulativeCredit = previous + (((int) (time - stateList.get(lastElement - 1).getTime()))) * (1 / availability);
}
}
return cumulativeCredit;
......@@ -96,7 +96,7 @@ public double getCumulativeCredit(double time) {
private Double putCredits(VmStateHistoryEntry state, double utilization, double dif, double availability) {
Double cumulativeCredit;
if(state.getAllocatedIops() <= utilization) {
if(state.getAllocatedIops() < utilization) {
credits.put((int) state.getTime(), dif - (1 / availability));
}
else {
......@@ -128,7 +128,7 @@ public double getCumulativeCredit(double time) {
return previous;
}
if(state.getAllocatedIops() > utilization)
if(state.getAllocatedIops() >= utilization)
dif = previous + (1 / availability) * (int )(time - prevTime - 1);
else
dif = previous - (1 / availability) * (int )(time - prevTime - 1);
......
......@@ -182,7 +182,7 @@ public class VmAllocationPolicyMigrationSlaTest {
vm0.addStateHistoryEntry(new VmStateHistoryEntry(0, 0, 0, MINIMUM_IOPS - 1, 0, false)); // allocatedIops is MINIMUM_IOPS
vm0.setIOPSUtilization(0, MINIMUM_IOPS -1);
vm0.addStateHistoryEntry(
new VmStateHistoryEntry(vm0.getMonitor().getMaximumAllowedSlaViolationTime() - policy.getMIGRATION_TIME(),
new VmStateHistoryEntry(vm0.getMonitor().getMaximumAllowedSlaViolationTime() - policy.getMigrationTime(),
0, 0, MINIMUM_IOPS, 0, false));
vm0.setIOPSUtilization(vm0.getMonitor().getMaximumAllowedSlaViolationTime(), MINIMUM_IOPS);
......
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