洗牌和排序后的 n-Records 到 reducer

n-Records to reducer after Shuffle and Sort

我只想将 sort/shuffle 后输出的前 10 条记录移动到减速器。这可能吗?

原因是这样的:我要在一个文件中找到数量最多的最少10项。但是,我知道映射阶段的结果将到达已经排序的 reducer。因此,我不想在映射器中排序,而是只想将 'shuffle and sort' 之后的前 10 行传递给缩减器。这将允许 reducer 仅对原始记录的一个子集进行排序。

有什么办法吗?

您可以通过为作业编写自定义 Combiner 来实现。

MapReduce 工作的不同阶段是:

Mapper -> Partitioner -> Sorting -> Combiner -> Reducer.

现在 Combiner 逻辑只读取前 10 (n) 条记录,其他的都不一致。 Reducer 将从每个 Mapper/Combiner.

中仅收到 10 条记录

@K246 提供的评论:

From haodop definitive guide (4th ed) : Before it writes to disk, the thread first divides the data into partitions corresponding to the reducers that they will ultimately be sent to. Within each partition, the background thread performs an in-memory sort by key, and if there is a combiner function, it is run on the output of the sort.

当您在文件中说至少 10 时...是针对每个映射器还是针对整个输入。 如果对于每个映射器,那么您必须再次在所有映射器的 reducer 处聚合。然后正如@YoungHobbit 指出的那样,Combiner 将完成这项工作。

如果你需要从整个输入文件中至少提取 10 个,那么我认为,你需要用一个 reducer 来处理它并相应地输出。

另外,你在最后一行说过,reducer 只会对子集进行排序。您的意思是您在 Reducer 中再次排序,还是在 reducer 中仅针对输入的子集执行某些逻辑。