📄 dataexample2.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 */import gridsim.*;import gridsim.datagrid.*;import gridsim.datagrid.index.DataGIS;import gridsim.datagrid.index.TopRegionalRC;import gridsim.datagrid.storage.HarddriveStorage;import gridsim.datagrid.storage.Storage;import gridsim.net.*;import java.util.ArrayList;import java.util.Calendar;import java.util.LinkedList;/** * This is an example that demonstrates how to implement basic user behviour. * The topology and the resources are the same as in other datagrid examples. * The user behaviour is implemented in Fileuser.java. * * @author Uros Cibej and Anthony Sulistio */public class DataExample2 { public static void main(String[] args) { DataGIS gis = null; TopRegionalRC rc = null; DataGridUser user = null; // FIRST STEP--------------------------------------------- // Initialize the GridSim package int num_user = 1; // number of grid users Calendar calendar = Calendar.getInstance(); boolean trace_flag = false; // means trace GridSim events boolean gisFlag = false; // means using DataGIS instead GridSim.init(num_user, calendar, trace_flag, gisFlag); // set the GIS into DataGIS that handles specifically for data grid // scenarios try { gis = new DataGIS(); GridSim.setGIS(gis); } catch (Exception e) { e.printStackTrace(); } // SECOND STEP--------------------------------------------- // Create a top level Replica Catalogue double baud_rate = 1000000; // bits/sec double propDelay = 10; // propagation delay in millisecond int mtu = 1500; // max. transmission unit in byte try { SimpleLink l = new SimpleLink("rc_link", baud_rate, propDelay, mtu); rc = new TopRegionalRC(l); } catch (Exception e1) { e1.printStackTrace(); } // THIRD STEP--------------------------------------------- // Create resources int i = 0; int totalResource = 3; ArrayList resList = new ArrayList(totalResource); for (i = 0; i < totalResource; i++) { DataGridResource res = createGridResource("Res_" + i, baud_rate, propDelay, mtu); resList.add(res); } // FOURTH STEP--------------------------------------------- // Create user(s) try { user = new FileUser("File_User", baud_rate, propDelay, mtu); user.setReplicaCatalogue(TopRegionalRC.DEFAULT_NAME); } catch (Exception e2) { e2.printStackTrace(); } // FIFTH STEP--------------------------------------------- // Create network Router r1 = new RIPRouter("router1"); // router 1 Router r2 = new RIPRouter("router2"); // router 2 try { // connect the routers baud_rate = 10000000; Link link = new SimpleLink("r1_r2_link", baud_rate, propDelay, mtu); FIFOScheduler r1Sched = new FIFOScheduler(); FIFOScheduler r2Sched = new FIFOScheduler(); // attach r2 to r1 r1.attachRouter(r2, link, r1Sched, r2Sched); } catch (Exception e3) { e3.printStackTrace(); } // FIFTH STEP--------------------------------------------- // Connect resources, users and catalogues to the network try { // connect resources GridResource resObj = null; for (i = 0; i < resList.size(); i++) { FIFOScheduler resSched = new FIFOScheduler(); resObj = (GridResource) resList.get(i); r2.attachHost(resObj, resSched);// attach resource to router } // connect user FIFOScheduler userSched = new FIFOScheduler(); r1.attachHost(user, userSched); // atach the user to router r1 // connect rc FIFOScheduler rcSched = new FIFOScheduler(); r2.attachHost(rc, rcSched); // attach RC } catch (ParameterException e4) { e4.printStackTrace(); } // SIXTH STEP--------------------------------------------- // Finally start the simulation GridSim.startGridSimulation(); } private static DataGridResource createGridResource(String name, double baud_rate, double delay, int MTU) { System.out.println(); System.out.println("Starting to create one Grid resource with " + "3 Machines"); // 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(); // 2. A Machine contains one or more PEs or CPUs. Therefore, should // create an object of PEList to store these PEs before creating // a Machine. PEList peList1 = new PEList(); // 3. Create PEs and add these into an object of PEList. // In this example, we are using a resource from // hpc420.hpcc.jp, AIST, Tokyo, Japan // Note: these data are taken the from GridSim paper, page 25. // In this example, all PEs has the same MIPS (Millions // Instruction Per Second) Rating for a Machine. peList1.add(new PE(0, 377)); // need to store PE id and MIPS Rating peList1.add(new PE(1, 377)); peList1.add(new PE(2, 377)); peList1.add(new PE(3, 377)); // 4. Create one Machine with its id and list of PEs or CPUs mList.add(new Machine(0, peList1)); // First Machine // 5. Repeat the process from 2 if we want to create more Machines // In this example, the AIST in Japan has 3 Machines with same // MIPS Rating but different PEs. // NOTE: if you only want to create one Machine for one Grid resource, // then you could skip this step. PEList peList2 = new PEList(); peList2.add(new PE(0, 377)); peList2.add(new PE(1, 377)); peList2.add(new PE(2, 377)); peList2.add(new PE(3, 377)); mList.add(new Machine(1, peList2)); // Second Machine PEList peList3 = new PEList(); // System.out.println("Creates a PE list for the 3rd Machine"); peList3.add(new PE(0, 377)); peList3.add(new PE(1, 377)); mList.add(new Machine(2, peList3)); // Third Machine // 6. 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 = 9.0; // time zone this resource located double cost = 3.0; // the cost of using this resource ResourceCharacteristics resConfig = new ResourceCharacteristics(arch, os, mList, ResourceCharacteristics.TIME_SHARED, time_zone, cost); // System.out.println("Creates the properties of a Grid resource and " + // "stores the Machine list"); // 7. Finally, we need to create a GridResource object. 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(); DataGridResource gridRes = null; try { // create the replica manager SimpleReplicaManager rm = new SimpleReplicaManager("RM_" + name, name); // create the resource calendar ResourceCalendar cal = new ResourceCalendar(time_zone, peakLoad, offPeakLoad, holidayLoad, Weekends, Holidays, seed); // create a storage Storage storage = new HarddriveStorage("storage", 100000); // 100GB // create the DataGrid resource gridRes = new DataGridResource(name, new SimpleLink(name + "_link", baud_rate, delay, MTU), resConfig, cal, rm); // add a storage to the resource gridRes.addStorage(storage); // tell the resource about a replica catalogue gridRes.setReplicaCatalogue(TopRegionalRC.DEFAULT_NAME); // in this example, we create 1 master file File f = new File("testFile1", 1);// 100 MB gridRes.addFile(f); } catch (Exception e) { e.printStackTrace(); } System.out.println("Finally, creates one Grid resource (name: " + name + " - id: " + gridRes.get_id() + ")"); System.out.println(); return gridRes; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -