From: <mar...@us...> - 2008-02-12 05:46:22
|
Revision: 101 http://gridsim.svn.sourceforge.net/gridsim/?rev=101&view=rev Author: marcos_dias Date: 2008-02-11 21:46:26 -0800 (Mon, 11 Feb 2008) Log Message: ----------- A scheduler with multiple queues and easy backfilling is under development. Added Paths: ----------- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues01.java branches/gridsim4.0-branch3/source/gridsim/turbo/MultipleEasyBackfillingQueues.java Added: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues01.java (rev 0) +++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues01.java 2008-02-12 05:46:26 UTC (rev 101) @@ -0,0 +1,176 @@ + +package examples.workload.parallel; + +import gridsim.GridResource; +import gridsim.GridSim; +import gridsim.Machine; +import gridsim.MachineList; +import gridsim.turbo.TResourceCharacteristics; +import gridsim.util.Workload; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.LinkedList; +import java.util.Random; + + +/** + * Test Driver class for this example + */ +public class TurboExampleMultiEBQueues01 +{ + /** + * Creates main() to run this example + */ + public static void main(String[] args) + { + long startTime = System.currentTimeMillis(); + if(args.length == 0){ + System.out.println("Please provide the location of the workload file!"); + System.exit(1); + } + + try { + + ////////////////////////////////////////// + // Get the workload to be used The format should be: + // ASCII text, gzip or zip. + + String fileName = args[0]; + // /Users/marcosd/Documents/workspace/intergrid/workloads/sdsc_blue_2000_400.swf + + ArrayList<GridResource> resources = new ArrayList<GridResource>(); + + ////////////////////////////////////////// + // Initialize the GridSim package. It should be called + // before creating any entities. We can't run this example without + // initializing GridSim first. We will get run-time exception + // error. + + // number of grid user entities + any Workload entities. + int num_user = 1; + Calendar calendar = Calendar.getInstance(); + boolean trace_flag = false; // mean trace GridSim events + + // Initialize the GridSim package without any statistical + // functionalities. Hence, no GridSim_stat.txt file is created. + System.out.println("Initializing GridSim package"); + GridSim.init(num_user, calendar, trace_flag); + + ////////////////////////////////////////// + // Creates one or more GridResource entities + int totalResource = 1; // total number of Grid resources + int rating = 377; // rating of each PE in MIPS + int totalPE = 9; // total number of PEs for each Machine + int totalMachine = 128; // total number of Machines + int i = 0; + + String[] resArray = new String[totalResource]; + for (i = 0; i < totalResource; i++) { + String resName = "Res_" + i; + GridResource resource = createGridResource(resName, rating, totalMachine, totalPE); + resources.add(resource); + + // add a resource name into an array + resArray[i] = resName; + } + + ////////////////////////////////////////// + // Creates one Workload trace entity. + + int resID = 0; + Random r = new Random(); + resID = r.nextInt(totalResource); + Workload workload = new Workload("Load_1", fileName, resArray[resID], rating); + + ////////////////////////////////////////// + // Starts the simulation in debug mode + GridSim.startGridSimulation(true); + + // Start the simulation in normal mode +// GridSim.startGridSimulation(); + + ////////////////////////////////////////// + // Final step: Prints the Gridlets when simulation is over + long finishTime = System.currentTimeMillis(); + System.out.println("The simulation took " + (finishTime - startTime) + " milliseconds"); + + // prints the Gridlets inside a Workload entity + // workload.printGridletList(trace_flag); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Creates one Grid resource. A Grid resource contains one or more + * Machines. Similarly, a Machine contains one or more PEs (Processing + * Elements or CPUs). + * @param name a Grid Resource name + * @param peRating rating of each PE + * @param totalMachine total number of Machines + * @param totalPE total number of PEs for each Machine + */ + private static GridResource createGridResource(String name, int peRating, + int totalMachine, int totalPE) + { + + ////////////////////////////////////////// + // Here are the steps needed to create a Grid resource: + // 1. We need to create an object of MachineList to store one or more + // Machines + MachineList mList = new MachineList(); + + for (int i = 0; i < totalMachine; i++) + { + ////////////////////////////////////////// + // 4. Create one Machine with its id and list of PEs or CPUs + mList.add( new Machine(i, totalPE, peRating) ); + } + + ////////////////////////////////////////// + // 5. Create a ResourceCharacteristics object that stores the + // properties of a Grid resource: architecture, OS, list of + // Machines, allocation policy: time- or space-shared, time zone + // and its price (G$/PE time unit). + String arch = "Sun Ultra"; // system architecture + String os = "Solaris"; // operating system + double time_zone = 0.0; // time zone this resource located + double cost = 3.0; // the cost of using this resource + + // this resource will use an aggressive backfilling policy (EASY) + TResourceCharacteristics resConfig = new TResourceCharacteristics( + arch, os, mList, TResourceCharacteristics.EB_PARALLEL_SPACE_SHARED, + time_zone, cost); + + ////////////////////////////////////////// + // 6. Finally, we need to create a GridResource object. + double baud_rate = 10000.0; // communication speed + long seed = 11L*13*17*19*23+1; + double peakLoad = 0.0; // the resource load during peak hour + double offPeakLoad = 0.0; // the resource load during off-peak hr + double holidayLoad = 0.0; // the resource load during holiday + + // incorporates weekends so the grid resource is on 7 days a week + LinkedList weekends = new LinkedList(); + weekends.add(new Integer(Calendar.SATURDAY)); + weekends.add(new Integer(Calendar.SUNDAY)); + + // incorporates holidays. However, no holidays are set in this example + LinkedList holidays = new LinkedList(); + GridResource gridRes = null; + try { + gridRes = new GridResource(name, baud_rate, seed, + resConfig, peakLoad, offPeakLoad, holidayLoad, weekends, + holidays); + } + catch (Exception e) { + e.printStackTrace(); + } + + System.out.println("Creates one Grid resource with name = " + name); + return gridRes; + } +} // end class + Added: branches/gridsim4.0-branch3/source/gridsim/turbo/MultipleEasyBackfillingQueues.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/MultipleEasyBackfillingQueues.java (rev 0) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/MultipleEasyBackfillingQueues.java 2008-02-12 05:46:26 UTC (rev 101) @@ -0,0 +1,322 @@ +/* + * Title: GridSim Toolkit + * Description: GridSim (Grid Simulation) Toolkit for Modelling and Simulation + * of Parallel and Distributed Systems such as Clusters and Grids + * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + * + */ + +package gridsim.turbo; + +import eduni.simjava.Sim_event; +import eduni.simjava.Sim_system; +import gridsim.GridSim; +import gridsim.GridSimTags; +import gridsim.Gridlet; +import gridsim.gui.AllocationAction; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Iterator; +import java.util.LinkedList; + +/** + * Under development... + * + * @author Marcos Dias de Assuncao + * @since GridSim Turbo Alpha 0.1 + * + * @see gridsim.GridSim + * @see gridsim.ResourceCharacteristics + * @see gridsim.turbo.TAllocPolicy + * @see gridsim.turbo.CBParallelSpaceShared + * @see gridsim.turbo.PERange + * @see gridsim.turbo.PERangeList + */ + +public class MultipleEasyBackfillingQueues extends TAllocPolicy { + + // Queue of running Gridlets + protected LinkedList<SSGridlet> runningGridlets_; + + // The queues used by this scheduler + protected ArrayList<EasyBackfillingQueue> queues_; + + // The rating of one PE + protected int ratingPE_; + + // the resource characteristics object to be used + protected TResourceCharacteristics resource_; + + // the last time when the schedule updated was called + private double lastScheduleUpdate_; + + // a tag to indicate that a gridlet has finished + private static final int UPDATE_SCHEDULE_TAG = 10; + + // a constant that denotes an unknown value + private static final int UNKNOWN = -1; + + /** + * Allocates a new <tt>EBParallelSpaceShared</tt> object + * + * @param resourceName the <tt>GridResource</tt> entity name that will + * contain this allocation policy + * @param entityName this object entity name + * @throws Exception This happens when one of the following scenarios occur: + * <ul> + * <li> Creating this entity before initialising GridSim package + * <li> The entity name is <tt>null</tt> or empty + * <li> The entity has <tt>zero</tt> number of PEs (Processing + * Elements). <br> + * No PEs, which means that the Gridlets cannot be processed. + * A GridResource must contain one or more Machines. + * A Machine must contain one or more PEs. + * </ul> + * + * @see gridsim.GridSim#init(int, Calendar, boolean, + * String[], String[], String) + */ + public MultipleEasyBackfillingQueues(String resourceName, + String entityName) throws Exception{ + super(resourceName, entityName); + + // initialises local data structure + runningGridlets_ = new LinkedList<SSGridlet>(); + lastScheduleUpdate_ = 0.0D; + ratingPE_ = 0; + } + + /** + * Handles internal events that come to this entity. + */ + public void body() { + + // get the resource characteristics object to be used + resource_ = getTResourceCharacteristics(); + + // Gets the information on number of PEs and rating + // of one PE assuming that the machines are homogeneous + ratingPE_ = resource_.getMIPSRatingOfOnePE(); + + // a loop that is looking for internal events only + Sim_event ev = new Sim_event(); + while ( Sim_system.running() ) { + super.sim_get_next(ev); + + // if the simulation finishes then exit the loop + if (ev.get_tag() == GridSimTags.END_OF_SIMULATION || + super.isEndSimulation() == true) { + break; + } + + processEvent(ev); + } + + // CHECK for ANY INTERNAL EVENTS WAITING TO BE PROCESSED + while (super.sim_waiting() > 0) { + // wait for event and ignore since it is likely to be related to + // internal event scheduled to update Gridlets processing + super.sim_get_next(ev); + System.out.println(super.get_name() + ".body(): ignore internal events"); + } + + // reset variables to default values + runningGridlets_.clear(); + lastScheduleUpdate_ = 0.0D; + ratingPE_ = 0; + resource_.resetFreePERanges(); + } + + /** + * Schedules/adds to the queue a new <tt>Gridlet</tt> received by the + * <tt>GridResource</tt> entity. + * @param gridlet a Gridlet object to be executed + * @param ack an acknowledgement, i.e. <tt>true</tt> if the + * user wants to know whether this operation is successful + * or not, <tt>false</tt> otherwise. + */ + public void gridletSubmit(Gridlet gridlet, boolean ack) { + int reqPE = gridlet.getNumPE(); + + try{ + // reject the Gridlet if it requires more PEs than the resource + // is able to provide + if(reqPE > super.totalPE_){ + String userName = GridSim.getEntityName( gridlet.getUserID() ); + System.out.println(super.get_name() + ".gridletSubmit(): " + + " Gridlet #" + gridlet.getGridletID() + " from " + + userName + " user requires " + gridlet.getNumPE() + " PEs."); + System.out.println("--> The resource has only " + + super.totalPE_ + " PEs."); + gridlet.setGridletStatus(Gridlet.FAILED); + super.sendFinishGridlet(gridlet); + return; + } + } + catch(Exception ex){ + System.out.println(super.get_name() + + ": Exception on submission of a Gridlet"); + } + + // Create a resource Gridlet + SSGridlet sgl = new SSGridlet(gridlet); + + //-------------- FOR DEBUGGING PURPOSES ONLY -------------- + + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_ARRIVED, true, sgl); + + } + + /** + * Finds the status of a specified <tt>Gridlet</tt>. + * @param gridletId a Gridlet ID + * @param userId the user or owner's ID of this Gridlet + * @return the Gridlet status or <tt>-1</tt> if not found + * @see gridsim.Gridlet + * @pre gridletId > 0 + * @pre userId > 0 + * @post $none + */ + public int gridletStatus(int gridletId,int userId){ + return UNKNOWN; + } + + /** + * Cancels a Gridlet running or in the waiting queue.<br> + * <b>NOTE: Not implemented YET.</b> + * @param gridletId a Gridlet ID + * @param userId the user or owner's ID of this Gridlet + * @pre gridletId > 0 + * @pre userId > 0 + */ + public void gridletCancel(int gridletId, int userId) { + System.out.println(super.get_name() + + ".gridletCancel(): not supported at the moment."); + } + + /** + * Pauses a <tt>Gridlet</tt> only if it is currently executing. + * <b>NOTE: This operation is not supported. </b> + * @param gridletId a Gridlet ID + * @param userId the user or owner's ID of this Gridlet + * @param ack an acknowledgement, i.e. <tt>true</tt> if wanted to know + * whether this operation is success or not, <tt>false</tt> + * otherwise. + */ + public void gridletPause(int gridletId, int userId, boolean ack){ + System.out.println(super.get_name() + + ".gridletMove(): not supported at the moment."); + } + + /** + * Moves a Gridlet from this GridResource entity to a different one. + * <b>NOTE: This operation is not supported. </b> + * @param gridletId a Gridlet ID + * @param userId the user or owner's ID of this Gridlet + * @param destId a new destination GridResource ID for this Gridlet + * @param ack an acknowledgement, i.e. <tt>true</tt> if wanted to know + * whether this operation is success or not, <tt>false</tt> + * otherwise + */ + public void gridletMove(int gridletId, int userId, int destId, boolean ack){ + System.out.println(super.get_name() + + ".gridletPause(): not supported at the moment."); + } + + /** + * Resumes a Gridlet only in the paused list. + * <b>NOTE: This operation is not supported. </b> + * @param gridletId a Gridlet ID + * @param userId the user or owner's ID of this Gridlet + * @param ack an acknowledgement, i.e. <tt>true</tt> if wanted to know + * whether this operation is success or not, <tt>false</tt> + * otherwise + */ + public void gridletResume(int gridletId, int userId, boolean ack){ + System.out.println(super.get_name() + + ".gridletResume(): not supported at the moment."); + } + + // -------------------- PRIVATE METHODS ---------------------------- + + /** + * Process and event sent to this entity + * @param ev the event to be handled + */ + private void processEvent(Sim_event ev) { + + // handle an internal event + double currentTime = GridSim.clock(); + + // Internal Event if the event source is this entity + if(ev.get_src() == myId_) { + // time to update the schedule, finish gridlets, + // finish reservations, start reservations and start gridlets + if (ev.get_tag() == UPDATE_SCHEDULE_TAG) { + if(currentTime > lastScheduleUpdate_) { + updateSchedule(); + } + lastScheduleUpdate_ = currentTime; + } + else + processOtherEvent(ev); + } + else + processOtherEvent(ev); + } + + /** + * This method is called to update the schedule. It removes completed + * gridlets and return them to the users and verifies whether the first gridlet + * in the waiting queue can be started. If it cannot be started, them + * tries to backfill with jobs waiting in the queue. The method also + * removes old entries from the availability profile. + */ + private void updateSchedule(){ + + + } + + static class EasyBackfillingQueue { + + int queueId_ = UNKNOWN; + + // initial number of PEs assigned to this queue + int initialNumPE_ = 0; + + // Queue of Gridlets waiting in this queue + LinkedList<SSGridlet> queuedGridlets_; + + // the time when the first job in the waiting queue can + // start its execution + double shadowTime_ = Double.MAX_VALUE; + + // the list of PEs left unused when the first job in the waiting + // queue is scheduled + PERangeList extraPEs_ = null; + + // a list containing the availability of PEs + AvailabilityProfile availProfile_; + + // The list of PEs available at the current simulation time + PERangeList freePERanges_ = null; + + + + } + + /** + * Updates the Gridlet's properties, such as status once a + * Gridlet is considered finished. + * @param sgl a SSGridlet object + * @param status the Gridlet status + */ + private void gridletFinish(SSGridlet sgl, int status) { + // the order is important! Set the status first then finalise + // due to timing issues in SSGridlet class + sgl.setStatus(status); + sgl.finalizeGridlet(); + super.sendFinishGridlet( sgl.getGridlet() ); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |