IT/빅데이터(bigData)
Reduce 에서 counter 조회
까딱이(micropai)
2014. 11. 22. 04:34
mapreduce 프로그래밍을 하면 counter가 필요한 곳은 대부분 reducer 이다
counter 는 job 안에 존재하며,
reducer의 context 가 가진 counter 를 조회한다면 그 값은 mapper 들에서 취합된 값이 아니므로 항상 0 이 나온다
따라서, reducer 를 동작중인 job 을 획득하여 counter 를 조회하여야 한다.
보통 reduce 메소드가 돌기전에 획득해 놓고 사용하기 때문에 setup 에서 구현한다.
long totalVal = 0; @Override public void setup(Context context) throws IOException, InterruptedException{ Configuration conf = context.getConfiguration(); Cluster cluster = new Cluster(conf); Job currentJob = cluster.getJob(context.getJobID()); totalCount = currentJob.getCounters().findCounter(MATCH_COUNTER.TOTAL_COUNT).getValue(); } |