GridSim 5.0 beta

gridsim
Class AllocPolicy

Object
  extended by Thread
      extended by Sim_entity
          extended by AllocPolicy
All Implemented Interfaces:
Cloneable, Runnable
Direct Known Subclasses:
AggressiveBackfill, AggressiveMultiPartitions, ARPolicy, ConservativeBackfill, SelectiveBackfill, SpaceShared, SpaceSharedWithFailure, TimeShared, TimeSharedWithFailure

public abstract class AllocPolicy
extends Sim_entity

AllocPolicy is an abstract class that handles the internal GridResource allocation policy. New scheduling algorithms can be added into a GridResource entity by extending this class and implement the required abstract methods.

All the implementation details and the data structures chosen are up to the child class. All the protected methods and attributes are available to code things easier.

Since GridSim 3.0, scheduling algorithm or allocation policy that requires Advanced Reservation functionalities need to extend from ARPolicy class instead.

Since:
GridSim Toolkit 2.2
Author:
Anthony Sulistio
See Also:
ARPolicy, GridSim, ResourceCharacteristics
Invariant:
$none

Nested Class Summary
 
Nested classes/interfaces inherited from class Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  long initTime_
          Initial simulation time as given in GridSim.init().
protected  int myId_
          This class entity ID
protected  Sim_port outputPort_
          The GridResource output port.
protected  ResourceCalendar resCalendar_
          The GridResource Calendar, same as the one in GridResource class
protected  int resId_
          This GridResource ID
protected  String resName_
          This GridResource name
protected  ResourceCharacteristics resource_
          The GridResource characteristics object, same as the one in GridResource class
protected  int totalPE_
          The total number of PEs that this resource has.
 
Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected AllocPolicy(String resName, String entityName)
          Allocates a new AllocPolicy object.
 
Method Summary
protected  void addTotalLoad(double load)
          Adds the given load into the overall total load for this entity
protected  double calculateTotalLoad(int size)
          Calculates the current load of a GridResource for a given number of Gridlets currently in execution.
protected  int findGridlet(Collection obj, int gridletId, int userId)
          Deprecated. As GridSim Version 5.0 this method has been replaced by: GridletList.indexOf(int, int) and ResGridletList.indexOf(int, int)
 Accumulator getTotalLoad()
          Gets the total load for this GridResource
abstract  void gridletCancel(int gridletId, int userId)
          An abstract method that cancels a Gridlet in an execution list.
protected  boolean gridletMigrate(Gridlet gl, int destId, boolean ack)
          Migrates a Gridlet from this GridResource ID to the destination ID
abstract  void gridletMove(int gridletId, int userId, int destId, boolean ack)
          An abstract method that moves a Gridlet to another GridResource entity.
abstract  void gridletPause(int gridletId, int userId, boolean ack)
          An abstract method that pauses a Gridlet during an execution.
abstract  void gridletResume(int gridletId, int userId, boolean ack)
          An abstract method that resumes a previously paused Gridlet.
abstract  int gridletStatus(int gridletId, int userId)
          An abstract method that finds the status of a Gridlet.
abstract  void gridletSubmit(Gridlet gl, boolean ack)
          An abstract method that schedules a new Gridlet received by a GridResource entity.
 void init(ResourceCharacteristics res, ResourceCalendar cal, Sim_port port)
          Initializes all important attributes.
protected  boolean isEndSimulation()
          Checks whether it is the end of a simulation or not
 void processOtherEvent(Sim_event ev)
          Overrides this method when executing or scheduling newly-defined tags.
protected  boolean sendAck(int tag, boolean status, int gridletId, int destId)
          Sends an acknowledgement to the sender.
protected  boolean sendCancelGridlet(int tag, Gridlet gl, int gridletId, int destId)
          Sends the canceled Gridlet back to sender.
protected  boolean sendFinishGridlet(Gridlet gl)
          Sends the completed Gridlet back to sender or Gridlet's user ID
protected  boolean sendInternalEvent(double time)
          Sends an internal event to itself
protected  boolean sendInternalEvent(double time, int tag)
          Sends an internal event to itself with a certain tag
 void setEndSimulation()
          Sets the end of simulation for this entity.
 
