Package org.apache.hadoop.mapred.TaskTracker

Examples of org.apache.hadoop.mapred.TaskTracker.ShuffleServerMetrics


  protected ChannelFuture sendMapOutput(ChannelHandlerContext ctx, Channel ch,
      String jobId, String mapId, int reduce) throws IOException {
    LocalDirAllocator lDirAlloc = attributes.getLocalDirAllocator();
    FileSystem rfs = ((LocalFileSystem) attributes.getLocalFS()).getRaw();

    ShuffleServerMetrics shuffleMetrics = attributes.getShuffleServerMetrics();
    TaskTracker tracker = attributes.getTaskTracker();

    // Index file
    Path indexFileName = lDirAlloc.getLocalPathToRead(
        TaskTracker.getIntermediateOutputDir(jobId, mapId)
        + "/file.out.index", attributes.getJobConf());
    // Map-output file
    Path mapOutputFileName = lDirAlloc.getLocalPathToRead(
        TaskTracker.getIntermediateOutputDir(jobId, mapId)
        + "/file.out", attributes.getJobConf());

    /**
     * Read the index file to get the information about where
     * the map-output for the given reducer is available.
     */
    IndexRecord info = tracker.getIndexInformation(mapId, reduce,indexFileName);

    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);

    //set the custom "from-map-task" http header to the map task from which
    //the map output data is being transferred
    response.setHeader(MRConstants.FROM_MAP_TASK, mapId);

    //set the custom "Raw-Map-Output-Length" http header to
    //the raw (decompressed) length
    response.setHeader(MRConstants.RAW_MAP_OUTPUT_LENGTH,
        Long.toString(info.rawLength));

    //set the custom "Map-Output-Length" http header to
    //the actual number of bytes being transferred
    response.setHeader(MRConstants.MAP_OUTPUT_LENGTH,
        Long.toString(info.partLength));

    //set the custom "for-reduce-task" http header to the reduce task number
    //for which this map output is being transferred
    response.setHeader(MRConstants.FOR_REDUCE_TASK, Integer.toString(reduce));

    ch.write(response);
    File spillfile = new File(mapOutputFileName.toString());
    RandomAccessFile spill;
    try {
      spill = new RandomAccessFile(spillfile, "r");
    } catch (FileNotFoundException e) {
      LOG.info(spillfile + " not found");
      return null;
    }
    final FileRegion partition = new DefaultFileRegion(
      spill.getChannel(), info.startOffset, info.partLength);
    ChannelFuture writeFuture = ch.write(partition);
    writeFuture.addListener(new ChanneFutureListenerMetrics(partition));
    shuffleMetrics.outputBytes(info.partLength); // optimistic
    LOG.info("Sending out " + info.partLength + " bytes for reduce: " +
             reduce + " from map: " + mapId + " given " +
             info.partLength + "/" + info.rawLength);
    return writeFuture;
  }
View Full Code Here


    factory.setAttribute("mapred.class",
        "org.apache.hadoop.metrics.spi.NoEmitMetricsContext");

    TaskTracker tt = new TaskTracker();
    tt.setConf(conf);
    ShuffleServerMetrics shuffleMetrics = tt.new ShuffleServerMetrics(conf);

    // first test with only MsgRegex set but doesn't match
    String exceptionMsgRegex = "Broken pipe";
    String exceptionStackRegex = null;
    IOException ie = new IOException("EOFException");
    testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
        shuffleMetrics);

    MetricsContext context = factory.getContext("mapred");
    shuffleMetrics.doUpdates(context);
    Map<String, Collection<OutputRecord>> records = context.getAllRecords();
    Collection<OutputRecord> col = records.get("shuffleOutput");
    OutputRecord outputRecord = col.iterator().next();
    assertEquals(0, outputRecord.getMetric("shuffle_exceptions_caught")
        .intValue());

    // test with only MsgRegex set that does match
    ie = new IOException("Broken pipe");
    testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
        shuffleMetrics);

    shuffleMetrics.doUpdates(context);
    assertEquals(1, outputRecord.getMetric("shuffle_exceptions_caught")
        .intValue());

    // test with neither set, make sure incremented
    exceptionStackRegex = null;
    exceptionMsgRegex = null;
    testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
        shuffleMetrics);
    shuffleMetrics.doUpdates(context);
    assertEquals(2, outputRecord.getMetric("shuffle_exceptions_caught")
        .intValue());

    // test with only StackRegex set doesn't match
    exceptionStackRegex = ".*\\.doesnt\\$SelectSet\\.wakeup.*";
    exceptionMsgRegex = null;
    ie.setStackTrace(constructStackTrace());
    testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
        shuffleMetrics);
    shuffleMetrics.doUpdates(context);
    assertEquals(2, outputRecord.getMetric("shuffle_exceptions_caught")
        .intValue());

    // test with only StackRegex set does match
    exceptionStackRegex = ".*\\.SelectorManager\\$SelectSet\\.wakeup.*";
    testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
        shuffleMetrics);
    shuffleMetrics.doUpdates(context);
    assertEquals(3, outputRecord.getMetric("shuffle_exceptions_caught")
        .intValue());

    // test with both regex set and matches
    exceptionMsgRegex = "Broken pipe";
    ie.setStackTrace(constructStackTraceTwo());
    testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
        shuffleMetrics);
    shuffleMetrics.doUpdates(context);
    assertEquals(4, outputRecord.getMetric("shuffle_exceptions_caught")
        .intValue());

    // test with both regex set and only msg matches
    exceptionStackRegex = ".*[1-9]+BOGUSREGEX";
    testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
        shuffleMetrics);
    shuffleMetrics.doUpdates(context);
    assertEquals(4, outputRecord.getMetric("shuffle_exceptions_caught")
        .intValue());

    // test with both regex set and only stack matches
    exceptionStackRegex = ".*\\.SelectorManager\\$SelectSet\\.wakeup.*";
    exceptionMsgRegex = "EOFException";
    testServlet.checkException(ie, exceptionMsgRegex, exceptionStackRegex,
        shuffleMetrics);
    shuffleMetrics.doUpdates(context);
    assertEquals(4, outputRecord.getMetric("shuffle_exceptions_caught")
        .intValue());
  }
