Commit a5837706 authored by Nikolay's avatar Nikolay

* Removed the dependency on the flanagan library. It is now replaced with Apache Math.

* The minimal time between events is now configurable
parent 60e69f4a
#!/bin/sh
wget http://www.ee.ucl.ac.uk/~mflanaga/java/flanagan.jar
mvn install:install-file -DgroupId=org.flanagan -DartifactId=flanagan -Dversion=1.0 -Dfile=flanagan.jar -Dpackaging=jar -DgeneratePom=true
rm flanagan.jar
...@@ -12,6 +12,8 @@ import java.util.HashMap; ...@@ -12,6 +12,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.cloudbus.cloudsim.core.CloudSim;
/** /**
* CloudletSchedulerDynamicWorkload implements a policy of scheduling performed by a virtual machine * CloudletSchedulerDynamicWorkload implements a policy of scheduling performed by a virtual machine
* assuming that there is just one cloudlet which is working as an online service. * assuming that there is just one cloudlet which is working as an online service.
...@@ -81,8 +83,8 @@ public class CloudletSchedulerDynamicWorkload extends CloudletSchedulerTimeShare ...@@ -81,8 +83,8 @@ public class CloudletSchedulerDynamicWorkload extends CloudletSchedulerTimeShare
continue; continue;
} else { // not finish: estimate the finish time } else { // not finish: estimate the finish time
double estimatedFinishTime = getEstimatedFinishTime(rcl, currentTime); double estimatedFinishTime = getEstimatedFinishTime(rcl, currentTime);
if (estimatedFinishTime - currentTime < 0.1) { if (estimatedFinishTime - currentTime < CloudSim.getMinTimeBetweenEvents()) {
estimatedFinishTime = currentTime + 0.1; estimatedFinishTime = currentTime + CloudSim.getMinTimeBetweenEvents();
} }
if (estimatedFinishTime < nextEvent) { if (estimatedFinishTime < nextEvent) {
nextEvent = estimatedFinishTime; nextEvent = estimatedFinishTime;
......
...@@ -136,8 +136,8 @@ public class CloudletSchedulerSpaceShared extends CloudletScheduler { ...@@ -136,8 +136,8 @@ public class CloudletSchedulerSpaceShared extends CloudletScheduler {
for (ResCloudlet rcl : getCloudletExecList()) { for (ResCloudlet rcl : getCloudletExecList()) {
double remainingLength = rcl.getRemainingCloudletLength(); double remainingLength = rcl.getRemainingCloudletLength();
double estimatedFinishTime = currentTime + (remainingLength / (capacity * rcl.getNumberOfPes())); double estimatedFinishTime = currentTime + (remainingLength / (capacity * rcl.getNumberOfPes()));
if (estimatedFinishTime - currentTime < 0.1) { if (estimatedFinishTime - currentTime < CloudSim.getMinTimeBetweenEvents()) {
estimatedFinishTime = currentTime + 0.1; estimatedFinishTime = currentTime + CloudSim.getMinTimeBetweenEvents();
} }
if (estimatedFinishTime < nextEvent) { if (estimatedFinishTime < nextEvent) {
nextEvent = estimatedFinishTime; nextEvent = estimatedFinishTime;
......
...@@ -90,8 +90,8 @@ public class CloudletSchedulerTimeShared extends CloudletScheduler { ...@@ -90,8 +90,8 @@ public class CloudletSchedulerTimeShared extends CloudletScheduler {
for (ResCloudlet rcl : getCloudletExecList()) { for (ResCloudlet rcl : getCloudletExecList()) {
double estimatedFinishTime = currentTime double estimatedFinishTime = currentTime
+ (rcl.getRemainingCloudletLength() / (getCapacity(mipsShare) * rcl.getNumberOfPes())); + (rcl.getRemainingCloudletLength() / (getCapacity(mipsShare) * rcl.getNumberOfPes()));
if (estimatedFinishTime - currentTime < 0.1) { if (estimatedFinishTime - currentTime < CloudSim.getMinTimeBetweenEvents()) {
estimatedFinishTime = currentTime + 0.1; estimatedFinishTime = currentTime + CloudSim.getMinTimeBetweenEvents();
} }
if (estimatedFinishTime < nextEvent) { if (estimatedFinishTime < nextEvent) {
......
...@@ -440,7 +440,7 @@ public class Datacenter extends SimEntity { ...@@ -440,7 +440,7 @@ public class Datacenter extends SimEntity {
} else { } else {
data[2] = CloudSimTags.FALSE; data[2] = CloudSimTags.FALSE;
} }
send(vm.getUserId(), 0.1, CloudSimTags.VM_CREATE_ACK, data); send(vm.getUserId(), CloudSim.getMinTimeBetweenEvents(), CloudSimTags.VM_CREATE_ACK, data);
} }
if (result) { if (result) {
...@@ -866,7 +866,7 @@ public class Datacenter extends SimEntity { ...@@ -866,7 +866,7 @@ public class Datacenter extends SimEntity {
// if some time passed since last processing // if some time passed since last processing
// R: for term is to allow loop at simulation start. Otherwise, one initial // R: for term is to allow loop at simulation start. Otherwise, one initial
// simulation step is skipped and schedulers are not properly initialized // simulation step is skipped and schedulers are not properly initialized
if (CloudSim.clock() < 0.111 || CloudSim.clock() > getLastProcessTime() + 0.1) { if (CloudSim.clock() < 0.111 || CloudSim.clock() > getLastProcessTime() + CloudSim.getMinTimeBetweenEvents()) {
List<? extends Host> list = getVmAllocationPolicy().getHostList(); List<? extends Host> list = getVmAllocationPolicy().getHostList();
double smallerTime = Double.MAX_VALUE; double smallerTime = Double.MAX_VALUE;
// for each host... // for each host...
...@@ -880,8 +880,8 @@ public class Datacenter extends SimEntity { ...@@ -880,8 +880,8 @@ public class Datacenter extends SimEntity {
} }
} }
// gurantees a minimal interval before scheduling the event // gurantees a minimal interval before scheduling the event
if (smallerTime < CloudSim.clock() + 0.11) { if (smallerTime < CloudSim.clock() + CloudSim.getMinTimeBetweenEvents() + 0.01) {
smallerTime = CloudSim.clock() + 0.11; smallerTime = CloudSim.clock() + CloudSim.getMinTimeBetweenEvents() + 0.01;
} }
if (smallerTime != Double.MAX_VALUE) { if (smallerTime != Double.MAX_VALUE) {
schedule(getId(), (smallerTime - CloudSim.clock()), CloudSimTags.VM_DATACENTER_EVENT); schedule(getId(), (smallerTime - CloudSim.clock()), CloudSimTags.VM_DATACENTER_EVENT);
......
...@@ -62,6 +62,9 @@ public class CloudSim { ...@@ -62,6 +62,9 @@ public class CloudSim {
/** The termination time. */ /** The termination time. */
private static double terminateAt = -1; private static double terminateAt = -1;
/** The minimal time between events. Events within shorter periods after the last event are discarded. */
private static double minTimeBetweenEvents = 0.1;
/** /**
* Initialises all the common attributes. * Initialises all the common attributes.
* *
...@@ -131,6 +134,40 @@ public class CloudSim { ...@@ -131,6 +134,40 @@ public class CloudSim {
} }
} }
/**
* Initialises CloudSim parameters. This method should be called before creating any entities.
* <p>
* Inside this method, it will create the following CloudSim entities:
* <ul>
* <li>CloudInformationService.
* <li>CloudSimShutdown
* </ul>
* <p>
*
* @param numUser the number of User Entities created. This parameters indicates that
* {@link gridsim.CloudSimShutdown} first waits for all user entities's
* END_OF_SIMULATION signal before issuing terminate signal to other entities
* @param cal starting time for this simulation. If it is <tt>null</tt>, then the time will be
* taken from <tt>Calendar.getInstance()</tt>
* @param traceFlag <tt>true</tt> if CloudSim trace need to be written
* @param periodBetweenEvents - the minimal period between events. Events within shorter periods
* after the last event are discarded.
* @see gridsim.CloudSimShutdown
* @see CloudInformationService.CloudInformationService
* @pre numUser >= 0
* @post $none
*/
public static void init(int numUser, Calendar cal, boolean traceFlag, double periodBetweenEvents) {
if (periodBetweenEvents <= 0) {
throw new IllegalArgumentException("The minimal time between events should be positive, but is:" + periodBetweenEvents);
}
init(numUser, cal, traceFlag);
minTimeBetweenEvents = periodBetweenEvents;
}
/** /**
* Starts the execution of CloudSim simulation. It waits for complete execution of all entities, * Starts the execution of CloudSim simulation. It waits for complete execution of all entities,
* i.e. until all entities threads reach non-RUNNABLE state or there are no more events in the * i.e. until all entities threads reach non-RUNNABLE state or there are no more events in the
...@@ -212,6 +249,15 @@ public class CloudSim { ...@@ -212,6 +249,15 @@ public class CloudSim {
return true; return true;
} }
/**
* Returns the minimum time between events. Events within shorter periods after the last event are discarded.
* @return the minimum time between events.
*/
public static double getMinTimeBetweenEvents() {
return minTimeBetweenEvents;
}
/** /**
* Gets a new copy of initial simulation Calendar. * Gets a new copy of initial simulation Calendar.
* *
......
...@@ -218,8 +218,8 @@ public class NetworkCloudletSpaceSharedScheduler extends CloudletScheduler { ...@@ -218,8 +218,8 @@ public class NetworkCloudletSpaceSharedScheduler extends CloudletScheduler {
for (ResCloudlet rcl : getCloudletExecList()) { for (ResCloudlet rcl : getCloudletExecList()) {
double remainingLength = rcl.getRemainingCloudletLength(); double remainingLength = rcl.getRemainingCloudletLength();
double estimatedFinishTime = currentTime + (remainingLength / (capacity * rcl.getNumberOfPes())); double estimatedFinishTime = currentTime + (remainingLength / (capacity * rcl.getNumberOfPes()));
if (estimatedFinishTime - currentTime < 0.1) { if (estimatedFinishTime - currentTime < CloudSim.getMinTimeBetweenEvents()) {
estimatedFinishTime = currentTime + 0.1; estimatedFinishTime = currentTime + CloudSim.getMinTimeBetweenEvents();
} }
if (estimatedFinishTime < nextEvent) { if (estimatedFinishTime < nextEvent) {
nextEvent = estimatedFinishTime; nextEvent = estimatedFinishTime;
......
...@@ -16,8 +16,6 @@ import org.cloudbus.cloudsim.Vm; ...@@ -16,8 +16,6 @@ import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim; import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.util.MathUtil; import org.cloudbus.cloudsim.util.MathUtil;
import flanagan.analysis.Stat;
/** /**
* The class of a VM that stores its CPU utilization history. The history is used by VM allocation * The class of a VM that stores its CPU utilization history. The history is used by VM allocation
* and selection policies. * and selection policies.
...@@ -63,17 +61,17 @@ public class PowerVm extends Vm { ...@@ -63,17 +61,17 @@ public class PowerVm extends Vm {
* @param schedulingInterval the scheduling interval * @param schedulingInterval the scheduling interval
*/ */
public PowerVm( public PowerVm(
int id, final int id,
int userId, final int userId,
double mips, final double mips,
int pesNumber, final int pesNumber,
int ram, final int ram,
long bw, final long bw,
long size, final long size,
int priority, final int priority,
String vmm, final String vmm,
CloudletScheduler cloudletScheduler, final CloudletScheduler cloudletScheduler,
double schedulingInterval) { final double schedulingInterval) {
super(id, userId, mips, pesNumber, ram, bw, size, vmm, cloudletScheduler); super(id, userId, mips, pesNumber, ram, bw, size, vmm, cloudletScheduler);
setSchedulingInterval(schedulingInterval); setSchedulingInterval(schedulingInterval);
} }
...@@ -85,13 +83,13 @@ public class PowerVm extends Vm { ...@@ -85,13 +83,13 @@ public class PowerVm extends Vm {
* @param mipsShare array with MIPS share of each Pe available to the scheduler * @param mipsShare array with MIPS share of each Pe available to the scheduler
* *
* @return time predicted completion time of the earliest finishing cloudlet, or 0 if there is * @return time predicted completion time of the earliest finishing cloudlet, or 0 if there is
* no next events * no next events
* *
* @pre currentTime >= 0 * @pre currentTime >= 0
* @post $none * @post $none
*/ */
@Override @Override
public double updateVmProcessing(double currentTime, List<Double> mipsShare) { public double updateVmProcessing(final double currentTime, final List<Double> mipsShare) {
double time = super.updateVmProcessing(currentTime, mipsShare); double time = super.updateVmProcessing(currentTime, mipsShare);
if (currentTime > getPreviousTime() && (currentTime - 0.1) % getSchedulingInterval() == 0) { if (currentTime > getPreviousTime() && (currentTime - 0.1) % getSchedulingInterval() == 0) {
double utilization = getTotalUtilizationOfCpu(getCloudletScheduler().getPreviousTime()); double utilization = getTotalUtilizationOfCpu(getCloudletScheduler().getPreviousTime());
...@@ -120,7 +118,7 @@ public class PowerVm extends Vm { ...@@ -120,7 +118,7 @@ public class PowerVm extends Vm {
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
deviationSum[i] = Math.abs(median - getUtilizationHistory().get(i)); deviationSum[i] = Math.abs(median - getUtilizationHistory().get(i));
} }
mad = Stat.median(deviationSum); mad = MathUtil.median(deviationSum);
} }
return mad; return mad;
} }
...@@ -172,7 +170,7 @@ public class PowerVm extends Vm { ...@@ -172,7 +170,7 @@ public class PowerVm extends Vm {
* *
* @param utilization the utilization * @param utilization the utilization
*/ */
public void addUtilizationHistoryValue(double utilization) { public void addUtilizationHistoryValue(final double utilization) {
getUtilizationHistory().add(0, utilization); getUtilizationHistory().add(0, utilization);
if (getUtilizationHistory().size() > HISTORY_LENGTH) { if (getUtilizationHistory().size() > HISTORY_LENGTH) {
getUtilizationHistory().remove(HISTORY_LENGTH); getUtilizationHistory().remove(HISTORY_LENGTH);
...@@ -202,7 +200,7 @@ public class PowerVm extends Vm { ...@@ -202,7 +200,7 @@ public class PowerVm extends Vm {
* *
* @param previousTime the new previous time * @param previousTime the new previous time
*/ */
public void setPreviousTime(double previousTime) { public void setPreviousTime(final double previousTime) {
this.previousTime = previousTime; this.previousTime = previousTime;
} }
...@@ -220,7 +218,7 @@ public class PowerVm extends Vm { ...@@ -220,7 +218,7 @@ public class PowerVm extends Vm {
* *
* @param schedulingInterval the schedulingInterval to set * @param schedulingInterval the schedulingInterval to set
*/ */
protected void setSchedulingInterval(double schedulingInterval) { protected void setSchedulingInterval(final double schedulingInterval) {
this.schedulingInterval = schedulingInterval; this.schedulingInterval = schedulingInterval;
} }
......
...@@ -11,9 +11,9 @@ package org.cloudbus.cloudsim.power; ...@@ -11,9 +11,9 @@ package org.cloudbus.cloudsim.power;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.cloudbus.cloudsim.Vm; import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.util.MathUtil;
import flanagan.analysis.Regression;
/** /**
* The Maximum Correlation (MC) VM selection policy. * The Maximum Correlation (MC) VM selection policy.
...@@ -39,19 +39,19 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo ...@@ -39,19 +39,19 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo
* *
* @param fallbackPolicy the fallback policy * @param fallbackPolicy the fallback policy
*/ */
public PowerVmSelectionPolicyMaximumCorrelation(PowerVmSelectionPolicy fallbackPolicy) { public PowerVmSelectionPolicyMaximumCorrelation(final PowerVmSelectionPolicy fallbackPolicy) {
super(); super();
setFallbackPolicy(fallbackPolicy); setFallbackPolicy(fallbackPolicy);
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see *
* org.cloudbus.cloudsim.experiments.power.PowerVmSelectionPolicy#getVmsToMigrate(org.cloudbus * @see org.cloudbus.cloudsim.experiments.power.PowerVmSelectionPolicy#
* .cloudsim.power.PowerHost) * getVmsToMigrate(org.cloudbus .cloudsim.power.PowerHost)
*/ */
@Override @Override
public Vm getVmToMigrate(PowerHost host) { public Vm getVmToMigrate(final PowerHost host) {
List<PowerVm> migratableVms = getMigratableVms(host); List<PowerVm> migratableVms = getMigratableVms(host);
if (migratableVms.isEmpty()) { if (migratableVms.isEmpty()) {
return null; return null;
...@@ -80,7 +80,7 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo ...@@ -80,7 +80,7 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo
* @param vmList the host * @param vmList the host
* @return the utilization matrix * @return the utilization matrix
*/ */
protected double[][] getUtilizationMatrix(List<PowerVm> vmList) { protected double[][] getUtilizationMatrix(final List<PowerVm> vmList) {
int n = vmList.size(); int n = vmList.size();
int m = getMinUtilizationHistorySize(vmList); int m = getMinUtilizationHistorySize(vmList);
double[][] utilization = new double[n][m]; double[][] utilization = new double[n][m];
...@@ -99,7 +99,7 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo ...@@ -99,7 +99,7 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo
* @param vmList the vm list * @param vmList the vm list
* @return the min utilization history size * @return the min utilization history size
*/ */
protected int getMinUtilizationHistorySize(List<PowerVm> vmList) { protected int getMinUtilizationHistorySize(final List<PowerVm> vmList) {
int minSize = Integer.MAX_VALUE; int minSize = Integer.MAX_VALUE;
for (PowerVm vm : vmList) { for (PowerVm vm : vmList) {
int size = vm.getUtilizationHistory().size(); int size = vm.getUtilizationHistory().size();
...@@ -116,7 +116,7 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo ...@@ -116,7 +116,7 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo
* @param data the data * @param data the data
* @return the correlation coefficients * @return the correlation coefficients
*/ */
protected List<Double> getCorrelationCoefficients(double[][] data) { protected List<Double> getCorrelationCoefficients(final double[][] data) {
int n = data.length; int n = data.length;
int m = data[0].length; int m = data[0].length;
List<Double> correlationCoefficients = new LinkedList<Double>(); List<Double> correlationCoefficients = new LinkedList<Double>();
...@@ -129,9 +129,12 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo ...@@ -129,9 +129,12 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo
} }
} }
Regression reg = new Regression(x, data[i]); // Transpose the matrix so that it fits the linear model
reg.linear(); double[][] xT = new Array2DRowRealMatrix(x).transpose().getData();
correlationCoefficients.add(reg.getCoefficientOfDetermination());
// RSquare is the "coefficient of determination"
correlationCoefficients.add(MathUtil.createLinearRegression(xT,
data[i]).calculateRSquared());
} }
return correlationCoefficients; return correlationCoefficients;
} }
...@@ -150,7 +153,7 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo ...@@ -150,7 +153,7 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo
* *
* @param fallbackPolicy the new fallback policy * @param fallbackPolicy the new fallback policy
*/ */
public void setFallbackPolicy(PowerVmSelectionPolicy fallbackPolicy) { public void setFallbackPolicy(final PowerVmSelectionPolicy fallbackPolicy) {
this.fallbackPolicy = fallbackPolicy; this.fallbackPolicy = fallbackPolicy;
} }
......
...@@ -17,6 +17,16 @@ ...@@ -17,6 +17,16 @@
<build> <build>
<plugins> <plugins>
<!-- Sets the version of the code -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin> <plugin>
<inherited>true</inherited> <inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
...@@ -49,10 +59,11 @@ ...@@ -49,10 +59,11 @@
<artifactId>easymockclassextension</artifactId> <artifactId>easymockclassextension</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.flanagan</groupId> <groupId>org.apache.commons</groupId>
<artifactId>flanagan</artifactId> <artifactId>commons-math3</artifactId>
<version>1.0</version> <version>3.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
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