【问题标题】:How can I access the Mapper/Reducer counters on the Output stage?如何访问输出阶段的 Mapper/Reducer 计数器?
【发布时间】:2014-04-03 22:53:01
【问题描述】:

我在 Mapper 课程中创建了一些计数器:

(使用 appengine-mapreduce Java 库 v.0.5 编写的示例)

@Override
public void map(Entity entity) {
    getContext().incrementCounter("analyzed");
    if (isSpecial(entity)){
        getContext().incrementCounter("special");
    }
}

(方法isSpecial只是根据实体的状态返回truefalse,与问题无关)

我想在处理完所有内容后访问这些计数器,在 Output 类的 finish 方法中:

@Override
public Summary finish(Collection<? extends OutputWriter<Entity>> writers) {
    //get the counters and save/return the summary
    int analyzed = 0; //getCounter("analyzed");
    int special = 0; //getCounter("special");
    Summary summary = new Summary(analyzed, special);
    save(summary);
    return summary;
}

...但是getCounter 方法只能从MapperContext 类中使用,该类只能从Mappers/Reducers getContext() 方法中访问。

如何在输出阶段访问我的计数器?

旁注:我无法将计数器值发送到我的输出类,因为整个 Map/Reduce 是将一组实体转换为另一组(换句话说:计数器不是 Map/减少)。计数器仅用于控制 - 我在这里计算它们而不是创建另一个进程只是为了进行计数是有意义的。

谢谢。

【问题讨论】:

    标签: java google-app-engine mapreduce


    【解决方案1】:

    今天没有办法在输出内部执行此操作。但请随时在此处请求: https://code.google.com/p/appengine-mapreduce/issues/list

    但是,您可以做的是链接一个作业以在您的 map-reduce 之后运行,该作业将接收它的输出和计数器。这里有一个例子: https://code.google.com/p/appengine-mapreduce/source/browse/trunk/java/example/src/com/google/appengine/demos/mapreduce/entitycount/ChainedMapReduceJob.java

    在上面的示例中,它连续运行 3 个 MapReduce 作业。请注意,这些不一定是 MapReduce 作业,您可以创建自己的类来扩展 Job 并具有创建 Summary 对象的 run 方法。

    【讨论】:

    猜你喜欢
    • 2016-09-16
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 2016-06-16
    • 1970-01-01
    相关资源
    最近更新 更多