View Full Code Here

  }

  protected ChannelFuture sendMapOutput(ChannelHandlerContext ctx, Channel ch,
      String jobId, String mapId, int reduce) throws IOException {
    LocalDirAllocator lDirAlloc = attributes.getLocalDirAllocator();
    ShuffleServerMetrics shuffleMetrics = attributes.getShuffleServerMetrics();
    TaskTracker tracker = attributes.getTaskTracker();
    boolean found = true;

    Path indexFileName = null;
    Path mapOutputFileName = null;
    try {
    // Index file
    indexFileName = lDirAlloc.getLocalPathToRead(
        TaskTracker.getIntermediateOutputDir(jobId, mapId)
        + "/file.out.index", attributes.getJobConf());
    // Map-output file
    mapOutputFileName = lDirAlloc.getLocalPathToRead(
        TaskTracker.getIntermediateOutputDir(jobId, mapId)
        + "/file.out", attributes.getJobConf());
    } catch (DiskChecker.DiskErrorException e) {
      LOG.error("sendMapOutput: Failed to retrieve index or map output " +
          "file, will send ShuffleHeader noting the file can't be found.",
          e);
      found = false;
    }

    /**
     * Read the index file to get the information about where
     * the map-output for the given reducer is available.
     */
    IndexRecord info = null;
    try {
      info = tracker.getIndexInformation(mapId, reduce, indexFileName);
    } catch (IOException e) {
      LOG.error("sendMapOutput: Failed to get the index information, " +
          "will send ShuffleHeader noting that the file can't be found.", e);
      found = false;
      info = new IndexRecord(-1, 0, 0);
    }

    RandomAccessFile spill = null;
    if (mapOutputFileName != null) {
      File spillfile = new File(mapOutputFileName.toString());
      try {
        spill = new RandomAccessFile(spillfile, "r");
      } catch (FileNotFoundException e) {
        LOG.error("sendMapOutput: " + spillfile + " not found, " +
            "will send ShuffleHeader noting that the file can't be found.", e);
        found = false;
      }
    }

    final ShuffleHeader header =
        new ShuffleHeader(mapId, info.partLength, info.rawLength, reduce,
            found);
    final DataOutputBuffer dob = new DataOutputBuffer();
    header.write(dob);
    ChannelFuture writeFuture =
        ch.write(wrappedBuffer(dob.getData(), 0, dob.getLength()));
    // Exit early if we didn't find the spill file.
    if (found == false || spill == null) {
      attributes.getTaskTracker().mapOutputLost(
          TaskAttemptID.forName(mapId),
          "sendMapOutput: Couldn't get mapId = " + mapId + ", reduce " +
              reduce);
      return writeFuture;
    }

    final FileRegion partition = new DefaultFileRegion(
      spill.getChannel(), info.startOffset, info.partLength);
    writeFuture = ch.write(partition);
    writeFuture.addListener(new ChanneFutureListenerMetrics(partition));
    shuffleMetrics.outputBytes(info.partLength); // optimistic
    LOG.info("Sending out " + info.partLength + " bytes for reduce: " +
             reduce + " from map: " + mapId + " given " +
             info.partLength + "/" + info.rawLength);
    return writeFuture;
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.mapred.TaskTracker.ShuffleServerMetrics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.