{
smallestList = mapOutputRecords.size();
}
//first we will develop the job files
TextTable jobTable = new TextTable(smallestList, 11);
//set the headers
jobTable.setHeader(0, "Time");
jobTable.setHeader(1, "Data local map tasks ");
jobTable.setHeader(2, "Map input records ");
jobTable.setHeader(3, "Combine output records");
jobTable.setHeader(4, "Output bytes");
jobTable.setHeader(5, "Input bytes");
jobTable.setHeader(6, "HDFS bytes read");
jobTable.setHeader(7, "Launched map tasks");
jobTable.setHeader(8, "Combine input records");
jobTable.setHeader(9, "Local bytes written");
jobTable.setHeader(10, "Map output records");
TextTable outputTime = new TextTable(smallestList, 2);
outputTime.setHeader(0, "Seconds");
outputTime.setHeader(1, "Map Output bytes/sec");
TextTable inputTime = new TextTable(smallestList, 2);
inputTime.setHeader(0, "Seconds");
inputTime.setHeader(1, "Map Input bytes/sec");
TextTable outputPeak = new TextTable(1,3);
outputPeak.setHeader(0, "Timestamp");
outputPeak.setHeader(1, "Peak Map Output Bytes rate");
outputPeak.setHeader(2, "Sample point (seconds)");
TextTable inputPeak = new TextTable(1,3);
inputPeak.setHeader(0, "Timestamp");
inputPeak.setHeader(1, "Peak Map Input Bytes rate");
inputPeak.setHeader(2, "Sample point (seconds)");
int row = 0;
int counter = jobRecordArray.size();
int peakInputByteRate = 0;
int peakOutputByteRate = 0;
int runPeakOutputByteRate = 0;
int runPeakInputByteRate = 0;
int peakInputSamplePoint = 0;
int peakOutputSamplePoint = 0;
String peakInputTimestamp = null;
String peakOutputTimestamp = null;
//all of these are placed outside of the loop for efficiency
String currentOutputBytes = null;
String previousOutputBytes = null;
String currentInputBytes = null;
String previousInputBytes = null;
String currentOutputRate = null;
String currentInputRate = null;
for(row = 0; row < smallestList;row++)
{
jobTable.setField(row, 0, new String(""+(row +1)*10));//newdateFormat.format(dataLocalMapTasks.get(row).getTimestamp().getTime()));
jobTable.setField(row, 1, dataLocalMapTasks.get(row).getValue());
jobTable.setField(row, 2, mapInputRecords.get(row).getValue());
jobTable.setField(row, 3, combineOutputRecords.get(row).getValue());
jobTable.setField(row, 4, outputBytes.get(row).getValue());
jobTable.setField(row, 5, inputBytes.get(row).getValue());
jobTable.setField(row, 6, hdfsRead.get(row).getValue());
jobTable.setField(row, 7, launchedTasks.get(row).getValue());
jobTable.setField(row, 8, combineInputRecords.get(row).getValue());
jobTable.setField(row, 9, localBytesWritten.get(row).getValue());
jobTable.setField(row, 10, mapOutputRecords.get(row).getValue());
//set the relative time we know the samples are taken at 10 second intervals
outputTime.setField(row, 0, new String(""+(row +1)*10));
inputTime.setField(row, 0, new String(""+(row +1)*10));
if(row > 0)
{
//we do not want to divide by zero or wast time formatting or subtracting the string
if((outputBytes.get(row -1).getValue().compareTo("0") != 0) && (outputBytes.get(row).getValue().compareTo("0") != 0))
{
currentOutputBytes = outputBytes.get(row).getValue();
previousOutputBytes = outputBytes.get(row -1).getValue();
currentInputBytes = inputBytes.get(row).getValue();
previousInputBytes = inputBytes.get(row -1).getValue();
//this is a little confusing but I am dividing the result of the stringSubtraction by 10 which needs to be a String to use
currentOutputRate = stringDivide(stringSubtract(currentOutputBytes, previousOutputBytes), new String(""+10));
currentInputRate = stringDivide(stringSubtract(currentInputBytes, previousInputBytes), new String(""+10));
outputTime.setField(row, 1,currentOutputRate);
inputTime.setField(row, 1, currentInputRate);
if(new Integer(currentOutputRate).intValue() > peakOutputByteRate)
{
peakOutputByteRate = new Integer(currentOutputRate).intValue();
Date timestamp = dataLocalMapTasks.get(row).getTimestamp();
if (timestamp != null)
peakOutputTimestamp = newdateFormat.format(timestamp);
peakOutputSamplePoint = (row +1)*10;
}
if(new Integer(currentInputRate).intValue() > peakInputByteRate)
{
peakInputByteRate = new Integer(currentInputRate).intValue();
Date timestamp = dataLocalMapTasks.get(row).getTimestamp();
if (timestamp != null)
peakInputTimestamp = newdateFormat.format(timestamp);
peakInputSamplePoint = (row +1)*10;
}
}
}else
{
outputTime.setField(row, 1, stringDivide(formatHadoopStringNumber(outputBytes.get(row).getValue()),new String(""+10)));
inputTime.setField(row, 1, stringDivide(formatHadoopStringNumber(inputBytes.get(row).getValue()), new String(""+10)));
}
}
//now configure the peak values tables
inputPeak.setField(0, 0, "N/A");
inputPeak.setField(0, 1, new String("" +peakInputByteRate));
inputPeak.setField(0, 2, new String("" +peakInputSamplePoint));
outputPeak.setField(0, 0, "N/A");
outputPeak.setField(0, 1, new String(""+peakOutputByteRate));
outputPeak.setField(0, 2, new String(""+peakOutputSamplePoint));
//write the file
try
{
//BufferedWriter bfw_metrics = new BufferedWriter(new FileWriter(hadoopConfPath + File.separator + "hadoop-logrecords.properties-"+host));
BufferedWriter bfw_metrics = new BufferedWriter(new FileWriter(RunContext.getOutDir() + "hadoop_metrics_jobRecords.xan."+host));
StringBuffer pageBuffer = new StringBuffer();
StringBuffer timeInputBuffer = new StringBuffer();
StringBuffer timeOutputBuffer = new StringBuffer();
StringBuffer peakInputBuffer= new StringBuffer();
StringBuffer peakOutputBuffer = new StringBuffer();
StringBuffer inputBuffer = new StringBuffer();
StringBuffer outputBuffer = new StringBuffer();
StringBuffer heading = new StringBuffer();
heading.append("Title:" + "Hadoop JobRecord Metric Results");
heading.append("\n");
pageBuffer.append("\n");
pageBuffer.append("\n");
pageBuffer.append("Section:" + "Hadoop JobRecord Metric");
pageBuffer.append("\n");
inputBuffer.append("\n");
inputBuffer.append("\n");
inputBuffer.append("Section: Map Input bytes/sec\n");
inputBuffer.append("Display: Line\n");
outputBuffer.append("\n");
outputBuffer.append("\n");
outputBuffer.append("Section: Map Output bytes/sec\n");
outputBuffer.append("Display: Line\n");
peakInputBuffer.append("\n");
peakInputBuffer.append("\n");
peakInputBuffer.append("Section: Peak Map Input Bytes rate\n");
//peakInputBuffer.append("Display: Line\n");
peakOutputBuffer.append("\n");
peakOutputBuffer.append("\n");
peakOutputBuffer.append("Section: Peak Map Output Bytes rate\n");
//peakOutputBuffer.append("Display: Line\n");
bfw_metrics.write(heading.toString());
bfw_metrics.write(inputBuffer.toString());
bfw_metrics.write(inputTime.format(timeInputBuffer).toString());
bfw_metrics.write(outputBuffer.toString());
bfw_metrics.write(outputTime.format(timeOutputBuffer).toString());
bfw_metrics.write(inputPeak.format(peakInputBuffer).toString());
bfw_metrics.write(outputPeak.format(peakOutputBuffer).toString());
bfw_metrics.write(jobTable.format(pageBuffer).toString());
bfw_metrics.close();
bfw_metrics = null;
logger.info("File written " + RunContext.getOutDir() + "hadoop_metrics_jobRecords." +host);
}catch(IOException ioe)
{
logger.warning("Could not create logrecords output file (hadoop_metrics_jobRecords) in generateTableFromMetrics" + ioe.getMessage());
}
}else
{
logger.warning("jobArray was empty or null in GridMix.generateTableFromMetrics()");
}
if((jobTrackerArray != null)&&(jobTrackerArray.size() > 0))
{
for(Iterator<AbstractLogRecord> it = jobTrackerArray.iterator(); it.hasNext();)
{
JobtrackerRecord jr = (JobtrackerRecord)it.next();
jobRecordTrackerArray.add(jr);
}
//next we will develop the jobTracker file
TextTable jobTrackerTable = new TextTable(jobRecordTrackerArray.size(), 5);
//set the headers
jobTrackerTable.setHeader(0, "Time");
jobTrackerTable.setHeader(1, "Maps launched");
jobTrackerTable.setHeader(2, "Maps finished");
jobTrackerTable.setHeader(3, "Reducers launched");
jobTrackerTable.setHeader(4, "Reducers finished");
TextTable mapLaunched = new TextTable(jobRecordTrackerArray.size(),2);
mapLaunched.setHeader(0, "Relative Time");
mapLaunched.setHeader(1, "Maps Launched/sec");
TextTable mapFinished = new TextTable(jobRecordTrackerArray.size(),2);
mapFinished.setHeader(0, "Relative Time");
mapFinished.setHeader(1, "Maps Finished/sec");
for(int row = 0; row < jobRecordTrackerArray.size();row++)
{
jobTrackerTable.setField(row, 0, "N/A");
jobTrackerTable.setField(row, 1, jobRecordTrackerArray.get(row).getMaps_launched());
jobTrackerTable.setField(row, 2, jobRecordTrackerArray.get(row).getMaps_completed());
jobTrackerTable.setField(row, 3, jobRecordTrackerArray.get(row).getReduces_launched());
jobTrackerTable.setField(row, 4, jobRecordTrackerArray.get(row).getReduces_completed());
//set the relative time we know the samples are taken at 10 second intervals
mapLaunched.setField(row, 0, new String(""+((row +1)*10)));
mapFinished.setField(row,0, new String(""+((row +1)*10)));
if(row > 0)
{
//outputTime.setField(row, 1,stringSubtract(outputBytes.get(row).getValue(), outputBytes.get(row -1).getValue()) );
mapLaunched.setField(row, 1, stringSubtract(jobRecordTrackerArray.get(row).getMaps_launched(), jobRecordTrackerArray.get(row -1).getMaps_launched()));
mapFinished.setField(row, 1, stringSubtract(jobRecordTrackerArray.get(row).getMaps_completed(), jobRecordTrackerArray.get(row -1).getMaps_completed()));
//mapFinished.setField(row, 1, jobTracker.getMaps_completed());
}else
{
mapLaunched.setField(row, 1, jobRecordTrackerArray.get(row).getMaps_launched());
mapFinished.setField(row, 1, jobRecordTrackerArray.get(row).getMaps_completed());
}
}
//write the file
try
{
BufferedWriter bfw_metrics = new BufferedWriter(new FileWriter(RunContext.getOutDir() + "hadoop_metrics_jobTrackerRecords.xan."+host));
StringBuffer sb = new StringBuffer();
StringBuffer sbl = new StringBuffer();
StringBuffer sbf = new StringBuffer();
StringBuffer launched = new StringBuffer();
StringBuffer finished = new StringBuffer();
StringBuffer heading = new StringBuffer();
heading.append("Title:" + "Hadoop JobTrackerRecord Metric Results");
sb.append("\n");
sb.append("\n");
sb.append("Section: JobTrackerRecord Metrics\n");
launched.append("\n");
launched.append("\n");
launched.append("Section: Launched Map Metrics\n");
launched.append("Display: Line\n");
finished.append("\n");
finished.append("\n");
finished.append("Section: Finished Map Metrics\n");
finished.append("Display: Line\n");
bfw_metrics.write(heading.toString());
bfw_metrics.write(launched.toString());
bfw_metrics.write(mapLaunched.format(sbl).toString());
bfw_metrics.write(finished.toString());
bfw_metrics.write(mapFinished.format(sbf).toString());
bfw_metrics.write(jobTrackerTable.format(sb).toString());
bfw_metrics.close();
bfw_metrics = null;
logger.info("File written " + RunContext.getOutDir() + "hadoop_metrics_jobTrackerRecords." +host);
}catch(IOException ioe)
{
logger.warning("Could not create logrecords output file (hadoop_metrics_jobTrackerRecords) in generateTableFromMetrics" + ioe.getMessage());
}
}else
{
logger.warning("jobTrackerArray was empty or null in GridMix.generateTableFromMetrics()");
}
if((shuffleInputArray != null) && (shuffleInputArray.size() > 0))
{
for(Iterator<AbstractLogRecord> it = shuffleInputArray.iterator(); it.hasNext();)
{
ShuffleInputRecord jr = (ShuffleInputRecord)it.next();
shuffleInputRecordArray.add(jr);
}
//next we will develop the jobTracker file
TextTable shuffleInputTable = new TextTable(shuffleInputArray.size(), 5);
//set the headers
shuffleInputTable.setHeader(0, "Relative Time");
shuffleInputTable.setHeader(1, "Shuffle failed fetches");
shuffleInputTable.setHeader(2, "Shuffle fetchers busy percent");
shuffleInputTable.setHeader(3, "Shuffle input bytes");
shuffleInputTable.setHeader(4, "Shuffle success fetches");
TextTable failed = new TextTable(shuffleInputArray.size(), 2);
failed.setHeader(0, "Relative Time");
failed.setHeader(1, "Failed fetches");
TextTable busy = new TextTable(shuffleInputArray.size(), 2);
busy.setHeader(0, "Relative Time");
busy.setHeader(1, "Fetches % Busy");
TextTable input = new TextTable(shuffleInputArray.size(), 2);
input.setHeader(0, "Relative Time");
input.setHeader(1, "Input Bytes/sec");
TextTable success = new TextTable(shuffleInputArray.size(), 2);
success.setHeader(0, "Relative Time");
success.setHeader(1, "Success fetches");
String currentValue;
String previousValue;
for(int row = 0; row < shuffleInputRecordArray.size();row++)
{
shuffleInputTable.setField(row, 0, new String(""+((row +1)*10)));
shuffleInputTable.setField(row, 1, shuffleInputRecordArray.get(row).getShuffle_failed_fetches());
shuffleInputTable.setField(row, 2, shuffleInputRecordArray.get(row).getShuffle_fetchers_busy_percent());
shuffleInputTable.setField(row, 3, shuffleInputRecordArray.get(row).getShuffle_input_bytes());
shuffleInputTable.setField(row, 4, shuffleInputRecordArray.get(row).getShuffle_success_fetches());
failed.setField(row, 0, new String(""+((row +1)*10)));
failed.setField(row, 1, shuffleInputRecordArray.get(row).getShuffle_failed_fetches());
busy.setField(row, 0, new String(""+((row +1)*10)));
busy.setField(row, 1, shuffleInputRecordArray.get(row).getShuffle_fetchers_busy_percent());
input.setField(row, 0, new String(""+((row +1)*10)));
if(row != 0)
{
currentValue = shuffleInputRecordArray.get(row).getShuffle_input_bytes();
previousValue = shuffleInputRecordArray.get(row - 1).getShuffle_input_bytes();
input.setField(row, 1, stringDivide(stringSubtract(currentValue, previousValue), new String(""+10)));
}else
{
input.setField(row, 1, stringDivide(shuffleInputRecordArray.get(row).getShuffle_input_bytes(), new String(""+10)));
}
success.setField(row, 0, new String(""+((row +1)*10)));
success.setField(row, 1, shuffleInputRecordArray.get(row).getShuffle_success_fetches());
currentValue = null;
previousValue = null;
}
//write the file
try
{
BufferedWriter bfw_metrics = new BufferedWriter(new FileWriter(RunContext.getOutDir() + "hadoop_metrics_shuffleInputRecords.xan."+host));
StringBuffer sb = new StringBuffer();
StringBuffer sbf = new StringBuffer();
StringBuffer sbb = new StringBuffer();
StringBuffer sbi = new StringBuffer();
StringBuffer sbs = new StringBuffer();
StringBuffer failedsb = new StringBuffer();
StringBuffer busysb = new StringBuffer();
StringBuffer inputsb = new StringBuffer();
StringBuffer successdb = new StringBuffer();
StringBuffer heading = new StringBuffer();
heading.append("Title:" + "Hadoop ShuffleInput Metric Results");
sb.append("\n");
sb.append("\n");
sb.append("Section: Hadoop ShuffleInput Metric Data\n");
failedsb.append("\n");
failedsb.append("\n");
failedsb.append("Section: Hadoop ShuffleInput Failed Data\n");
failedsb.append("Display: Line\n");
busysb.append("\n");
busysb.append("\n");
busysb.append("Section: Hadoop ShuffleInput Busy Data\n");
busysb.append("Display: Line\n");
inputsb.append("\n");
inputsb.append("\n");
inputsb.append("Section: Hadoop ShuffleInput Input Data\n");
inputsb.append("Display: Line\n");
successdb.append("\n");
successdb.append("\n");
successdb.append("Section: Hadoop ShuffleInput Successful Fetches Data\n");
successdb.append("Display: Line\n");
bfw_metrics.write(heading.toString());
bfw_metrics.write(failedsb.toString());
bfw_metrics.write(failed.format(sbf).toString());
bfw_metrics.write(inputsb.toString());
bfw_metrics.write(input.format(sbi).toString());
bfw_metrics.write(busysb.toString());
bfw_metrics.write(busy.format(sbb).toString());
bfw_metrics.write(successdb.toString());
bfw_metrics.write(success.format(sbs).toString());
bfw_metrics.write(shuffleInputTable.format(sb).toString());
bfw_metrics.close();
bfw_metrics = null;
logger.info("File written " + RunContext.getOutDir() + "hadoop_metrics_shuffleInputRecords." +host);
}catch(IOException ioe)
{
logger.warning("Could not create logrecords output file (hadoop_metrics_shuffleInputRecords) in generateTableFromMetrics" + ioe.getMessage());
}
}else
{
logger.warning("shuffleInputArray was empty or null in GridMix.generateTableFromMetrics()");
}
if((shuffleOutputArray != null) && (shuffleOutputArray.size() > 0))
{
for(Iterator<AbstractLogRecord> it = shuffleOutputArray.iterator(); it.hasNext();)
{
ShuffleOutputRecord jr = (ShuffleOutputRecord)it.next();
shuffleOutputRecordArray.add(jr);
}
//next we will develop the jobTracker file
TextTable shufflePutputTable = new TextTable(shuffleOutputArray.size(), 5);
//set the headers
shufflePutputTable.setHeader(0, "Relative Time");
shufflePutputTable.setHeader(1, "Shuffle failed outputs");
shufflePutputTable.setHeader(2, "Shuffle handler busy percent");
shufflePutputTable.setHeader(3, "Shuffle output bytes");
shufflePutputTable.setHeader(4, "Shuffle_success_outputs");
TextTable failed = new TextTable(shuffleOutputArray.size(), 2);
failed.setHeader(0, "Relative Time");
failed.setHeader(1, "Shuffle failed outputs");
TextTable busy = new TextTable(shuffleOutputArray.size(), 2);
busy.setHeader(0, "Relative Time");
busy.setHeader(1, "Shuffle handler % busy");
TextTable output = new TextTable(shuffleOutputArray.size(), 2);
output.setHeader(0, "Relative Time");
output.setHeader(1, "Shuffle output bytes/sec");
TextTable success = new TextTable(shuffleOutputArray.size(), 2);
success.setHeader(0, "Relative Time");
success.setHeader(1, "Shuffle_success_outputs");
for(int row = 0; row < shuffleOutputRecordArray.size(); row++)
{
shufflePutputTable.setField(row, 0, new String(""+((row +1)*10)));
shufflePutputTable.setField(row, 1, shuffleOutputRecordArray.get(row).getShuffle_failed_outputs());
shufflePutputTable.setField(row, 2, shuffleOutputRecordArray.get(row).getShuffle_handler_busy_percent());
shufflePutputTable.setField(row, 3, shuffleOutputRecordArray.get(row).getShuffle_output_bytes());
shufflePutputTable.setField(row, 4, shuffleOutputRecordArray.get(row).getShuffle_success_outputs());
failed.setField(row, 0, new String(""+((row +1)*10)));
busy.setField(row, 0, new String(""+((row +1)*10)));
output.setField(row, 0, new String(""+((row +1)*10)));
success.setField(row, 0, new String(""+((row +1)*10)));
failed.setField(row, 1, shuffleOutputRecordArray.get(row).getShuffle_failed_outputs());
busy.setField(row, 1, shuffleOutputRecordArray.get(row).getShuffle_handler_busy_percent());
if(row != 0)
{
output.setField(row, 1, shuffleOutputRecordArray.get(row).getShuffle_output_bytes());
}else
{
output.setField(row, 1, shuffleOutputRecordArray.get(row).getShuffle_output_bytes());
}
success.setField(row, 1, shuffleOutputRecordArray.get(row).getShuffle_success_outputs());
}
//write the file
try
{
BufferedWriter bfw_metrics = new BufferedWriter(new FileWriter(RunContext.getOutDir() + "hadoop_metrics_shuffleOutputRecords.xan."+host));
StringBuffer sb = new StringBuffer();
StringBuffer sbf = new StringBuffer();
StringBuffer sbb = new StringBuffer();
StringBuffer sbo = new StringBuffer();
StringBuffer sbs = new StringBuffer();
StringBuffer failed_sb = new StringBuffer();
StringBuffer busy_sb = new StringBuffer();
StringBuffer output_sb = new StringBuffer();
StringBuffer success_sb = new StringBuffer();
StringBuffer heading = new StringBuffer();
heading.append("Title:" + "Hadoop ShuffleOutput Metric Results");
sb.append("\n");
sb.append("\n");
sb.append("Section: ShuffleOutput Metrics\n");
failed_sb.append("\n");
failed_sb.append("\n");
failed_sb.append("Section: ShuffleOutput Failed Metrics\n");
failed_sb.append("Display: Line\n");
busy_sb.append("\n");
busy_sb.append("\n");
busy_sb.append("Section: ShuffleOutput % Busy Metrics\n");
busy_sb.append("Display: Line\n");
output_sb.append("\n");
output_sb.append("\n");
output_sb.append("Section: ShuffleOutput Output Metrics\n");
output_sb.append("Display: Line\n");
success_sb.append("\n");
success_sb.append("\n");
success_sb.append("Section: ShuffleOutput Successful Shuffle Metrics\n");
success_sb.append("Display: Line\n");
bfw_metrics.write(heading.toString());
bfw_metrics.write(failed_sb.toString());
bfw_metrics.write(failed.format(sbf).toString());
bfw_metrics.write(busy_sb.toString());
bfw_metrics.write(busy.format(sbb).toString());
bfw_metrics.write(output_sb.toString());
bfw_metrics.write(output.format(sbo).toString());
bfw_metrics.write(success_sb.toString());
bfw_metrics.write(success.format(sbs).toString());
bfw_metrics.write(shufflePutputTable.format(sb).toString());
bfw_metrics.close();
bfw_metrics = null;