Methods inherited from class Sim_entity
add_generator, add_param, add_port, body, clone, get_id, get_name, get_port, get_port, get_stat, run, send_on, set_invisible, set_stat, sim_cancel, sim_completed, sim_current, sim_get_next, sim_get_next, sim_hold_for, sim_hold, sim_pause_for, sim_pause_for, sim_pause_until, sim_pause_until, sim_pause, sim_process_for, sim_process_for, sim_process_until, sim_process_until, sim_process, sim_putback, sim_schedule, sim_schedule, sim_schedule, sim_schedule, sim_schedule, sim_schedule, sim_select, sim_trace, sim_wait_for, sim_wait_for, sim_wait_for, sim_wait, sim_waiting, sim_waiting
 
Methods inherited from class Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

resource_

protected ResourceCharacteristics resource_
The GridResource characteristics object, same as the one in GridResource class


resCalendar_

protected ResourceCalendar resCalendar_
The GridResource Calendar, same as the one in GridResource class


outputPort_

protected Sim_port outputPort_
The GridResource output port. This port is mainly used to send Gridlets or any other messages by this Allocation Policy class. This is because an Allocation Policy class doesn't have networked entities (Input and Output).


totalPE_

protected int totalPE_
The total number of PEs that this resource has.


resId_

protected int resId_
This GridResource ID


myId_

protected final int myId_
This class entity ID


resName_

protected final String resName_
This GridResource name


initTime_

protected long initTime_
Initial simulation time as given in GridSim.init().

See Also:
GridSim.init(int, Calendar, boolean), GridSim.init(int, Calendar, boolean, String[], String[], String)
Constructor Detail

AllocPolicy

protected AllocPolicy(String resName,
                      String entityName)
               throws Exception
Allocates a new AllocPolicy object. A child class should call this method during its constructor. The name of this entity (or the child class that inherits this class) will be "resName_entityName".

Parameters:
resName - the GridResource entity name that will contain this allocation policy
entityName - this object entity name
Throws:
Exception - This happens when one of the following scenarios occur:
  • creating this entity before initializing GridSim package
  • this entity name is null or empty
  • this entity has zero number of PEs (Processing Elements).
    No PEs mean the Gridlets can't be processed. A GridResource must contain one or more Machines. A Machine must contain one or more PEs.
See Also:
GridSim.init(int, Calendar, boolean, String[], String[], String)
Pre Condition:
resName != null, entityName != null
Post Condition:
$none
Method Detail

gridletSubmit

public abstract void gridletSubmit(Gridlet gl,
                                   boolean ack)
An abstract method that schedules a new Gridlet received by a GridResource entity.

For a Gridlet that requires many Processing Elements (PEs) or CPUs, the gridlet length is calculated only for 1 PE.
For example, a Gridlet has a length of 500 MI and requires 2 PEs. This means each PE will execute 500 MI of this job. If this scheduler can only execute 1 Gridlet per PE, then it is up to the scheduler to either double the gridlet length up to 1,000 MI or to leave the length as it is.

In the beginning of this code, a ResGridlet object should be created. The ResGridlet object is very useful since it keeps track of related time information during execution of this Gridlet.

If an acknowledgement is required, then at the end of this method, should include the following code:

... // other code

// sends back an ack if required
boolean success = true; // If this method success, false otherwise
if (ack == true) {
    sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, success, gl.getGridletID(), gl.getUserID() );
}

