Skip to content

Commit

Permalink
Changes before replace the TreeSet in the CloudletSchedulerCompletely…
Browse files Browse the repository at this point in the history
…Fair (CFS) by regular ArrayList.

- The TreeSet uses a internal TreeMap (a Red-Black tree implementation) and requires
  each element to be unique. This uniqueness is ensured by sorting the elements
  using a Comparator.
- However, as the the CFS uses the virtual runtime to sort the Cloudlets in Sets
  such as execution list and waiting list, this uniqueness cannot be ensured.
- The duplication of virtual runtime causes several issues such as avoiding
  new elements with same vruntime to be added, removal of the wrong element
  of not fiding the element to be removed.
- While a correct and efficient solution is not found,
  it is being used ArrayList instead.
  • Loading branch information
manoelcampos committed Nov 7, 2016
1 parent 44e34c5 commit cae9d35
Show file tree
Hide file tree
Showing 9 changed files with 358 additions and 325 deletions.
43 changes: 4 additions & 39 deletions cloudsim-plus/src/main/java/org/cloudbus/cloudsim/Cloudlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -667,38 +667,6 @@ void assignCloudletToDatacenter(
* @post $none
*/
boolean setCloudletFinishedSoFar(final long length);

/**
* Gets the virtual runtime (vruntime) that indicates how long the Cloudlet
* has been executing by a {@link CloudletScheduler} (in seconds).
* The default value of this attribute is zero and each scheduler
* implementation might or not set a value to such attribute
* so that the scheduler might use to perform context switch,
* preempting running Cloudlets to enable other ones to start executing.
* By this way, the attribute is just used internally by specific CloudletSchedulers.
*
* @return
*/
double getVirtualRuntime();

/**
* Adds a given time to the {@link #getVirtualRuntime() virtual runtime}.
*
* @param timeToAdd time to add to the virtual runtime (in seconds)
* @return the new virtual runtime (in seconds)
* @pre timeToAdd >= 0
*/
double addVirtualRuntime(double timeToAdd);

/**
* Sets the virtual runtime (vruntime) that indicates how long the Cloudlet
* has been executing by a {@link CloudletScheduler} (in seconds). This attribute is used
* just internally by specific CloudletSchedulers.
*
* @param virtualRuntime the value to set (in seconds)
* @see #getVirtualRuntime()
*/
void setVirtualRuntime(double virtualRuntime);

/**
* Gets the listener object that will be notified every time when
Expand Down Expand Up @@ -824,7 +792,7 @@ void assignCloudletToDatacenter(
@Override public long getCloudletFinishedSoFar() { return 0L; }
@Override public long getCloudletFinishedSoFar(int datacenterId) { return 0L; }
@Override public String getCloudletHistory() { return ""; };
@Override public int getId() { return 0; }
@Override public int getId() { return -1; }
@Override public long getCloudletLength() { return 0L; }
@Override public long getCloudletOutputSize() { return 0L; }
@Override public Status getCloudletStatus() { return Status.FAILED; }
Expand All @@ -839,12 +807,12 @@ void assignCloudletToDatacenter(
@Override public int getNumberOfPes(){ return 0; }
@Override public double getProcessingCost(){ return 0.0; }
@Override public List<String> getRequiredFiles() { return Collections.emptyList();}
@Override public int getReservationId() { return 0; }
@Override public int getDatacenterId() { return 0; }
@Override public int getReservationId() { return -1; }
@Override public int getDatacenterId() { return -1; }
@Override public Status getStatus() { return getCloudletStatus(); }
@Override public double getDatacenterArrivalTime() { return 0.0; }
@Override public double getSubmissionTime(int datacenterId) { return 0.0; }
@Override public int getUserId() { return 0; }
@Override public int getUserId() { return -1; }
@Override public UtilizationModel getUtilizationModelBw() { return UtilizationModel.NULL; }
@Override public UtilizationModel getUtilizationModelCpu() { return UtilizationModel.NULL; }
@Override public UtilizationModel getUtilizationModelRam() { return UtilizationModel.NULL; }
Expand Down Expand Up @@ -888,8 +856,5 @@ void assignCloudletToDatacenter(
@Override public double registerArrivalOfCloudletIntoDatacenter() { return -1; }
@Override public boolean isBoundedToVm() { return false; }
@Override public int compareTo(Cloudlet o) { return 0; }
@Override public double getVirtualRuntime() { return 0; }
@Override public void setVirtualRuntime(double virtualRuntime) {}
@Override public double addVirtualRuntime(double timeToAdd) { return 0; }
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
* @author Manoel Campos da Silva Filho
*/
public abstract class CloudletAbstract implements Cloudlet {
/**
* @see #getVirtualRuntime()
*/
private double virtualRuntime;

/**
* The list of every {@link Datacenter} where the cloudlet has been executed. In case
* it starts and finishes executing in a single datacenter, without
Expand All @@ -38,7 +33,6 @@ protected CloudletAbstract(){
*/
executionInDatacenterInfoList = new ArrayList<>(2);
lastExecutedDatacenterIndex = NOT_ASSIGNED;
virtualRuntime = 0;
}

@Override
Expand Down Expand Up @@ -69,24 +63,6 @@ protected void setLastExecutedDatacenterIndex(int lastExecutedDatacenterIndex) {
protected List<ExecutionInDatacenterInfo> getExecutionInDatacenterInfoList() {
return executionInDatacenterInfoList;
}

@Override
public double getVirtualRuntime() {
return virtualRuntime;
}

@Override
public void setVirtualRuntime(double virtualRuntime) {
this.virtualRuntime = virtualRuntime;
}

@Override
public double addVirtualRuntime(double timeToAdd) {
if(timeToAdd >= 0) {
setVirtualRuntime(virtualRuntime + timeToAdd);
}
return getVirtualRuntime();
}

/**
* Internal class that keeps track of Cloudlet's movement in different
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.cloudbus.cloudsim.Cloudlet.Status;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.resources.Pe;
import org.cloudbus.cloudsim.schedulers.CloudletScheduler;

/**
* Stores execution information about a Cloudlet submitted to a Datacenter for
Expand All @@ -22,7 +23,7 @@
* placeholder for maintaining the amount of resource share allocated at various
* times for simulating any scheduling using internal events.
* </p>
*
*
* <p>As the VM where the Cloudlet is running might migrate to another
* Datacenter, each CloudletExecutionInfo object represents the data about
* execution of the cloudlet when the Vm was in a given Datacenter.</p>
Expand All @@ -34,7 +35,7 @@
public class CloudletExecutionInfo {

/**
* @see #getCloudlet()
* @see #getCloudlet()
*/
private final Cloudlet cloudlet;

Expand All @@ -53,7 +54,7 @@ public class CloudletExecutionInfo {
* The time when the Cloudlet has finished completely
* (not just in a given Datacenter, but finished at all).
* If the cloudlet wasn't finished completely yet,
* the value is equals to {@link #NOT_FOUND}.
* the value is equals to {@link Cloudlet#NOT_ASSIGNED}.
*/
private double finishedTime;

Expand Down Expand Up @@ -118,7 +119,17 @@ public class CloudletExecutionInfo {
* The reservation id.
*/
private final int reservationId;


/**
* @see #getVirtualRuntime()
*/
private double virtualRuntime;

/**
* @see #getTimeSlice()
*/
private double timeSlice;

/**
* Instantiates a new CloudletExecutionInfo object upon the arrival of a Cloudlet object.
* The arriving time is determined by
Expand Down Expand Up @@ -164,6 +175,8 @@ public CloudletExecutionInfo(Cloudlet cloudlet, long startTime, int duration, in
this.finishedTime = Cloudlet.NOT_ASSIGNED; // Cannot finish in this hourly slot.
this.totalCompletionTime = 0.0;
this.startExecTime = 0.0;
this.virtualRuntime = 0;


//In case a Cloudlet has been executed partially by some other host
this.cloudletFinishedSoFar = cloudlet.getCloudletFinishedSoFar() * Consts.MILLION;
Expand Down Expand Up @@ -516,7 +529,7 @@ public String getUid() {
* Gets the time to transfer the list of files required by the Cloudlet
* from the Datacenter storage (such as a Storage Area Network)
* to the Vm of the Cloudlet.
* @return
* @return
*/
public double getFileTransferTime() {
return fileTransferTime;
Expand Down Expand Up @@ -548,35 +561,82 @@ public double getLastProcessingTime() {
public void setLastProcessingTime(double lastProcessingTime) {
this.lastProcessingTime = lastProcessingTime;
}

/**
* Gets the virtual runtime of the related Cloudlet.
* @return
*
* @see Cloudlet#getVirtualRuntime()
* Gets the virtual runtime (vruntime) that indicates how long the Cloudlet
* has been executing by a {@link CloudletScheduler} (in seconds).
* The default value of this attribute is zero and each scheduler
* implementation might or not set a value to such attribute
* so that the scheduler might use to perform context switch,
* preempting running Cloudlets to enable other ones to start executing.
* By this way, the attribute is just used internally by specific CloudletSchedulers.
*
* @return
*/
public double getVirtualRuntime(){
return cloudlet.getVirtualRuntime();
return virtualRuntime;
}

/**
* Adds a given time to the {@link #getVirtualRuntime() virtual runtime}.
*
* @param timeToAdd time to add to the virtual runtime (in seconds)
* @return the new virtual runtime (in seconds)
* @pre timeToAdd >= 0
*/
public double addVirtualRuntime(double timeToAdd) {
if(timeToAdd >= 0) {
setVirtualRuntime(virtualRuntime + timeToAdd);
}
return getVirtualRuntime();

}

/**
* Sets the virtual runtime of the related Cloudlet.
* @param virtualRuntime the virtual runtime to set
*
* @see Cloudlet#setVirtualRuntime(double)
* Sets the virtual runtime (vruntime) that indicates how long the Cloudlet
* has been executing by a {@link CloudletScheduler} (in seconds). This attribute is used
* just internally by specific CloudletSchedulers.
*
* @param virtualRuntime the value to set (in seconds)
* @see #getVirtualRuntime()
*/
public void setVirtualRuntime(double virtualRuntime){
cloudlet.setVirtualRuntime(virtualRuntime);
this.virtualRuntime = virtualRuntime;
}

/**
* Gets the timeslice assigned by a CloudletScheduler for a Cloudlet, that is the amount
* of time (in seconds) that such a Cloudlet will have to use the PEs
* of a Vm. Each CloudletScheduler implementation can make use of this attribute or not.
* CloudletSchedulers that use it, are in charge to compute the timeslice to
* assign to each Cloudlet.
*
* @return Cloudlet timeslice (in seconds)
*
*/
public double getTimeSlice() {
return timeSlice;
}

public void setTimeSlice(double timeSlice) {
this.timeSlice = timeSlice;
}

@Override
public String toString() {
return String.format("Cloudlet %d", getCloudletId());
}

@Override
public boolean equals(Object obj) {
return (obj instanceof CloudletExecutionInfo) &&
((CloudletExecutionInfo)obj).getCloudletId() == this.getCloudletId();
}

/**
* A property that implements the Null Object Design Pattern for {@link CloudletExecutionInfo}
* objects.
*/
public static final CloudletExecutionInfo NULL = new CloudletExecutionInfo(Cloudlet.NULL);

}

0 comments on commit cae9d35

Please sign in to comment.