analysejobhistory.jsp
上传用户:quxuerui
上传日期:2018-01-08
资源大小:41811k
文件大小:10k
源码类别:

网格计算

开发平台:

Java

  1. <%@ page
  2.   contentType="text/html; charset=UTF-8"
  3.   import="javax.servlet.http.*"
  4.   import="java.io.*"
  5.   import="java.util.*"
  6.   import="org.apache.hadoop.mapred.*"
  7.   import="org.apache.hadoop.util.*"
  8.   import="java.text.SimpleDateFormat"
  9.   import="org.apache.hadoop.mapred.JobHistory.*"
  10. %>
  11. <jsp:include page="loadhistory.jsp">
  12.   <jsp:param name="jobid" value="<%=request.getParameter("jobid") %>"/>
  13.   <jsp:param name="logFile" value="<%=request.getParameter("logFile") %>"/>
  14. </jsp:include>
  15. <%! private static SimpleDateFormat dateFormat 
  16.                               = new SimpleDateFormat("d/MM HH:mm:ss") ; 
  17. %>
  18. <html><body>
  19. <%
  20.   String jobid = request.getParameter("jobid");
  21.   String logFile = request.getParameter("logFile");
  22.   String encodedLogFileName = JobHistory.JobInfo.encodeJobHistoryFilePath(logFile);
  23.   String numTasks = request.getParameter("numTasks");
  24.   int showTasks = 10 ; 
  25.   if (numTasks != null) {
  26.     showTasks = Integer.parseInt(numTasks);  
  27.   }
  28.   JobInfo job = (JobInfo)request.getSession().getAttribute("job");
  29. %>
  30. <h2>Hadoop Job <a href="jobdetailshistory.jsp?jobid=<%=jobid%>&&logFile=<%=encodedLogFileName%>"><%=jobid %> </a></h2>
  31. <b>User : </b> <%=job.get(Keys.USER) %><br/> 
  32. <b>JobName : </b> <%=job.get(Keys.JOBNAME) %><br/> 
  33. <b>JobConf : </b> <%=job.get(Keys.JOBCONF) %><br/> 
  34. <b>Submitted At : </b> <%=StringUtils.getFormattedTimeWithDiff(dateFormat, job.getLong(Keys.SUBMIT_TIME), 0 ) %><br/> 
  35. <b>Launched At : </b> <%=StringUtils.getFormattedTimeWithDiff(dateFormat, job.getLong(Keys.LAUNCH_TIME), job.getLong(Keys.SUBMIT_TIME)) %><br/>
  36. <b>Finished At : </b>  <%=StringUtils.getFormattedTimeWithDiff(dateFormat, job.getLong(Keys.FINISH_TIME), job.getLong(Keys.LAUNCH_TIME)) %><br/>
  37. <b>Status : </b> <%= ((job.get(Keys.JOB_STATUS) == null)?"Incomplete" :job.get(Keys.JOB_STATUS)) %><br/> 
  38. <hr/>
  39. <center>
  40. <%
  41.   if (!Values.SUCCESS.name().equals(job.get(Keys.JOB_STATUS))) {
  42.     out.print("<h3>No Analysis available as job did not finish</h3>");
  43.     return;
  44.   }
  45.   Map<String, JobHistory.Task> tasks = job.getAllTasks();
  46.   int finishedMaps = job.getInt(Keys.FINISHED_MAPS)  ;
  47.   int finishedReduces = job.getInt(Keys.FINISHED_REDUCES) ;
  48.   JobHistory.Task [] mapTasks = new JobHistory.Task[finishedMaps]; 
  49.   JobHistory.Task [] reduceTasks = new JobHistory.Task[finishedReduces]; 
  50.   int mapIndex = 0 , reduceIndex=0; 
  51.   long avgMapTime = 0;
  52.   long avgReduceTime = 0;
  53.   long avgShuffleTime = 0;
  54.   for (JobHistory.Task task : tasks.values()) {
  55.     Map<String, TaskAttempt> attempts = task.getTaskAttempts();
  56.     for (JobHistory.TaskAttempt attempt : attempts.values()) {
  57.       if (attempt.get(Keys.TASK_STATUS).equals(Values.SUCCESS.name())) {
  58.         long avgFinishTime = (attempt.getLong(Keys.FINISH_TIME) -
  59.                        attempt.getLong(Keys.START_TIME));
  60.         if (Values.MAP.name().equals(task.get(Keys.TASK_TYPE))) {
  61.           mapTasks[mapIndex++] = attempt ; 
  62.           avgMapTime += avgFinishTime;
  63.         } else if (Values.REDUCE.name().equals(task.get(Keys.TASK_TYPE))) { 
  64.           reduceTasks[reduceIndex++] = attempt;
  65.           avgShuffleTime += (attempt.getLong(Keys.SHUFFLE_FINISHED) - 
  66.                              attempt.getLong(Keys.START_TIME));
  67.           avgReduceTime += (attempt.getLong(Keys.FINISH_TIME) -
  68.                             attempt.getLong(Keys.SHUFFLE_FINISHED));
  69.         }
  70.         break;
  71.       }
  72.     }
  73.   }
  74.  
  75.   if (finishedMaps > 0) {
  76.     avgMapTime /= finishedMaps;
  77.   }
  78.   if (finishedReduces > 0) {
  79.     avgReduceTime /= finishedReduces;
  80.     avgShuffleTime /= finishedReduces;
  81.   }
  82.   Comparator<JobHistory.Task> cMap = new Comparator<JobHistory.Task>(){
  83.     public int compare(JobHistory.Task t1, JobHistory.Task t2){
  84.       long l1 = t1.getLong(Keys.FINISH_TIME) - t1.getLong(Keys.START_TIME); 
  85.       long l2 = t2.getLong(Keys.FINISH_TIME) - t2.getLong(Keys.START_TIME);
  86.       return (l2<l1 ? -1 : (l2==l1 ? 0 : 1));
  87.     }
  88.   }; 
  89.   Comparator<JobHistory.Task> cShuffle = new Comparator<JobHistory.Task>(){
  90.     public int compare(JobHistory.Task t1, JobHistory.Task t2){
  91.       long l1 = t1.getLong(Keys.SHUFFLE_FINISHED) - 
  92.                 t1.getLong(Keys.START_TIME); 
  93.       long l2 = t2.getLong(Keys.SHUFFLE_FINISHED) - 
  94.                 t2.getLong(Keys.START_TIME); 
  95.       return (l2<l1 ? -1 : (l2==l1 ? 0 : 1));
  96.     }
  97.   }; 
  98.   Arrays.sort(mapTasks, cMap);
  99.   JobHistory.Task minMap = mapTasks[mapTasks.length-1] ;
  100. %>
  101. <h3>Time taken by best performing Map task 
  102. <a href="taskdetailshistory.jsp?jobid=<%=jobid%>&logFile=<%=encodedLogFileName%>&taskid=<%=minMap.get(Keys.TASKID)%>">
  103. <%=minMap.get(Keys.TASKID) %></a> : <%=StringUtils.formatTimeDiff(minMap.getLong(Keys.FINISH_TIME), minMap.getLong(Keys.START_TIME) ) %></h3>
  104. <h3>Average time taken by Map tasks: 
  105. <%=StringUtils.formatTimeDiff(avgMapTime, 0) %></h3>
  106. <h3>Worse performing map tasks</h3>
  107. <table border="2" cellpadding="5" cellspacing="2">
  108. <tr><td>Task Id</td><td>Time taken</td></tr>
  109. <%
  110.   for (int i=0;i<showTasks && i<mapTasks.length; i++) {
  111. %>
  112.     <tr>
  113.     <td><a href="taskdetailshistory.jsp?jobid=<%=jobid%>&logFile=<%=encodedLogFileName%>&taskid=<%=mapTasks[i].get(Keys.TASKID)%>">
  114.         <%=mapTasks[i].get(Keys.TASKID) %></a></td>
  115.     <td><%=StringUtils.formatTimeDiff(mapTasks[i].getLong(Keys.FINISH_TIME), mapTasks[i].getLong(Keys.START_TIME)) %></td>
  116.     </tr>
  117. <%
  118.   }
  119. %>
  120. </table>
  121. <%  
  122.   Comparator<JobHistory.Task> cFinishMapRed = 
  123.     new Comparator<JobHistory.Task>() {
  124.     public int compare(JobHistory.Task t1, JobHistory.Task t2){
  125.       long l1 = t1.getLong(Keys.FINISH_TIME); 
  126.       long l2 = t2.getLong(Keys.FINISH_TIME);
  127.       return (l2<l1 ? -1 : (l2==l1 ? 0 : 1));
  128.     }
  129.   };
  130.   Arrays.sort(mapTasks, cFinishMapRed);
  131.   JobHistory.Task lastMap = mapTasks[0] ;
  132. %>
  133. <h3>The last Map task 
  134. <a href="taskdetailshistory.jsp?jobid=<%=jobid%>&logFile=<%=encodedLogFileName%>
  135. &taskid=<%=lastMap.get(Keys.TASKID)%>"><%=lastMap.get(Keys.TASKID) %></a> 
  136. finished at (relative to the Job launch time): 
  137. <%=StringUtils.getFormattedTimeWithDiff(dateFormat, 
  138.                               lastMap.getLong(Keys.FINISH_TIME), 
  139.                               job.getLong(Keys.LAUNCH_TIME) ) %></h3>
  140. <hr/>
  141. <%
  142.   if (reduceTasks.length <= 0) return;
  143.   Arrays.sort(reduceTasks, cShuffle); 
  144.   JobHistory.Task minShuffle = reduceTasks[reduceTasks.length-1] ;
  145. %>
  146. <h3>Time taken by best performing shuffle
  147. <a href="taskdetailshistory.jsp?jobid=<%=jobid%>&logFile=<%=encodedLogFileName%>
  148. &taskid=<%=minShuffle.get(Keys.TASKID)%>"><%=minShuffle.get(Keys.TASKID)%></a> : 
  149. <%=StringUtils.formatTimeDiff(minShuffle.getLong(Keys.SHUFFLE_FINISHED), 
  150.                               minShuffle.getLong(Keys.START_TIME) ) %></h3>
  151. <h3>Average time taken by Shuffle: 
  152. <%=StringUtils.formatTimeDiff(avgShuffleTime, 0) %></h3>
  153. <h3>Worse performing Shuffle(s)</h3>
  154. <table border="2" cellpadding="5" cellspacing="2">
  155. <tr><td>Task Id</td><td>Time taken</td></tr>
  156. <%
  157.   for (int i=0;i<showTasks && i<reduceTasks.length; i++) {
  158. %>
  159.     <tr>
  160.     <td><a href="taskdetailshistory.jsp?jobid=<%=jobid%>&logFile=
  161. <%=encodedLogFileName%>&taskid=<%=reduceTasks[i].get(Keys.TASKID)%>">
  162. <%=reduceTasks[i].get(Keys.TASKID) %></a></td>
  163.     <td><%=
  164.            StringUtils.formatTimeDiff(
  165.                        reduceTasks[i].getLong(Keys.SHUFFLE_FINISHED),
  166.                        reduceTasks[i].getLong(Keys.START_TIME)) %>
  167.     </td>
  168.     </tr>
  169. <%
  170.   }
  171. %>
  172. </table>
  173. <%  
  174.   Comparator<JobHistory.Task> cFinishShuffle = 
  175.     new Comparator<JobHistory.Task>() {
  176.     public int compare(JobHistory.Task t1, JobHistory.Task t2){
  177.       long l1 = t1.getLong(Keys.SHUFFLE_FINISHED); 
  178.       long l2 = t2.getLong(Keys.SHUFFLE_FINISHED);
  179.       return (l2<l1 ? -1 : (l2==l1 ? 0 : 1));
  180.     }
  181.   };
  182.   Arrays.sort(reduceTasks, cFinishShuffle);
  183.   JobHistory.Task lastShuffle = reduceTasks[0] ;
  184. %>
  185. <h3>The last Shuffle  
  186. <a href="taskdetailshistory.jsp?jobid=<%=jobid%>&logFile=<%=encodedLogFileName%>
  187. &taskid=<%=lastShuffle.get(Keys.TASKID)%>"><%=lastShuffle.get(Keys.TASKID)%>
  188. </a> finished at (relative to the Job launch time): 
  189. <%=StringUtils.getFormattedTimeWithDiff(dateFormat,
  190.                               lastShuffle.getLong(Keys.SHUFFLE_FINISHED), 
  191.                               job.getLong(Keys.LAUNCH_TIME) ) %></h3>
  192. <%
  193.   Comparator<JobHistory.Task> cReduce = new Comparator<JobHistory.Task>(){
  194.     public int compare(JobHistory.Task t1, JobHistory.Task t2){
  195.       long l1 = t1.getLong(Keys.FINISH_TIME) - 
  196.                 t1.getLong(Keys.SHUFFLE_FINISHED); 
  197.       long l2 = t2.getLong(Keys.FINISH_TIME) - 
  198.                 t2.getLong(Keys.SHUFFLE_FINISHED);
  199.       return (l2<l1 ? -1 : (l2==l1 ? 0 : 1));
  200.     }
  201.   }; 
  202.   Arrays.sort(reduceTasks, cReduce); 
  203.   JobHistory.Task minReduce = reduceTasks[reduceTasks.length-1] ;
  204. %>
  205. <hr/>
  206. <h3>Time taken by best performing Reduce task : 
  207. <a href="taskdetailshistory.jsp?jobid=<%=jobid%>&logFile=<%=encodedLogFileName%>&taskid=<%=minReduce.get(Keys.TASKID)%>">
  208. <%=minReduce.get(Keys.TASKID) %></a> : 
  209. <%=StringUtils.formatTimeDiff(minReduce.getLong(Keys.FINISH_TIME),
  210.     minReduce.getLong(Keys.SHUFFLE_FINISHED) ) %></h3>
  211. <h3>Average time taken by Reduce tasks: 
  212. <%=StringUtils.formatTimeDiff(avgReduceTime, 0) %></h3>
  213. <h3>Worse performing reduce tasks</h3>
  214. <table border="2" cellpadding="5" cellspacing="2">
  215. <tr><td>Task Id</td><td>Time taken</td></tr>
  216. <%
  217.   for (int i=0;i<showTasks && i<reduceTasks.length; i++) {
  218. %>
  219.     <tr>
  220.     <td><a href="taskdetailshistory.jsp?jobid=<%=jobid%>&logFile=<%=encodedLogFileName%>&taskid=<%=reduceTasks[i].get(Keys.TASKID)%>">
  221.         <%=reduceTasks[i].get(Keys.TASKID) %></a></td>
  222.     <td><%=StringUtils.formatTimeDiff(
  223.              reduceTasks[i].getLong(Keys.FINISH_TIME), 
  224.              reduceTasks[i].getLong(Keys.SHUFFLE_FINISHED)) %></td>
  225.     </tr>
  226. <%
  227.   }
  228. %>
  229. </table>
  230. <%  
  231.   Arrays.sort(reduceTasks, cFinishMapRed);
  232.   JobHistory.Task lastReduce = reduceTasks[0] ;
  233. %>
  234. <h3>The last Reduce task 
  235. <a href="taskdetailshistory.jsp?jobid=<%=jobid%>&logFile=<%=encodedLogFileName%>
  236. &taskid=<%=lastReduce.get(Keys.TASKID)%>"><%=lastReduce.get(Keys.TASKID)%>
  237. </a> finished at (relative to the Job launch time): 
  238. <%=StringUtils.getFormattedTimeWithDiff(dateFormat,
  239.                               lastReduce.getLong(Keys.FINISH_TIME), 
  240.                               job.getLong(Keys.LAUNCH_TIME) ) %></h3>
  241. </center>
  242. </body></html>