Class CloudletSchedulerAbstract
- All Implemented Interfaces:
Serializable
,CloudletScheduler
- Direct Known Subclasses:
CloudletSchedulerSpaceShared
,CloudletSchedulerTimeShared
public abstract class CloudletSchedulerAbstract extends Object implements CloudletScheduler
CloudletScheduler
, representing
the policy of scheduling performed by a virtual machine to run its
Cloudlets
. So, classes extending this must execute
Cloudlets. The interface for cloudlet management is also implemented in this
class. Each VM has to have its own instance of a CloudletScheduler.- Since:
- CloudSim Toolkit 1.0
- Author:
- Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho
- See Also:
- Serialized Form
-
Field Summary
Fields inherited from interface org.cloudbus.cloudsim.schedulers.cloudlet.CloudletScheduler
LOGGER, NULL
-
Constructor Summary
Constructors Modifier Constructor Description protected
CloudletSchedulerAbstract()
Creates a new CloudletScheduler object. -
Method Summary
Modifier and Type Method Description protected void
addCloudletToExecList(CloudletExecution cle)
Adds a Cloudlet to the list of cloudlets in execution.void
addCloudletToReturnedList(Cloudlet cloudlet)
Adds a Cloudlet to the list of finished Cloudlets that have been returned to itsDatacenterBroker
.protected void
addCloudletToWaitingList(CloudletExecution cle)
CloudletScheduler
addOnCloudletResourceAllocationFail(EventListener<CloudletResourceAllocationFailEventInfo> listener)
Adds a listener object that will be notified every time aCloudletScheduler
is not able to allocated the amount of resource aCloudlet
is requesting due to lack of available capacity.protected CloudletExecution
addWaitingCloudletToExecList(CloudletExecution cle)
Removes a Cloudlet from waiting list and adds it to the exec list.protected abstract boolean
canExecuteCloudletInternal(CloudletExecution cle)
void
clear()
Clears the internal state of the schedulerCloudlet
cloudletCancel(Cloudlet cloudlet)
Cancels execution of a cloudlet.protected double
cloudletEstimatedFinishTime(CloudletExecution cle, double currentTime)
Gets the estimated time when a given cloudlet is supposed to finish executing.Cloudlet
cloudletFail(Cloudlet cloudlet)
Sets a cloudlet as failed.protected void
cloudletFinish(CloudletExecution cle)
Processes a finished cloudlet.boolean
cloudletPause(Cloudlet cloudlet)
Pauses execution of a cloudlet.boolean
cloudletReady(Cloudlet cloudlet)
Sets the status of a Cloudlet toCloudlet.Status.READY
so that it can start executing as soon as possible.double
cloudletSubmit(Cloudlet cloudlet)
Receives an cloudlet to be executed in the VM managed by this scheduler.double
cloudletSubmit(Cloudlet cloudlet, double fileTransferTime)
Receives a cloudlet to be executed in the VM managed by this scheduler.protected double
cloudletSubmitInternal(CloudletExecution cle, double fileTransferTime)
Receives the execution information of a Cloudlet to be executed in the VM managed by this scheduler.void
deallocatePesFromVm(int pesToRemove)
Releases a given number of PEs from a VM.protected Optional<CloudletExecution>
findCloudletInAllLists(double cloudletId)
Search for a Cloudlet into all Cloudlet lists.protected Optional<CloudletExecution>
findCloudletInList(Cloudlet cloudlet, List<CloudletExecution> list)
Search for a Cloudlet into a given list.protected Optional<CloudletExecution>
findSuitableWaitingCloudlet()
Try to find the first Cloudlet in the waiting list that the number of required PEs is not higher than the number of free PEs.double
getAllocatedMipsForCloudlet(CloudletExecution cle, double time)
Gets the current allocated MIPS for cloudlet.double
getAvailableMipsByPe()
Gets the amount of MIPS available (free) for each Processor PE, considering the currently executing cloudlets in this processor and the number of PEs these cloudlets require.List<CloudletExecution>
getCloudletExecList()
Gets a read-only List of cloudlets being executed on the VM.protected List<CloudletExecution>
getCloudletFailedList()
Gets the list of failed cloudlets.List<CloudletExecution>
getCloudletFinishedList()
Gets a list of finished cloudlets.List<Cloudlet>
getCloudletList()
Gets a read-only List of all cloudlets which are either waiting or executing on the VM.protected List<CloudletExecution>
getCloudletPausedList()
Gets the list of paused cloudlets.protected Set<Cloudlet>
getCloudletReturnedList()
Gets a read-only list of Cloudlets that finished executing and were returned the their broker.List<CloudletExecution>
getCloudletWaitingList()
Gets a read-only List of cloudlet waiting to be executed on the VM.List<Double>
getCurrentMipsShare()
Gets a read-only list of current mips capacity from the VM that will be made available to the scheduler.double
getCurrentRequestedBwPercentUtilization()
/** Gets the current utilization percentage of Bandwidth that the running Cloudlets are requesting (in scale from 0 to 1).double
getCurrentRequestedRamPercentUtilization()
Gets the current utilization percentage of RAM that the running Cloudlets are requesting (in scale from 0 to 1).long
getFreePes()
Gets the number of PEs currently not being used.double
getPreviousTime()
Gets the previous time when the scheduler updated the processing of cloudlets it is managing.double
getRequestedCpuPercentUtilization(double time)
Gets total CPU utilization percentage of all cloudlets, according to CPU UtilizationModel of each one (in scale from 0 to 1, where 1 is 100%).protected double
getRequestedMipsForCloudlet(CloudletExecution cle, double time)
Gets the current requested MIPS for a given cloudlet.CloudletTaskScheduler
getTaskScheduler()
Gets theCloudletTaskScheduler
that will be used by this CloudletScheduler to processVmPacket
s to be sent or received by the Vm that is assigned to the current CloudletScheduler.long
getUsedPes()
Gets the number of currently usedPe
's.Vm
getVm()
Gets the Vm that uses the scheduler.boolean
hasFinishedCloudlets()
Informs if there is any cloudlet that finished to execute in the VM managed by this scheduler.boolean
isEmpty()
Checks if there aren't cloudlets waiting or executing inside the Vm.protected boolean
isThereEnoughFreePesForCloudlet(CloudletExecution cle)
Checks if the amount of PEs required by a given Cloudlet is free to use.boolean
isThereTaskScheduler()
Checks if there is aCloudletTaskScheduler
assigned to this CloudletScheduler in order to enable tasks execution and dispatching packets from and to the Vm of this CloudletScheduler.protected double
moveNextCloudletsFromWaitingToExecList(double currentTime)
Selects the next Cloudlets in the waiting list to move to the execution list in order to start executing them.protected CloudletExecution
removeCloudletFromExecList(CloudletExecution cle)
Removes a Cloudlet from the list of cloudlets in execution.boolean
removeOnCloudletResourceAllocationFail(EventListener<CloudletResourceAllocationFailEventInfo> listener)
Removes a Listener object from the registered List.protected void
setCurrentMipsShare(List<Double> currentMipsShare)
Sets the list of current mips share available for the VM using the scheduler.protected void
setPreviousTime(double previousTime)
Sets the previous time when the scheduler updated the processing of cloudlets it is managing.void
setTaskScheduler(CloudletTaskScheduler taskScheduler)
Sets theCloudletTaskScheduler
that will be used by this CloudletScheduler to processVmPacket
s to be sent or received by the Vm that is assigned to the current CloudletScheduler.void
setVm(Vm vm)
Sets the Vm that will use the scheduler.protected void
sortCloudletWaitingList(Comparator<CloudletExecution> comparator)
Sorts thecloudletWaitingList
using a givenComparator
.protected double
timeSpan(CloudletExecution cle, double currentTime)
Computes the time span between the current simulation time and the last time the processing of a cloudlet was updated.protected long
updateCloudletProcessing(CloudletExecution cle, double currentTime)
Updates the processing of a specific cloudlet of the Vm using this scheduler.double
updateProcessing(double currentTime, List<Double> mipsShare)
Updates the processing of cloudlets inside the Vm running under management of this scheduler.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.cloudbus.cloudsim.schedulers.cloudlet.CloudletScheduler
cloudletResume
-
Constructor Details
-
CloudletSchedulerAbstract
protected CloudletSchedulerAbstract()Creates a new CloudletScheduler object.
-
-
Method Details
-
getPreviousTime
public double getPreviousTime()Description copied from interface:CloudletScheduler
Gets the previous time when the scheduler updated the processing of cloudlets it is managing.- Specified by:
getPreviousTime
in interfaceCloudletScheduler
- Returns:
- the previous time
-
setPreviousTime
protected final void setPreviousTime(double previousTime)Sets the previous time when the scheduler updated the processing of cloudlets it is managing.- Parameters:
previousTime
- the new previous time
-
getAvailableMipsByPe
public double getAvailableMipsByPe()Gets the amount of MIPS available (free) for each Processor PE, considering the currently executing cloudlets in this processor and the number of PEs these cloudlets require. This is the amount of MIPS that each Cloudlet is allowed to used, considering that the processor is shared among all executing cloudlets.In the case of space shared schedulers, there is no concurrency for PEs because some cloudlets may wait in a queue until there is available PEs to be used exclusively by them.
- Returns:
- the amount of available MIPS for each Processor PE.
- To do something:
- Splitting the capacity of a CPU core among different applications is not in fact possible. This was just an oversimplification performed by the CloudletSchedulerTimeShared that may affect other schedulers such as the CloudletSchedulerCompletelyFair, which in fact performs task preemption.
-
getCloudletExecList
Description copied from interface:CloudletScheduler
Gets a read-only List of cloudlets being executed on the VM.- Specified by:
getCloudletExecList
in interfaceCloudletScheduler
- Returns:
- the cloudlet execution list
-
addCloudletToWaitingList
-
getCloudletPausedList
Gets the list of paused cloudlets.- Returns:
- the cloudlet paused list
-
getCloudletFinishedList
Description copied from interface:CloudletScheduler
Gets a list of finished cloudlets.- Specified by:
getCloudletFinishedList
in interfaceCloudletScheduler
- Returns:
- the cloudlet finished list
-
getCloudletFailedList
Gets the list of failed cloudlets.- Returns:
- the cloudlet failed list.
-
getCloudletWaitingList
Description copied from interface:CloudletScheduler
Gets a read-only List of cloudlet waiting to be executed on the VM.- Specified by:
getCloudletWaitingList
in interfaceCloudletScheduler
- Returns:
- the cloudlet waiting list
-
sortCloudletWaitingList
Sorts thecloudletWaitingList
using a givenComparator
.- Parameters:
comparator
- theComparator
to sort the Waiting Cloudlets List
-
cloudletSubmit
Description copied from interface:CloudletScheduler
Receives an cloudlet to be executed in the VM managed by this scheduler.- Specified by:
cloudletSubmit
in interfaceCloudletScheduler
- Parameters:
cloudlet
- the submitted cloudlet- Returns:
- expected finish time of this cloudlet (considering the time to transfer required files from the Datacenter to the Vm), or 0 if it is in a waiting queue
-
cloudletSubmit
Description copied from interface:CloudletScheduler
Receives a cloudlet to be executed in the VM managed by this scheduler.- Specified by:
cloudletSubmit
in interfaceCloudletScheduler
- Parameters:
cloudlet
- the submitted cloudletfileTransferTime
- time required to move the required files from the SAN to the VM- Returns:
- expected finish time of this cloudlet (considering the time to transfer required files from the Datacenter to the Vm), or 0 if it is in a waiting queue
-
cloudletSubmitInternal
Receives the execution information of a Cloudlet to be executed in the VM managed by this scheduler.- Parameters:
cle
- the submitted cloudletfileTransferTime
- time required to move the required files from the SAN to the VM- Returns:
- expected finish time of this cloudlet (considering the time to transfer required files from the Datacenter to the Vm), or 0 if it is in a waiting queue
- See Also:
cloudletSubmit(Cloudlet, double)
-
addCloudletToExecList
Adds a Cloudlet to the list of cloudlets in execution.- Parameters:
cle
- the Cloudlet to be added
-
hasFinishedCloudlets
public boolean hasFinishedCloudlets()Description copied from interface:CloudletScheduler
Informs if there is any cloudlet that finished to execute in the VM managed by this scheduler.- Specified by:
hasFinishedCloudlets
in interfaceCloudletScheduler
- Returns:
- $true if there is at least one finished cloudlet; $false otherwise
-
findCloudletInAllLists
Search for a Cloudlet into all Cloudlet lists.- Parameters:
cloudletId
- the id of the Cloudlet to search for- Returns:
- an
Optional
value that is able to indicate if the Cloudlet was found or not
-
findCloudletInList
protected Optional<CloudletExecution> findCloudletInList(Cloudlet cloudlet, List<CloudletExecution> list)Search for a Cloudlet into a given list.- Parameters:
cloudlet
- the Cloudlet to search forlist
- the list to search the Cloudlet into- Returns:
- an
Optional
value that is able to indicate if the Cloudlet was found or not
-
cloudletFinish
Processes a finished cloudlet.- Parameters:
cle
- finished cloudlet
-
cloudletReady
Description copied from interface:CloudletScheduler
Sets the status of a Cloudlet toCloudlet.Status.READY
so that it can start executing as soon as possible.- Specified by:
cloudletReady
in interfaceCloudletScheduler
- Parameters:
cloudlet
- the cloudlet to be started- Returns:
- $true if cloudlet was set to ready, $false otherwise
-
cloudletPause
Description copied from interface:CloudletScheduler
Pauses execution of a cloudlet.- Specified by:
cloudletPause
in interfaceCloudletScheduler
- Parameters:
cloudlet
- the cloudlet being paused- Returns:
- $true if cloudlet was paused, $false otherwise
-
cloudletFail
Description copied from interface:CloudletScheduler
Sets a cloudlet as failed.- Specified by:
cloudletFail
in interfaceCloudletScheduler
- Parameters:
cloudlet
- ID of the cloudlet to set as failed- Returns:
- the failed cloudlet or
Cloudlet.NULL
if not found
-
cloudletCancel
Description copied from interface:CloudletScheduler
Cancels execution of a cloudlet.- Specified by:
cloudletCancel
in interfaceCloudletScheduler
- Parameters:
cloudlet
- the cloudlet being canceled- Returns:
- the canceled cloudlet or
Cloudlet.NULL
if not found
-
updateProcessing
Description copied from interface:CloudletScheduler
Updates the processing of cloudlets inside the Vm running under management of this scheduler.- Specified by:
updateProcessing
in interfaceCloudletScheduler
- Parameters:
currentTime
- current simulation timemipsShare
- list with MIPS share of each Pe available to the scheduler- Returns:
- the predicted completion time of the earliest finishing cloudlet
(which is a relative delay from the current simulation time),
or
Double.MAX_VALUE
if there is no next Cloudlet to execute
-
updateCloudletProcessing
Updates the processing of a specific cloudlet of the Vm using this scheduler.- Parameters:
cle
- The cloudlet to be its processing updatedcurrentTime
- current simulation time- Returns:
- the executed length, in Million Instructions (MI), since the last time cloudlet was processed.
-
addOnCloudletResourceAllocationFail
public CloudletScheduler addOnCloudletResourceAllocationFail(EventListener<CloudletResourceAllocationFailEventInfo> listener)Description copied from interface:CloudletScheduler
Adds a listener object that will be notified every time aCloudletScheduler
is not able to allocated the amount of resource aCloudlet
is requesting due to lack of available capacity.- Specified by:
addOnCloudletResourceAllocationFail
in interfaceCloudletScheduler
- Parameters:
listener
- the Listener to add- Returns:
-
removeOnCloudletResourceAllocationFail
public boolean removeOnCloudletResourceAllocationFail(EventListener<CloudletResourceAllocationFailEventInfo> listener)Description copied from interface:CloudletScheduler
Removes a Listener object from the registered List.- Specified by:
removeOnCloudletResourceAllocationFail
in interfaceCloudletScheduler
- Parameters:
listener
- the Listener to remove- Returns:
- true if the Listener was removed, false otherwise
-
timeSpan
Computes the time span between the current simulation time and the last time the processing of a cloudlet was updated.- Parameters:
cle
- the cloudlet to compute the execution time spancurrentTime
- the current simulation time- Returns:
-
removeCloudletFromExecList
Removes a Cloudlet from the list of cloudlets in execution.- Parameters:
cle
- the Cloudlet to be removed- Returns:
- the removed Cloudlet or
CloudletExecution.NULL
if not found
-
cloudletEstimatedFinishTime
Gets the estimated time when a given cloudlet is supposed to finish executing. It considers the amount of Vm PES and the sum of PEs required by all VMs running inside the VM.- Parameters:
cle
- cloudlet to get the estimated finish timecurrentTime
- current simulation time- Returns:
- the estimated finish time of the given cloudlet (which is a relative delay from the current simulation time)
-
moveNextCloudletsFromWaitingToExecList
protected double moveNextCloudletsFromWaitingToExecList(double currentTime)Selects the next Cloudlets in the waiting list to move to the execution list in order to start executing them. While there is enough free PEs, the method try to find a suitable Cloudlet in the list, until it reaches the end of such a list.The method might also exchange some cloudlets in the execution list with some in the waiting list. Thus, some running cloudlets may be preempted to give opportunity to previously waiting cloudlets to run. This is a process called context switch. However, each CloudletScheduler implementation decides how such a process is implemented. For instance, Space-Shared schedulers may perform context switch just after the currently running Cloudlets completely finish executing.
This method is called internally by the
CloudletScheduler.updateProcessing(double, List)
.- Parameters:
currentTime
- current simulation time- Returns:
- the predicted completion time of the earliest finishing cloudlet
(which is a relative delay from the current simulation time),
or
Double.MAX_VALUE
if there is no next Cloudlet to execute
-
findSuitableWaitingCloudlet
Try to find the first Cloudlet in the waiting list that the number of required PEs is not higher than the number of free PEs.- Returns:
- an
Optional
containing the found Cloudlet or an empty Optional otherwise
-
isThereEnoughFreePesForCloudlet
Checks if the amount of PEs required by a given Cloudlet is free to use.- Parameters:
cle
- the Cloudlet to get the number of required PEs- Returns:
- true if there is the amount of free PEs, false otherwise
-
addWaitingCloudletToExecList
Removes a Cloudlet from waiting list and adds it to the exec list.- Parameters:
cle
- the cloudlet to add to to exec list- Returns:
- the given cloudlet
-
getVm
Description copied from interface:CloudletScheduler
Gets the Vm that uses the scheduler.- Specified by:
getVm
in interfaceCloudletScheduler
- Returns:
-
setVm
Description copied from interface:CloudletScheduler
Sets the Vm that will use the scheduler. It is not required to manually set a Vm for the scheduler, since aVm
sets itself to the scheduler when the scheduler is assigned to the Vm.- Specified by:
setVm
in interfaceCloudletScheduler
- Parameters:
vm
- the Vm to set
-
getUsedPes
public long getUsedPes()Description copied from interface:CloudletScheduler
Gets the number of currently usedPe
's.- Specified by:
getUsedPes
in interfaceCloudletScheduler
- Returns:
-
getFreePes
public long getFreePes()Gets the number of PEs currently not being used.- Specified by:
getFreePes
in interfaceCloudletScheduler
- Returns:
-
getTaskScheduler
Description copied from interface:CloudletScheduler
Gets theCloudletTaskScheduler
that will be used by this CloudletScheduler to processVmPacket
s to be sent or received by the Vm that is assigned to the current CloudletScheduler.- Specified by:
getTaskScheduler
in interfaceCloudletScheduler
- Returns:
- the CloudletTaskScheduler for this CloudletScheduler or
CloudletTaskScheduler.NULL
if this scheduler will not deal with packets transmission.
-
setTaskScheduler
Description copied from interface:CloudletScheduler
Sets theCloudletTaskScheduler
that will be used by this CloudletScheduler to processVmPacket
s to be sent or received by the Vm that is assigned to the current CloudletScheduler. The Vm from the CloudletScheduler is also set to the CloudletTaskScheduler.This attribute usually doesn't need to be set manually. See the note at the
CloudletTaskScheduler
interface for more details.- Specified by:
setTaskScheduler
in interfaceCloudletScheduler
- Parameters:
taskScheduler
- the CloudletTaskScheduler to set for this CloudletScheduler orCloudletTaskScheduler.NULL
if this scheduler will not deal with packets transmission.
-
isThereTaskScheduler
public boolean isThereTaskScheduler()Description copied from interface:CloudletScheduler
Checks if there is aCloudletTaskScheduler
assigned to this CloudletScheduler in order to enable tasks execution and dispatching packets from and to the Vm of this CloudletScheduler.- Specified by:
isThereTaskScheduler
in interfaceCloudletScheduler
- Returns:
-
getRequestedCpuPercentUtilization
public double getRequestedCpuPercentUtilization(double time)Description copied from interface:CloudletScheduler
Gets total CPU utilization percentage of all cloudlets, according to CPU UtilizationModel of each one (in scale from 0 to 1, where 1 is 100%).- Specified by:
getRequestedCpuPercentUtilization
in interfaceCloudletScheduler
- Parameters:
time
- the time to get the current CPU utilization- Returns:
- the total CPU utilization percentage
-
getRequestedMipsForCloudlet
Gets the current requested MIPS for a given cloudlet.- Parameters:
cle
- the cetime
- the time- Returns:
- the current requested mips for the given cloudlet
-
getAllocatedMipsForCloudlet
Gets the current allocated MIPS for cloudlet.- Parameters:
cle
- the cetime
- the time- Returns:
- the current allocated mips for cloudlet
-
getCurrentRequestedBwPercentUtilization
public double getCurrentRequestedBwPercentUtilization()Description copied from interface:CloudletScheduler
/** Gets the current utilization percentage of Bandwidth that the running Cloudlets are requesting (in scale from 0 to 1).- Specified by:
getCurrentRequestedBwPercentUtilization
in interfaceCloudletScheduler
- Returns:
- the BW utilization percentage from 0 to 1 (where 1 is 100%)
-
getCurrentRequestedRamPercentUtilization
public double getCurrentRequestedRamPercentUtilization()Description copied from interface:CloudletScheduler
Gets the current utilization percentage of RAM that the running Cloudlets are requesting (in scale from 0 to 1).- Specified by:
getCurrentRequestedRamPercentUtilization
in interfaceCloudletScheduler
- Returns:
- the RAM utilization percentage from 0 to 1 (where 1 is 100%)
-
getCloudletReturnedList
Gets a read-only list of Cloudlets that finished executing and were returned the their broker. A Cloudlet is returned to notify the broker about the end of its execution.- Returns:
-
addCloudletToReturnedList
Description copied from interface:CloudletScheduler
Adds a Cloudlet to the list of finished Cloudlets that have been returned to itsDatacenterBroker
.- Specified by:
addCloudletToReturnedList
in interfaceCloudletScheduler
- Parameters:
cloudlet
- the Cloudlet to be added
-
deallocatePesFromVm
public void deallocatePesFromVm(int pesToRemove)Description copied from interface:CloudletScheduler
Releases a given number of PEs from a VM.- Specified by:
deallocatePesFromVm
in interfaceCloudletScheduler
- Parameters:
pesToRemove
- number of PEs to deallocate
-
getCloudletList
Description copied from interface:CloudletScheduler
Gets a read-only List of all cloudlets which are either waiting or executing on the VM.- Specified by:
getCloudletList
in interfaceCloudletScheduler
- Returns:
- the list of waiting and executing cloudlets
-
isEmpty
public boolean isEmpty()Description copied from interface:CloudletScheduler
Checks if there aren't cloudlets waiting or executing inside the Vm.- Specified by:
isEmpty
in interfaceCloudletScheduler
- Returns:
- true if there aren't waiting or executing Cloudlets, false otherwise.
-
canExecuteCloudletInternal
- See Also:
canExecuteCloudlet(CloudletExecution)
-
clear
public void clear()Description copied from interface:CloudletScheduler
Clears the internal state of the scheduler- Specified by:
clear
in interfaceCloudletScheduler
-