當前位置: 首頁>>代碼示例>>Java>>正文


Java MapOutputCollector類代碼示例

本文整理匯總了Java中org.apache.hadoop.mapred.MapOutputCollector的典型用法代碼示例。如果您正苦於以下問題:Java MapOutputCollector類的具體用法?Java MapOutputCollector怎麽用?Java MapOutputCollector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MapOutputCollector類屬於org.apache.hadoop.mapred包,在下文中一共展示了MapOutputCollector類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: collectRecords

import org.apache.hadoop.mapred.MapOutputCollector; //導入依賴的package包/類
/**
 * Collect a bunch of random terasort-like records into the map output
 * collector.
 */
@SuppressWarnings("unchecked")
private void collectRecords(MapOutputCollector collector)
    throws IOException, InterruptedException {
  // Use a consistent random seed so that different implementations are
  // sorting the exact same data.
  XorshiftRandom r = new XorshiftRandom(1);

  // The 10-90 key-value split is the same as terasort.
  BytesWritable key = new BytesWritable();
  key.setSize(10);
  BytesWritable val = new BytesWritable();
  val.setSize(90);
  r.nextBytes(val.getBytes());

  byte[] keyBytes = key.getBytes();

  for (int i = 0; i < NUM_RECORDS; i++) {
    int partition = i % NUM_PARTITIONS;
    r.nextBytes(keyBytes);
    collector.collect(key, val, partition);
  }
}
 
開發者ID:toddlipcon,項目名稱:mr-collector-benchmark,代碼行數:27,代碼來源:MapOutputCollectorBenchmark.java

示例2: runTest

import org.apache.hadoop.mapred.MapOutputCollector; //導入依賴的package包/類
public void runTest(Class<? extends MapOutputCollector> collector) throws Exception {
  for (int i = 0; i < 30; i++) {
    // GC a few times first so we're really just testing the collection, nothing else.
    System.gc();
    System.gc();
    System.gc();
    doBenchmark(collector);
  }
}
 
開發者ID:toddlipcon,項目名稱:mr-collector-benchmark,代碼行數:10,代碼來源:MapOutputCollectorBenchmark.java

示例3: main

import org.apache.hadoop.mapred.MapOutputCollector; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
  Preconditions.checkArgument(args.length == 1,
      "Usage: " + MapOutputCollectorBenchmark.class.getName() +
      " <collector class name>");
  Class<?> clazz = Class.forName(args[0]);
  Class<? extends MapOutputCollector> collectorClazz =
      clazz.asSubclass(MapOutputCollector.class);
  new MapOutputCollectorBenchmark().runTest(collectorClazz);
}
 
開發者ID:toddlipcon,項目名稱:mr-collector-benchmark,代碼行數:10,代碼來源:MapOutputCollectorBenchmark.java

示例4: doBenchmark

import org.apache.hadoop.mapred.MapOutputCollector; //導入依賴的package包/類
private void doBenchmark(Class<? extends MapOutputCollector> collectorClazz)
  throws Exception {
  JobConf jobConf = new JobConf();
  jobConf.setInt("io.sort.mb", 600);
  jobConf.setInt("io.file.buffer.size", 128*1024);
  jobConf.setMapOutputKeyClass(BytesWritable.class);
  jobConf.setMapOutputValueClass(BytesWritable.class);
  jobConf.setNumReduceTasks(NUM_PARTITIONS);
  jobConf.set(JobContext.TASK_ATTEMPT_ID, "test_attempt");
  
  // Fake out a bunch of stuff to make a task context.
  MapOutputFile output = new YarnOutputFiles();
  output.setConf(jobConf);

  Progress mapProgress = new Progress();
  mapProgress.addPhase("map");
  mapProgress.addPhase("sort");

  MapTask mapTask = Mockito.mock(MapTask.class);
  Mockito.doReturn(output).when(mapTask).getMapOutputFile();
  Mockito.doReturn(true).when(mapTask).isMapTask();
  Mockito.doReturn(new TaskAttemptID("fake-jt", 12345, TaskType.MAP, 1, 1)).when(mapTask).getTaskID();
  Mockito.doReturn(mapProgress).when(mapTask).getSortPhase();
  
  MapTask t = new MapTask();
  Constructor<TaskReporter> constructor =
      TaskReporter.class.getDeclaredConstructor(Task.class,
          Progress.class, TaskUmbilicalProtocol.class);
  constructor.setAccessible(true);
  TaskReporter reporter = constructor.newInstance(t, mapProgress, null);
  reporter.setProgress(0.0f);
  Context context = new MapOutputCollector.Context(mapTask, jobConf, reporter);

  // Actually run the map sort.
  ResourceTimer timer = new ResourceTimer();
  MapOutputCollector<?,?> collector = ReflectionUtils.newInstance(collectorClazz, jobConf);
  collector.init(context);
  collectRecords(collector);
  collector.flush();
  collector.close();

  // Print results
  System.out.println("---------------------");
  System.out.println("Results for " + collectorClazz.getName() + ":");
  System.out.println("CPU time: " + timer.elapsedCpu() + "ms");
  System.out.println("CPU time (only this thread): " + timer.elapsedCpuThisThread() + "ms");
  System.out.println("Compilation time: " + timer.elapsedCompilation());
  System.out.println("GC time: " + timer.elapsedGC());
  System.out.println("Wall time: " + timer.elapsedWall());
  System.out.println("---------------------");
}
 
開發者ID:toddlipcon,項目名稱:mr-collector-benchmark,代碼行數:52,代碼來源:MapOutputCollectorBenchmark.java


注:本文中的org.apache.hadoop.mapred.MapOutputCollector類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。