{
try
{
long start = System.currentTimeMillis();
//计算并输出
JobTaskResult jobTaskResult = statisticsEngine.doAnalysis(jobTasks.get(0));
jobTaskResult.setEfficiency((System.currentTimeMillis() - timer + hardWorkTimer.get())
/(System.currentTimeMillis() - nodeStartTimeStamp));
if (logger.isInfoEnabled())
logger.info("analysis task:" + jobTasks.get(0).getTaskId() + ","
+ jobTasks.get(0).getInput() + " uses:" + (System.currentTimeMillis() - start));
start = System.currentTimeMillis();
if (jobTaskResult != null)
{
handleTaskResult(jobTasks.get(0),jobTaskResult);
}
if (logger.isInfoEnabled())
logger.info("send result task:" + jobTasks.get(0).getTaskId() + ","
+ jobTasks.get(0).getInput() + " uses:" + (System.currentTimeMillis() - start));
doingTasks.remove(jobTasks.get(0).getTaskId() + "_" + jobTasks.get(0).getJobEpoch());
}
catch (Exception e) {
logger.error("SlaveNode send result error." + jobTasks.get(0).getJobName(),e);
}
}
else
{
final CountDownLatch taskCountDownLatch = new CountDownLatch(jobTasks.size());
final List<JobTaskResult> taskResults = new ArrayList<JobTaskResult>();
//同一个Job的多个Task并行执行
for(final JobTask jobtask : jobTasks)
{
final JobTask j = jobtask;
analysisWorkerThreadPool.execute(
new Runnable()
{
public void run()
{
try
{
taskResults.add(statisticsEngine.doAnalysis(j));
}
catch (Exception e)
{
logger.error("analysis error : " + jobtask.getJobName(), e);
}
finally
{
taskCountDownLatch.countDown();
}
}
}
);
}
try
{
if (!taskCountDownLatch.await(config.getMaxTaskProcessTime(),TimeUnit.SECONDS)) {
StringBuilder sb = new StringBuilder("task analysis timeout !tasks:{");
for(JobTask task : jobTasks) {
sb.append(task.getTaskId()).append(",").append(task.getInput()).append(";");
}
sb.append("}");
logger.error(sb.toString());
}
}
catch (InterruptedException e) {
//do nothing
}
long start = System.currentTimeMillis();
//合并分析结果
JobTaskResult jobTaskResult = jobResultMerger.merge(jobTasks.get(0), taskResults,false,false);
// 统计merge, 这里的时间并不科学, 应用线程并发, 时间可能被多计算了
monitor.mergedTask(System.currentTimeMillis() - start, taskResults.size());
jobTaskResult.setEfficiency((System.currentTimeMillis() - timer + hardWorkTimer.get())
/(System.currentTimeMillis() - nodeStartTimeStamp));
if (logger.isInfoEnabled())
logger.info("merge result task:" + jobTasks.get(0).getTaskId() + ","
+ jobTasks.get(0).getInput() + "," + taskResults.size() + ",uses:" + (System.currentTimeMillis() - start));