📄 broker.java
字号:
* @pre parameter >= 0 * @pre expt != null * @pre BRList != null * @post $none */ public void writeScheduleReport(String reportTitle, String reportFileFullname, int parameter, Experiment expt, LinkedList BRList, boolean reportHeaderFlag) { try { // open file for append mode. FileWriter fw = new FileWriter(reportFileFullname, true); BufferedWriter bw = new BufferedWriter(fw); PrintWriter reportFile = new PrintWriter(bw); String [] resourceNameList = expt.getResourceNameList(); int length = resourceNameList.length; if (reportHeaderFlag) { // TIME-STAMP "\t" Resource1-Name "\t" Resource2-Name "\t" // Resource3-Name ... reportFile.println(reportTitle); // start on newline. reportFile.println("Deadline: " + expt.getDeadline() + " Budget: " + expt.getBudget()); reportFile.print("Time-Stamp"); for (int i = 0; i < length; i++) { reportFile.print("\t" + resourceNameList[i]); } reportFile.print("\t" + "Total"); reportFile.println(); // end of header line. } else { // TIME-STAMP "\t" Resource1-Name "\t" Resource2-Name "\t" // Resource3-Name ... reportFile.print( GridSim.clock() ); double total_finished = 0; double value = 0.0; for (int i = 0; i < length; i++) { BrokerResource br = findBrokerResourceWithName(BRList, resourceNameList[i]); value = br.getParameterValue(parameter); reportFile.print("\t" + value); total_finished += value; } reportFile.print("\t" + total_finished); reportFile.println(); // end of a report row. } reportFile.close(); } catch (IOException e) { System.out.println("Broker.writeScheduleReport(): Error - unable " + "to open \"" + reportFileFullname + "\""); } } /** * Writes a summary of the schedule report mentioning the total results * of the experiment. * <p> * In addition, * creates report files with <tt>".sched4"</tt>, <tt>".sched5"</tt>, and * <tt>".sched6"</tt> extension. * @param expt an Experiment object * @param BRList a linked-list of BrokerResource objects * @deprecated As of GridBroker 2.1, replaced by * {@link #aggregatedScheduleReport(Experiment, LinkedList)} * @pre expt != null * @pre BRList != null * @post $none */ public void AggregatedScheduleReport(Experiment expt, LinkedList BRList) { this.aggregatedScheduleReport(expt, BRList); } /** * Writes a summary of the schedule report mentioning the total results * of the experiment. * <p> * In addition, * creates report files with <tt>".sched4"</tt>, <tt>".sched5"</tt>, and * <tt>".sched6"</tt> extension. * @param expt an Experiment object * @param BRList a linked-list of BrokerResource objects * @pre expt != null * @pre BRList != null * @post $none */ public void aggregatedScheduleReport(Experiment expt, LinkedList BRList) { if (expt.getExperimentID() != 0) { return; } // print scheduling trace for experiment with ID 0 (i.e., for the // first user) String report1_filename = expt.getReportFileName() + ".sched4"; String report2_filename = expt.getReportFileName() + ".sched5"; String report3_filename = expt.getReportFileName() + ".sched6"; writeAggregateScheduleReport("Gridlets Finished Report", report1_filename, BrokerResource.PARAM_GRIDLETS_FINISHED, expt, BRList, false); writeAggregateScheduleReport("Gridlets Processing Expenses Report", report2_filename, BrokerResource.PARAM_PROCESSING_EXPENSES, expt, BRList, false); writeAggregateScheduleReport("Gridlets on Resource Report", report3_filename, BrokerResource.PARAM_GRIDLETS_ON_RESOURCE, expt, BRList, false); } /** * Writes a schedule report * @param reportTitle the report title * @param reportFileFullname the file name * @param parameter the parameter of a broker resource * @param expt an Experiment object * @param BRList a linked-list of BrokerResource objects * @param reportHeaderFlag a flag to denote writing header titles or * @deprecated As of GridBroker 2.1, replaced by * {@link #writeAggregateScheduleReport(String, String, int, * Experiment, LinkedList, boolean)} * @pre reportTitle != null * @pre reportFileFullname != null * @pre parameter >= 0 * @pre expt != null * @pre BRList != null * @post $none */ public void WriteAggregateScheduleReport(String reportTitle, String reportFileFullname, int parameter, Experiment expt, LinkedList BRList, boolean reportHeaderFlag) { this.writeAggregateScheduleReport(reportTitle, reportFileFullname, parameter, expt, BRList, reportHeaderFlag); } /** * Writes a schedule report * @param reportTitle the report title * @param reportFileFullname the file name * @param parameter the parameter of a broker resource * @param expt an Experiment object * @param BRList a linked-list of BrokerResource objects * @param reportHeaderFlag a flag to denote writing header titles or * @pre reportTitle != null * @pre reportFileFullname != null * @pre parameter >= 0 * @pre expt != null * @pre BRList != null * @post $none */ public void writeAggregateScheduleReport(String reportTitle, String reportFileFullname, int parameter, Experiment expt, LinkedList BRList, boolean reportHeaderFlag) { try { // open file for append mode. FileWriter fw = new FileWriter(reportFileFullname, true); BufferedWriter bw = new BufferedWriter(fw); PrintWriter reportFile = new PrintWriter(bw); String [] resourceNameList = expt.getResourceNameList(); int length = resourceNameList.length; if (reportHeaderFlag) { // TIME-STAMP "\t" Resource1-Name "\t" Resource2-Name "\t" // Resource3-Name ... reportFile.println(reportTitle); // start on newline. reportFile.println("Deadline: " + expt.getDeadline() + " Budget: " + expt.getBudget()); for (int i = 0; i < length; i++) { reportFile.print("\t" + resourceNameList[i]); } reportFile.print("\t"+"Total"); reportFile.println(); // end of header line. } else { // FOR Gridlet Completion on Resources, .. , // TimeStamp Deadline Budget R0 R2 R3 .... // TIME-STAMP "\t" Resource1-Name "\t" Resource2-Name "\t" // Resource3-Name ... reportFile.print(GridSim.clock() + "\t" + expt.getDeadline() + "\t" + expt.getBudget()); double total_finished = 0; double value = 0.0; for (int i = 0; i < length; i++) { BrokerResource br = findBrokerResourceWithName(BRList, resourceNameList[i]); value = br.getParameterValue(parameter); reportFile.print("\t" + value); total_finished += value; } reportFile.print("\t" + total_finished); reportFile.println(); // end of a report row. } reportFile.close(); } catch (IOException e) { System.out.println("Broker.writeAggregateScheduleReport(): Error -"+ " unable to open \"" + reportFileFullname + "\""); } } /** * Processes one event at one time. Then calculating the gridlet deadline * and budget. In addition, starting the experiment time, records * statistics, and constructs report files. * @pre $none * @post $none */ public void body() { Sim_event ev = new Sim_event(); // Accept User Commands and Process for ( sim_get_next(ev); ev.get_tag() != GridSimTags.END_OF_SIMULATION; sim_get_next(ev) ) { // Extra Experiment Details from the User Event if (ev.get_tag() != GridSimTags.EXPERIMENT) { System.out.println(super.getEntityName() + ": A late delivery of Gridlet!"); System.out.println("-->1. Please ensure that GridBroker waits" + " for arrival of all Gridlets assigned to resource."); System.out.println("-->2. Make sure that Resources are NOT " + "returning more Gridlets than assigned to it!"); System.out.println( ev.get_data() ); continue; } experiment_ = (Experiment) ev.get_data(); int UserEntityID = ev.get_src(); // Record Experiment Start Time. experiment_.setStartTime(); // Set Gridlets OwnerID as this BrokerID so that Resources // knows where to return them. int i = 0; int id = super.get_id(); for (i = 0; i < experiment_.getGridletList().size(); i++) { ( (Gridlet) experiment_.getGridletList().get(i) ).setUserID(id); } // RESOURCE DISCOVERY: Get Resource List from GIS + Property // from Resource Info Service // Requesting the GridInformationService to send a list of resources resIDList_ = super.getGridResourceList(); super.recordStatistics("BROKER.Resource.Count", resIDList_.size()); // Cretae Resource List with Static and Dynamic Info. brokerResourceList_ = new LinkedList(); Accumulator accMIPSRatingAll = new Accumulator(); Accumulator accMIPSRating = new Accumulator(); Accumulator accMIPSRatingAllWithLoad = new Accumulator(); Accumulator accCostPerMI = new Accumulator(); // Create Broker Resource List: include Static and Dynamic // Characteristics for (i = 0; i < resIDList_.size(); i++) { // Get Resource ID int res_id = ( (Integer) resIDList_.get(i) ).intValue(); // Get Resource Characteristic Info ResourceCharacteristics res = super.getResourceCharacteristics( res_id); accMIPSRating.add( res.getMIPSRatingOfOnePE() ); accMIPSRatingAll.add( res.getMIPSRating() ); accCostPerMI.add( res.getCostPerMI() ); // Get Resource Dynamic information Accumulator accLoad = super.getResourceDynamicInfo(res_id); accMIPSRatingAllWithLoad.add( res.getMIPSRating() * (1 - accLoad.getMean()) ); brokerResourceList_.add( new BrokerResource(res, accLoad.getMean()) ); } // calculate deadline and budget based on D_factor, B_factor, // workload and resource charactertiscs. if ( experiment_.getFactorFlag() ) { Accumulator accLength = experiment_.getAllGridletLengthAccumulator(); double total_MI = accLength.getSum(); // MAX and MIN_TIME for gridlet processing should be at least // time required to process a single gridlet // on a faster processor. double ratingMax = accMIPSRating.getMax(); double lengthMax = accLength.getMax(); double MAX_time = Math.max( total_MI/accMIPSRatingAllWithLoad.getMin(), lengthMax / ratingMax ); double MIN_time = Math.max( total_MI/accMIPSRatingAll.getSum(), lengthMax / ratingMax ); double deadline_duration = MIN_time + (experiment_.getDeadlineFactor() * (MAX_time - MIN_time)); // ADDING 10% of COMMUNICATION OVERHEAD to the Computational // Deadline deadline_duration += deadline_duration * 0.1; // processing cost on the most expensive machine double MAX_cost = total_MI * accCostPerMI.getMax(); // processing cost on the least expensive machine double MIN_cost = total_MI * accCostPerMI.getMin(); double budget = MIN_cost + (experiment_.getBudgetFactor() * (MAX_cost-MIN_cost)); experiment_.setDeadlineBudget(deadline_duration, budget); } System.out.println(super.getEntityName() + ":: Deadline: " + experiment_.getDeadline()+" Budget: "+experiment_.getBudget()); super.recordStatistics("USER.Experiment.Deadline", experiment_.getDeadline()); super.recordStatistics("USER.Experiment.Budget", experiment_.getBudget()); // INITIALISE Broker's global member variables glUnfinishedList_ = (GridletList) experiment_.getGridletList().clone(); glFinishedList_ = new GridletList(); gridletDispatched_ = 0; gridletReturned_ = 0; expenses_ = 0.0; // INITIAL Report Writter: // create a clone of brokerResourceList_ to maintain the listing // Order for Report Generation LinkedList BRListOriginal = (LinkedList)brokerResourceList_.clone();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -