|
GridSim 5.0 beta | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object Thread Sim_entity AllocPolicy
public abstract class AllocPolicy
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.
ARPolicy
,
GridSim
,
ResourceCharacteristics
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 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 |
---|
protected ResourceCharacteristics resource_
protected ResourceCalendar resCalendar_
protected Sim_port outputPort_
protected int totalPE_
protected int resId_
protected final int myId_
protected final String resName_
protected long initTime_
GridSim.init(int, Calendar, boolean)
,
GridSim.init(int, Calendar, boolean, String[], String[],
String)
Constructor Detail |
---|
protected AllocPolicy(String resName, String entityName) throws Exception
resName
- the GridResource entity name that will contain
this allocation policyentityName
- this object entity name
Exception
- This happens when one of the following scenarios occur:
GridSim.init(int, Calendar, boolean, String[], String[],
String)
Method Detail |
---|
public abstract void gridletSubmit(Gridlet gl, boolean ack)
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() );
}
gl
- a Gridlet object that is going to be executedack
- an acknowledgement, i.e. true if wanted to know
whether this operation is success or not, false
otherwise (don't care)ResGridlet
,
ResGridletList
public abstract void gridletCancel(int gridletId, int userId)
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);
gridletId
- a Gridlet IDuserId
- the user or owner's ID of this Gridletpublic abstract void gridletPause(int gridletId, int userId, boolean ack)
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() );
}
gridletId
- a Gridlet IDuserId
- the user or owner's ID of this Gridletack
- an acknowledgement, i.e. true if wanted to know
whether this operation is success or not, false
otherwise (don't care)public abstract void gridletResume(int gridletId, int userId, boolean ack)
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() );
}
gridletId
- a Gridlet IDuserId
- the user or owner's ID of this Gridletack
- an acknowledgement, i.e. true if wanted to know
whether this operation is success or not, false
otherwise (don't care)public abstract int gridletStatus(int gridletId, int userId)
gridletId
- a Gridlet IDuserId
- the user or owner's ID of this Gridlet
Gridlet
public abstract void gridletMove(int gridletId, int userId, int destId, boolean ack)
sendAck(int, boolean, int, int)
.sendAck(int, boolean, int, int)
. sendFinishGridlet(Gridlet)
.gridletMigrate(Gridlet, int, boolean)
.
gridletId
- a Gridlet IDuserId
- the user or owner's ID of this GridletdestId
- a new destination GridResource ID for this Gridletack
- an acknowledgement, i.e. true if wanted to know
whether this operation is success or not, false
otherwise (don't care)public void processOtherEvent(Sim_event ev)
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.
ev
- a Sim_event objectpublic Accumulator getTotalLoad()
public void setEndSimulation()
protected boolean isEndSimulation()
public void init(ResourceCharacteristics res, ResourceCalendar cal, Sim_port port)
res
- a ResourceCharacteristics objectcal
- a ResourceCalendar objectport
- a Sim_port objectprotected void addTotalLoad(double load)
load
- current GridResource loadprotected int findGridlet(Collection obj, int gridletId, int userId)
GridletList.indexOf(int, int)
and
ResGridletList.indexOf(int, int)
obj
- a Collection object that contains a list of ResGridletgridletId
- a Gridlet IduserId
- an User Id
protected double calculateTotalLoad(int size)
// 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 );
size
- total Gridlets in execution size
ResourceCharacteristics.getNumPE()
,
ResourceCalendar.getCurrentLoad()
protected boolean sendAck(int tag, boolean status, int gridletId, int destId)
At the receiving end, gridletPause(), gridletResume() and gridletSubmit() will be responsible for this acknowledgment data.
tag
- event tag as described abovestatus
- true if the operation has been completed
successfully, false otherwisegridletId
- the Gridlet IDdestId
- the sender ID. This can also be the user or owner's
ID for this Gridlet
GridSim.gridletPause(int, int, int, double, boolean)
,
GridSim.gridletResume(int, int, int, double, boolean)
,
GridSim.gridletSubmit(Gridlet, int, double, boolean)
protected boolean sendCancelGridlet(int tag, Gridlet gl, int gridletId, int destId)
tag
- event tag as described abovegl
- a Gridlet objectgridletId
- the Gridlet IDdestId
- the sender ID. This can also be the user or owner's
ID for this Gridlet
GridSim.gridletCancel(int, int, int, double)
protected boolean gridletMigrate(Gridlet gl, int destId, boolean ack)
gl
- a Gridlet object that is going to be executeddestId
- a new destination GridResource Idack
- an acknowledgement, i.e. true if wanted to know
whether this operation is success or not, false
otherwise (don't care)
GridSim.gridletMove(int, int, int, int, double, boolean)
protected boolean sendFinishGridlet(Gridlet gl)
gl
- a completed Gridlet object
protected boolean sendInternalEvent(double time)
time
- the simulation delay time
protected boolean sendInternalEvent(double time, int tag)
time
- the simulation delay timetag
- a tag ID
|
GridSim 5.0 beta | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |