【问题标题】:MapReduce TotalOrderPartitioning writes output to only to one file?MapReduce TotalOrderPartitioning 仅将输出写入一个文件?
【发布时间】:2016-10-18 14:59:48
【问题描述】:

我正在运行一个 mapreduce 作业,它读取输入并使用多个 reduce 对其进行排序。 我能够将输出排序为 5 个减速器。但是,输出仅写入 1 个文件,并且有 4 个空文件。 我正在使用输入采样器和 totalorderpartitioner 进行全局排序。

我的驱动如下:

int numReduceTasks = 5;
    Configuration conf = new Configuration();
    Job job = new Job(conf, "DictionarySorter");
    job.setJarByClass(SampleEMR.class);
    job.setMapperClass(SortMapper.class);
    job.setReducerClass(SortReducer.class);
    job.setPartitionerClass(TotalOrderPartitioner.class);
    job.setNumReduceTasks(numReduceTasks);
    job.setInputFormatClass(TextInputFormat.class);
    job.setOutputFormatClass(TextOutputFormat.class);

    job.setOutputKeyClass(LongWritable.class);
    job.setOutputValueClass(Text.class);


    FileInputFormat.setInputPaths(job, input);
    FileOutputFormat.setOutputPath(job, new Path(output
            + ".dictionary.sorted." + getCurrentDateTime()));
    job.setPartitionerClass(TotalOrderPartitioner.class);

    Path inputDir = new Path("/others/partitions");

    Path partitionFile = new Path(inputDir, "partitioning");
    TotalOrderPartitioner.setPartitionFile(job.getConfiguration(),
            partitionFile);

    double pcnt = 1.0;
    int numSamples = numReduceTasks;
    int maxSplits = numReduceTasks - 1;
    if (0 >= maxSplits)
        maxSplits = Integer.MAX_VALUE;

    InputSampler.Sampler<LongWritable, Text> sampler = new InputSampler.RandomSampler<LongWritable, Text>(pcnt,
            numSamples, maxSplits);
    InputSampler.writePartitionFile(job, sampler);
    job.waitForCompletion(true);

【问题讨论】:

    标签: hadoop totalorderpartitioner


    【解决方案1】:

    您的 RandomSampler 参数对我来说似乎很可疑:

    • 第一个参数freq是概率,不是百分比。对于 pcnt = 1,您正在对 100% 的记录进行抽样。
    • 第二个参数numSamples应该更大。它应该足以代表整个数据集的分布。

    假设您有以下键:4,7,8,9,4,1,2,5,6,3,2,4,7,4,8,1,7,1,8,9, 9,9,9

    使用freq = 0.3numSamples = 10。为简单起见,假设 0.3 表示每 3 个键一个(如果采样)。这将收集以下样本:4,9,2,3,7,1,8,9。这将被排序为 1,2,3,4,7,8,9,9。这个样本有8个元素,所以全部保留,因为没有超过最大样本数numSamples = 10。 在此示例中,您的减速器的边界 将类似于 2、4、8、9。这意味着如果一对有键“1”,它将最终出现在 Reducer #1。带有键“2”的一对将在 Reducer #2 中结束。键为“5”的一对最终会出现在 Reducer #3 中,等等……这将是一个很好的分布。

    现在,如果我们在相同的示例键上运行您的值。您的freq = 1,因此您将每个键都放入示例中。因此,您的样本将与初始键集相同。除了您设置了最大样本数numSamples = 4,这意味着您的样本中只保留了 4 个元素。您的最终样本可能是 9,9,9,9。在这种情况下,你的所有边界都是相同的,所以所有对总是去 Reducer #5。

    在我的示例中,我们很不幸拥有相同的最后 4 个键。但是,如果您的原始数据集已经排序,如果您使用高频率和少量样本,则很可能会发生这种情况(并且边界分布肯定是不好的)。

    blog post 有很多关于采样和 TotalOrderPartitioning 的详细信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-22
      • 1970-01-01
      • 1970-01-01
      • 2012-10-25
      • 1970-01-01
      相关资源
      最近更新 更多