2014-03-03 23 views
2

我有一些櫃檯我在映射類創建:如何訪問輸出階段的Mapper/Reducer計數器?

(例如,使用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類,它只能訪問從映射器/減速器getContext()方法。

如何在輸出階段訪問我的計數器?

備註:我無法將計數器值發送到我輸出的類,因爲整個Map/Reduce是將一組實體轉換爲另一個實體(換句話說:計數器不是地圖的主要用途/減少)。計數器只是爲了控制 - 這是有道理的,我在這裏計算它們,而不是創建另一個進程來計算。

謝謝。

回答

0

今天在輸出內部沒有辦法做到這一點。但是請隨時在這裏請求它: 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方法。

+0

你去了哪裏,創建了問題:https://code.google.com/p/appengine-mapreduce/issues/detail?id=208 –