📄 workload.java
字号:
/* * Title: GridSim Toolkit * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * * $Id: Workload.java,v 1.9 2007/08/30 01:50:04 anthony Exp $ */package gridsim.util;import eduni.simjava.*;import gridsim.*;import gridsim.net.*;// below packages are needed to read a fileimport java.util.*;import java.util.zip.*;import java.io.*;/** * The main purpose of this class is to create a realistic simulation * environment where your jobs or Gridlets are competing with others. * In other words, the grid resource might not be available at certain times. * In addition, the arrival time of jobs are also captured in the trace file. * <p> * This class is responsible for reading resource traces from a file and * sends Gridlets to only <tt>one</tt> destinated resource. <br> * <b>NOTE:</b> * <ul> * <li> This class can only take <tt>one</tt> trace file of the following * format: <i>ASCII text, zip, gz.</i> * <li> This class can be classified as <b>one grid user entity</b>. * Hence, you need to incorporate this entity into <tt>numUser</tt> * during {@link gridsim.GridSim#init(int, Calendar, boolean)} * <li> If you need to use multiple trace files to submit Gridlets to * same or different resources, then you need to create multiple * instances of this class <tt>each with a unique entity name</tt>. * <li> If size of the trace file is huge or contains lots of traces * please increase the JVM heap size accordingly by using * <tt>java -Xmx</tt> option when running the simulation. * <li> If you are running an experiment using the network extension, * i.e. the gridsim.net package, then you need to use * {@link #Workload(String, double, double, int, String, String, int)} * instead. * <li> The default job file size for sending to and receiving from * a resource is {@link gridsim.net.Link#DEFAULT_MTU}. * However, you can specify * the file size by using {@link #setGridletFileSize(int)}. * <li> A job run time is only for 1 PE <tt>not</tt> the total number of * allocated PEs. * Therefore, a Gridlet length is also calculated for 1 PE.<br> * For example, job #1 in the trace has a run time of 100 seconds * for 2 processors. This means each processor runs * job #1 for 100 seconds, if the processors have the same * specification. * </ul> * <p> * By default, this class follows the standard workload format as specified * in <a href="http://www.cs.huji.ac.il/labs/parallel/workload/"> * http://www.cs.huji.ac.il/labs/parallel/workload/</a> <br> * However, you can use other format by calling the below methods before * running the simulation: * <ul> * <li> {@link #setComment(String)} * <li> {@link #setField(int, int, int, int, int)} * </ul> * * @see gridsim.GridSim#init(int, Calendar, boolean) * @author Anthony Sulistio * @since GridSim Toolkit 3.1 * @invariant $none */public class Workload extends GridSim{ private String fileName_; // file name private String resName_; // resource name private int resID_; // resource ID private int rating_; // a PE rating private int gridletID_; // gridletID private int size_; // job size for sending it through a network private ArrayList list_; // a list for getting all the Gridlets // constant private int JOB_NUM; // job number private int SUBMIT_TIME; // submit time of a Gridlet private int RUN_TIME; // running time of a Gridlet private int NUM_PROC; // number of processors needed for a Gridlet private int REQ_NUM_PROC; // required number of processors private int REQ_RUN_TIME; // required running time private int MAX_FIELD; // max number of field in the trace file private String COMMENT; // a string that denotes the start of a comment private final int IRRELEVANT = -1; // irrelevant number private final int INTERVAL = 10; // number of intervals private String[] fieldArray_; // a temp array storing all the fields /** * Create a new Workload object <b>without</b> using the network extension. * This means this entity directly sends Gridlets to a destinated resource * without going through a wired network. <br> * <tt>NOTE:</tt> * You can not use this constructor in an experiment that uses a wired * network topology. * * @param name this entity name * @param fileName the workload trace filename in one of the following * format: <i>ASCII text, zip, gz.</i> * @param resourceName the resource name * @param rating the resource's PE rating * @throws Exception This happens when creating this entity before * initializing GridSim package or this entity name is * <tt>null</tt> or empty * @throws ParameterException This happens for the following conditions: * <ul> * <li>the entity name is null or empty * <li>the workload trace file name is null or empty * <li>the resource entity name is null or empty * <li>the resource PE rating <= 0 * </ul> * @pre name != null * @pre fileName != null * @pre resourceName != null * @pre rating > 0 * @post $none */ public Workload(String name, String fileName, String resourceName, int rating) throws ParameterException, Exception { super(name, GridSimTags.DEFAULT_BAUD_RATE); // check the input parameters first String msg = name + "(): Error - "; if (fileName == null || fileName.length() == 0) { throw new ParameterException(msg + "invalid trace file name."); } else if (resourceName == null || resourceName.length() == 0) { throw new ParameterException(msg + "invalid resource name."); } else if (rating <= 0) { throw new ParameterException(msg+"resource PE rating must be > 0."); } System.out.println(name + ": Creating a workload object ..."); init(fileName, resourceName, rating); } /** * Create a new Workload object <b>with</b> the network extension. * This means this entity directly sends Gridlets to a destinated resource * through a link. The link is automatically created by this constructor. * * @param name this entity name * @param baudRate baud rate of this link (bits/s) * @param propDelay Propogation delay of the Link in milli seconds * @param MTU Maximum Transmission Unit of the Link in bytes. * Packets which are larger than the MTU should be split * up into MTU size units. * For example, a 1024 byte packet trying to cross a 576 * byte MTU link should get split into 2 packets of 576 * bytes and 448 bytes. * @param fileName the workload trace filename in one of the following * format: <i>ASCII text, zip, gz.</i> * @param resourceName the resource name * @param rating the resource's PE rating * @throws Exception This happens when creating this entity before * initializing GridSim package or this entity name is * <tt>null</tt> or empty * @throws ParameterException This happens for the following conditions: * <ul> * <li>the entity name is null or empty * <li> baudRate <= 0 * <li> propDelay <= 0 * <li> MTU <= 0 * <li>the workload trace file name is null or empty * <li>the resource entity name is null or empty * <li>the resource PE rating <= 0 * </ul> * @pre name != null * @pre baudRate > 0 * @pre propDelay > 0 * @pre MTU > 0 * @pre fileName != null * @pre resourceName != null * @pre rating > 0 * @post $none */ public Workload(String name, double baudRate, double propDelay, int MTU, String fileName, String resourceName, int rating) throws ParameterException, Exception { super( name, new SimpleLink(name+"_link", baudRate, propDelay, MTU) ); // check the input parameters first String msg = name + "(): Error - "; if (fileName == null || fileName.length() == 0) { throw new ParameterException(msg + "invalid trace file name."); } else if (resourceName == null || resourceName.length() == 0) { throw new ParameterException(msg + "invalid resource name."); } else if (rating <= 0) { throw new ParameterException(msg+"resource PE rating must be > 0."); } System.out.println(name + ": Creating a workload object ..."); init(fileName, resourceName, rating); } /** * Create a new Workload object <b>with</b> the network extension. * This means this entity directly sends Gridlets to a destinated resource * through a link. The link is automatically created by this constructor. * * @param name this entity name * @param link the link that will be used to connect this Workload * to another entity or a Router. * @param fileName the workload trace filename in one of the following * format: <i>ASCII text, zip, gz.</i> * @param resourceName the resource name * @param rating the resource's PE rating * @throws Exception This happens when creating this entity before * initializing GridSim package or this entity name is * <tt>null</tt> or empty * @throws ParameterException This happens for the following conditions: * <ul> * <li>the entity name is null or empty * <li>the link is empty * <li>the workload trace file name is null or empty * <li>the resource entity name is null or empty * <li>the resource PE rating <= 0 * </ul> * @pre name != null * @pre link != null * @pre fileName != null * @pre resourceName != null * @pre rating > 0 * @post $none */ public Workload(String name, Link link, String fileName, String resourceName, int rating) throws ParameterException, Exception { super(name, link); // check the input parameters first String msg = name + "(): Error - "; if (fileName == null || fileName.length() == 0) { throw new ParameterException(msg + "invalid trace file name."); } else if (resourceName == null || resourceName.length() == 0) { throw new ParameterException(msg + "invalid resource name."); } else if (rating <= 0) { throw new ParameterException(msg+"resource PE rating must be > 0."); } System.out.println(name + ": Creating a workload object ..."); init(fileName, resourceName, rating); } /** * Initialises all the attributes * @param fileName trace file name * @param resourceName resource entity name * @param rating resource PE rating * @pre $none * @post $none */ private void init(String fileName, String resourceName, int rating) { fileName_ = fileName; resName_ = resourceName; resID_ = GridSim.getEntityId(resName_); rating_ = rating; gridletID_ = 1; // starts at 1 to make it the same as in a trace file list_ = null; size_ = Link.DEFAULT_MTU; // if using Standard Workload Format -- don't forget to substract by 1 // since an array starts at 0, but the field in a trace starts at 1 JOB_NUM = 1 - 1; SUBMIT_TIME = 2 - 1; RUN_TIME = 4 - 1; NUM_PROC = 5 - 1; REQ_NUM_PROC = 8 - 1; REQ_RUN_TIME = 9 - 1; COMMENT = ";"; // semicolon means the start of a comment MAX_FIELD = 18; // standard workload format has 18 fields fieldArray_ = null; } /** * Sets a Gridlet file size (in byte) for sending to/from a resource. * @param size a Gridlet file size (in byte) * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise * @pre size > 0 * @post $none */ public boolean setGridletFileSize(int size) { if (size < 0) { return false; } size_ = size; return true; } /** * Identifies the start of a comment line. Hence, a line that starts * with a given comment will be ignored. * @param comment a character that denotes the start of a comment,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -