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;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* 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.
......@@ -81,8 +83,8 @@ public class CloudletSchedulerDynamicWorkload extends CloudletSchedulerTimeShare
continue;
} else { // not finish: estimate the finish time
double estimatedFinishTime = getEstimatedFinishTime(rcl, currentTime);
if (estimatedFinishTime - currentTime < 0.1) {
estimatedFinishTime = currentTime + 0.1;
if (estimatedFinishTime - currentTime < CloudSim.getMinTimeBetweenEvents()) {
estimatedFinishTime = currentTime + CloudSim.getMinTimeBetweenEvents();
}
if (estimatedFinishTime < nextEvent) {
nextEvent = estimatedFinishTime;
......
......@@ -136,8 +136,8 @@ public class CloudletSchedulerSpaceShared extends CloudletScheduler {
for (ResCloudlet rcl : getCloudletExecList()) {
double remainingLength = rcl.getRemainingCloudletLength();
double estimatedFinishTime = currentTime + (remainingLength / (capacity * rcl.getNumberOfPes()));
if (estimatedFinishTime - currentTime < 0.1) {
estimatedFinishTime = currentTime + 0.1;
if (estimatedFinishTime - currentTime < CloudSim.getMinTimeBetweenEvents()) {
estimatedFinishTime = currentTime + CloudSim.getMinTimeBetweenEvents();
}
if (estimatedFinishTime < nextEvent) {
nextEvent = estimatedFinishTime;
......
......@@ -90,8 +90,8 @@ public class CloudletSchedulerTimeShared extends CloudletScheduler {
for (ResCloudlet rcl : getCloudletExecList()) {
double estimatedFinishTime = currentTime
+ (rcl.getRemainingCloudletLength() / (getCapacity(mipsShare) * rcl.getNumberOfPes()));
if (estimatedFinishTime - currentTime < 0.1) {
estimatedFinishTime = currentTime + 0.1;
if (estimatedFinishTime - currentTime < CloudSim.getMinTimeBetweenEvents()) {
estimatedFinishTime = currentTime + CloudSim.getMinTimeBetweenEvents();
}
if (estimatedFinishTime < nextEvent) {
......
......@@ -440,7 +440,7 @@ public class Datacenter extends SimEntity {
} else {
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) {
......@@ -866,7 +866,7 @@ public class Datacenter extends SimEntity {
// if some time passed since last processing
// R: for term is to allow loop at simulation start. Otherwise, one initial
// 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();
double smallerTime = Double.MAX_VALUE;
// for each host...
......@@ -880,8 +880,8 @@ public class Datacenter extends SimEntity {
}
}
// gurantees a minimal interval before scheduling the event
if (smallerTime < CloudSim.clock() + 0.11) {
smallerTime = CloudSim.clock() + 0.11;
if (smallerTime < CloudSim.clock() + CloudSim.getMinTimeBetweenEvents() + 0.01) {
smallerTime = CloudSim.clock() + CloudSim.getMinTimeBetweenEvents() + 0.01;
}
if (smallerTime != Double.MAX_VALUE) {
schedule(getId(), (smallerTime - CloudSim.clock()), CloudSimTags.VM_DATACENTER_EVENT);
......
......@@ -62,6 +62,9 @@ public class CloudSim {
/** The termination time. */
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.
*
......@@ -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,
* 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 {
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.
*
......
......@@ -218,8 +218,8 @@ public class NetworkCloudletSpaceSharedScheduler extends CloudletScheduler {
for (ResCloudlet rcl : getCloudletExecList()) {
double remainingLength = rcl.getRemainingCloudletLength();
double estimatedFinishTime = currentTime + (remainingLength / (capacity * rcl.getNumberOfPes()));
if (estimatedFinishTime - currentTime < 0.1) {
estimatedFinishTime = currentTime + 0.1;
if (estimatedFinishTime - currentTime < CloudSim.getMinTimeBetweenEvents()) {
estimatedFinishTime = currentTime + CloudSim.getMinTimeBetweenEvents();
}
if (estimatedFinishTime < nextEvent) {
nextEvent = estimatedFinishTime;
......
......@@ -16,8 +16,6 @@ import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
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
* and selection policies.
......@@ -63,17 +61,17 @@ public class PowerVm extends Vm {
* @param schedulingInterval the scheduling interval
*/
public PowerVm(
int id,
int userId,
double mips,
int pesNumber,
int ram,
long bw,
long size,
int priority,
String vmm,
CloudletScheduler cloudletScheduler,
double schedulingInterval) {
final int id,
final int userId,
final double mips,
final int pesNumber,
final int ram,
final long bw,
final long size,
final int priority,
final String vmm,
final CloudletScheduler cloudletScheduler,
final double schedulingInterval) {
super(id, userId, mips, pesNumber, ram, bw, size, vmm, cloudletScheduler);
setSchedulingInterval(schedulingInterval);
}
......@@ -85,13 +83,13 @@ public class PowerVm extends Vm {
* @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
* no next events
* no next events
*
* @pre currentTime >= 0
* @post $none
*/
@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);
if (currentTime > getPreviousTime() && (currentTime - 0.1) % getSchedulingInterval() == 0) {
double utilization = getTotalUtilizationOfCpu(getCloudletScheduler().getPreviousTime());
......@@ -120,7 +118,7 @@ public class PowerVm extends Vm {
for (int i = 0; i < n; i++) {
deviationSum[i] = Math.abs(median - getUtilizationHistory().get(i));
}
mad = Stat.median(deviationSum);
mad = MathUtil.median(deviationSum);
}
return mad;
}
......@@ -172,7 +170,7 @@ public class PowerVm extends Vm {
*
* @param utilization the utilization
*/
public void addUtilizationHistoryValue(double utilization) {
public void addUtilizationHistoryValue(final double utilization) {
getUtilizationHistory().add(0, utilization);
if (getUtilizationHistory().size() > HISTORY_LENGTH) {
getUtilizationHistory().remove(HISTORY_LENGTH);
......@@ -202,7 +200,7 @@ public class PowerVm extends Vm {
*
* @param previousTime the new previous time
*/
public void setPreviousTime(double previousTime) {
public void setPreviousTime(final double previousTime) {
this.previousTime = previousTime;
}
......@@ -220,7 +218,7 @@ public class PowerVm extends Vm {
*
* @param schedulingInterval the schedulingInterval to set
*/
protected void setSchedulingInterval(double schedulingInterval) {
protected void setSchedulingInterval(final double schedulingInterval) {
this.schedulingInterval = schedulingInterval;
}
......
......@@ -11,9 +11,9 @@ package org.cloudbus.cloudsim.power;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.cloudbus.cloudsim.Vm;
import flanagan.analysis.Regression;
import org.cloudbus.cloudsim.util.MathUtil;
/**
* The Maximum Correlation (MC) VM selection policy.
......@@ -39,19 +39,19 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo
*
* @param fallbackPolicy the fallback policy
*/
public PowerVmSelectionPolicyMaximumCorrelation(PowerVmSelectionPolicy fallbackPolicy) {
public PowerVmSelectionPolicyMaximumCorrelation(final PowerVmSelectionPolicy fallbackPolicy) {
super();
setFallbackPolicy(fallbackPolicy);
}
/*
* (non-Javadoc)
* @see
* org.cloudbus.cloudsim.experiments.power.PowerVmSelectionPolicy#getVmsToMigrate(org.cloudbus
* .cloudsim.power.PowerHost)
*
* @see org.cloudbus.cloudsim.experiments.power.PowerVmSelectionPolicy#
* getVmsToMigrate(org.cloudbus .cloudsim.power.PowerHost)
*/
@Override
public Vm getVmToMigrate(PowerHost host) {
public Vm getVmToMigrate(final PowerHost host) {
List<PowerVm> migratableVms = getMigratableVms(host);
if (migratableVms.isEmpty()) {
return null;
......@@ -80,7 +80,7 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo
* @param vmList the host
* @return the utilization matrix
*/
protected double[][] getUtilizationMatrix(List<PowerVm> vmList) {
protected double[][] getUtilizationMatrix(final List<PowerVm> vmList) {
int n = vmList.size();
int m = getMinUtilizationHistorySize(vmList);
double[][] utilization = new double[n][m];
......@@ -99,7 +99,7 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo
* @param vmList the vm list
* @return the min utilization history size
*/
protected int getMinUtilizationHistorySize(List<PowerVm> vmList) {
protected int getMinUtilizationHistorySize(final List<PowerVm> vmList) {
int minSize = Integer.MAX_VALUE;
for (PowerVm vm : vmList) {
int size = vm.getUtilizationHistory().size();
......@@ -116,7 +116,7 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo
* @param data the data
* @return the correlation coefficients
*/
protected List<Double> getCorrelationCoefficients(double[][] data) {
protected List<Double> getCorrelationCoefficients(final double[][] data) {
int n = data.length;
int m = data[0].length;
List<Double> correlationCoefficients = new LinkedList<Double>();
......@@ -129,9 +129,12 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo
}
}
Regression reg = new Regression(x, data[i]);
reg.linear();
correlationCoefficients.add(reg.getCoefficientOfDetermination());
// Transpose the matrix so that it fits the linear model
double[][] xT = new Array2DRowRealMatrix(x).transpose().getData();
// RSquare is the "coefficient of determination"
correlationCoefficients.add(MathUtil.createLinearRegression(xT,
data[i]).calculateRSquared());
}
return correlationCoefficients;
}
......@@ -150,7 +153,7 @@ public class PowerVmSelectionPolicyMaximumCorrelation extends PowerVmSelectionPo
*
* @param fallbackPolicy the new fallback policy
*/
public void setFallbackPolicy(PowerVmSelectionPolicy fallbackPolicy) {
public void setFallbackPolicy(final PowerVmSelectionPolicy fallbackPolicy) {
this.fallbackPolicy = fallbackPolicy;
}
......
......@@ -17,6 +17,16 @@
<build>
<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>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
......@@ -49,10 +59,11 @@
<artifactId>easymockclassextension</artifactId>
</dependency>
<dependency>
<groupId>org.flanagan</groupId>
<artifactId>flanagan</artifactId>
<version>1.0</version>
</dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.0</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
</project>
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