当前位置: 首页>>代码示例>>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;未经允许,请勿转载。