Parameters:
gl - a Gridlet object that is going to be executed
ack - an acknowledgement, i.e. true if wanted to know whether this operation is success or not, false otherwise (don't care)
See Also:
ResGridlet, ResGridletList
Pre Condition:
gl != null
Post Condition:
$none

gridletCancel

public abstract void gridletCancel(int gridletId,
                                   int userId)
An abstract method that cancels a Gridlet in an execution list. When writing this code, there are few things to consider:
  • if a Gridlet can't be found in any data structures
  • if a Gridlet has finished executing upon canceling
  • if a Gridlet can be canceled

This method is always required to send back the Gridlet to sender. If the Gridlet is not found, then send back a null Gridlet. Therefore, at the end of this method, should include the following code:

... // other code

// A ResGridlet object stored in a container or other data structure
// before exit, finalize all the Gridlet's relevant time information
resGridlet.finalizeGridlet();

// sends the Gridlet back to sender
// Here, gridlet can be null if not found
Gridlet gridlet = resGridlet.getGridlet();
sendCancelGridlet(GridSimTags.GRIDLET_CANCEL, gridlet, gridletId, userId);

Parameters:
gridletId - a Gridlet ID
userId - the user or owner's ID of this Gridlet
Pre Condition:
gridletId > 0, userId > 0
Post Condition:
$none

gridletPause

public abstract void gridletPause(int gridletId,
                                  int userId,
                                  boolean ack)
An abstract method that pauses a Gridlet during an execution.

If an acknowledgement is required, then at the end of this method, should include the following code:

... // other code

// sends back an ack if required
boolean success = true; // If this method success, false otherwise
if (ack == true) {
    sendAck(GridSimTags.GRIDLET_PAUSE_ACK, success, gl.getGridletID(), gl.getUserID() );
}

Parameters:
gridletId - a Gridlet ID
userId - the user or owner's ID of this Gridlet
ack - an acknowledgement, i.e. true if wanted to know whether this operation is success or not, false otherwise (don't care)
Pre Condition:
gridletId > 0, userId > 0
Post Condition:
$none

gridletResume

public abstract void gridletResume(int gridletId,
                                   int userId,
                                   boolean ack)
An abstract method that resumes a previously paused Gridlet.

If an acknowledgement is required, then at the end of this method, should include the following code:

... // other code

// sends back an ack if required
boolean success = true; // If this method success, false otherwise
if (ack == true) {
    sendAck(GridSimTags.GRIDLET_RESUME_ACK, success, gl.getGridletID(), gl.getUserID() );
}

Parameters:
gridletId - a Gridlet ID
userId - the user or owner's ID of this Gridlet
ack - an acknowledgement, i.e. true if wanted to know whether this operation is success or not, false otherwise (don't care)
Pre Condition:
gridletId > 0, userId > 0
Post Condition:
$none

gridletStatus

public abstract int gridletStatus(int gridletId,
                                  int userId)
An abstract method that finds the status of a Gridlet. This method doesn't need to send back anything since it will automatically handle by GridResource class once the status is found.

Parameters:
gridletId - a Gridlet ID
userId - the user or owner's ID of this Gridlet
Returns:
the Gridlet status or -1 if not found
See Also:
Gridlet
Pre Condition:
gridletId > 0, userId > 0
Post Condition:
$none

gridletMove

public abstract void gridletMove(int gridletId,
                                 int userId,
                                 int destId,
                                 boolean ack)
An abstract method that moves a Gridlet to another GridResource entity. When writing this code, there are few things to consider:

Parameters:
gridletId - a Gridlet ID
userId - the user or owner's ID of this Gridlet
destId - a new destination GridResource ID for this Gridlet
ack - an acknowledgement, i.e. true if wanted to know whether this operation is success or not, false otherwise (don't care)
Pre Condition:
gridletId > 0, userId > 0, destId > 0
Post Condition:
$none

processOtherEvent

public void processOtherEvent(Sim_event ev)
Overrides this method when executing or scheduling newly-defined tags. This method is called by GridResource.processOtherEvent(Sim_event) for an event with an unknown tag. This approach is desirable if you do not want to create a new type of grid resource.

Parameters:
ev - a Sim_event object
Pre Condition:
ev != null
Post Condition:
$none

getTotalLoad

public Accumulator getTotalLoad()
Gets the total load for this GridResource

Returns:
an Accumulator object
Pre Condition:
$none
Post Condition:
$result != null

setEndSimulation

public void setEndSimulation()
Sets the end of simulation for this entity. Normally, the GridResource entity will set this flag.

Pre Condition:
$none
Post Condition:
$none

isEndSimulation

protected boolean isEndSimulation()
Checks whether it is the end of a simulation or not

Returns:
true if it is the end of a simulation, false otherwise
Pre Condition:
$none
Post Condition:
$none

init

public void init(ResourceCharacteristics res,
                 ResourceCalendar cal,
                 Sim_port port)
Initializes all important attributes. Normally, the GridResource entity will call this method upon its constructor.

Parameters:
res - a ResourceCharacteristics object
cal - a ResourceCalendar object
port - a Sim_port object
Pre Condition:
res != null, cal != null, port != null
Post Condition:
$none

addTotalLoad

protected void addTotalLoad(double load)
Adds the given load into the overall total load for this entity

Parameters:
load - current GridResource load
Pre Condition:
load >= 0.0
Post Condition:
$none

findGridlet

protected int findGridlet(Collection obj,
                          int gridletId,
                          int userId)
Deprecated. As GridSim Version 5.0 this method has been replaced by: GridletList.indexOf(int, int) and ResGridletList.indexOf(int, int)

Finds a Gridlet inside a given list. This method needs a combination of Gridlet Id and User Id because each Grid User might have exactly the same Gridlet Id submitted to this GridResource.

Parameters:
obj - a Collection object that contains a list of ResGridlet
gridletId - a Gridlet Id
userId - an User Id
Returns:
the location of a Gridlet or -1 if not found
Pre Condition:
obj != null, gridletId >= 0, userId >= 0
Post Condition:
$none

calculateTotalLoad

protected double calculateTotalLoad(int size)
Calculates the current load of a GridResource for a given number of Gridlets currently in execution. This method can be overridden by child class, if the below algorithm isn't suitable for a particular type of scheduling:

// totalPE = total PEs that this GridResource has.
// It can be found out using ResourceCharacteristics.getNumPE();
int numGridletPerPE = (totalGridletSize + 1) / totalPE;

// load is between [0.0, 1.0] where 1.0 is busy and 0.0 is not busy
double localLoad = resCalendar_.getCurrentLoad();
double totalLoad = 1.0 - ( (1 - localLoad) / numGridletPerPE );

Parameters:
size - total Gridlets in execution size
Returns:
total load between range [0.0, 1.0]
See Also:
ResourceCharacteristics.getNumPE(), ResourceCalendar.getCurrentLoad()
Pre Condition:
$none
Post Condition:
$none

sendAck

protected boolean sendAck(int tag,
                          boolean status,
                          int gridletId,
                          int destId)
Sends an acknowledgement to the sender. This method is only suitable for the following tags:
  • GridSimTags.GRIDLET_PAUSE_ACK
  • GridSimTags.GRIDLET_RESUME_ACK
  • case GridSimTags.GRIDLET_SUBMIT_ACK

At the receiving end, gridletPause(), gridletResume() and gridletSubmit() will be responsible for this acknowledgment data.

Parameters:
tag - event tag as described above
status - true if the operation has been completed successfully, false otherwise
gridletId - the Gridlet ID
destId - the sender ID. This can also be the user or owner's ID for this Gridlet
Returns:
true if an acknowledgment has been sent successfully, false otherwise
See Also:
GridSim.gridletPause(int, int, int, double, boolean), GridSim.gridletResume(int, int, int, double, boolean), GridSim.gridletSubmit(Gridlet, int, double, boolean)
Pre Condition:
tag >= 0, gridletId >= 0, destId >= 0
Post Condition:
$none

sendCancelGridlet

protected boolean sendCancelGridlet(int tag,
                                    Gridlet gl,
                                    int gridletId,
                                    int destId)
Sends the canceled Gridlet back to sender. This method is only valid for GridSimTags.GRIDLET_CANCEL.

Parameters:
tag - event tag as described above
gl - a Gridlet object
gridletId - the Gridlet ID
destId - the sender ID. This can also be the user or owner's ID for this Gridlet
Returns:
true if the Gridlet has been sent successfully, false otherwise
See Also:
GridSim.gridletCancel(int, int, int, double)
Pre Condition:
tag >= 0, gridletId >= 0, destId >= 0
Post Condition:
$none

gridletMigrate

protected boolean gridletMigrate(Gridlet gl,
                                 int destId,
                                 boolean ack)
Migrates a Gridlet from this GridResource ID to the destination ID

Parameters:
gl - a Gridlet object that is going to be executed
destId - a new destination GridResource Id
ack - an acknowledgement, i.e. true if wanted to know whether this operation is success or not, false otherwise (don't care)
Returns:
true if the Gridlet has been sent successfully, false otherwise
See Also:
GridSim.gridletMove(int, int, int, int, double, boolean)
Pre Condition:
gl != null, destId >= 0
Post Condition:
$none

sendFinishGridlet

protected boolean sendFinishGridlet(Gridlet gl)
Sends the completed Gridlet back to sender or Gridlet's user ID

Parameters:
gl - a completed Gridlet object
Returns:
true if the Gridlet has been sent successfully, false otherwise
Pre Condition:
gl != null
Post Condition:
$none

sendInternalEvent

protected boolean sendInternalEvent(double time)
Sends an internal event to itself

Parameters:
time - the simulation delay time
Returns:
true if the event has been sent successfully, false otherwise
Pre Condition:
time >= 0.0
Post Condition:
$none

sendInternalEvent

protected boolean sendInternalEvent(double time,
                                    int tag)
Sends an internal event to itself with a certain tag

Parameters:
time - the simulation delay time
tag - a tag ID
Returns:
true if the event has been sent successfully, false otherwise
Pre Condition:
time >= 0.0
Post Condition:
$none

GridSim 5.0 beta

The University of Melbourne, Australia, 2009