복붙노트

[HADOOP] API를 통해 Hadoop 카운터 값에 액세스하는 방법은 무엇입니까?

HADOOP

API를 통해 Hadoop 카운터 값에 액세스하는 방법은 무엇입니까?

Hadoop에서 map / reduce 태스크의 카운터를 증가시킬 수 있습니다. 다음과 같습니다.

...
context.getCounter(MyCountersEnum.SomeCounter).increment(1);
...

로그에서 가치를 찾을 수 있습니다.

작업이 완료된 후 코드에서 어떻게 액세스합니까?

카운터 값을 읽는 Hadoop API는 무엇입니까?

해결법

  1. ==============================

    1.카운터는 Map-Reduce 프레임 워크 또는 응용 프로그램에 의해 정의 된 글로벌 카운터를 나타냅니다.

    카운터는 Map-Reduce 프레임 워크 또는 응용 프로그램에 의해 정의 된 글로벌 카운터를 나타냅니다.

    각 카운터는 모든 열거 형일 수 있습니다. Driver 클래스에서 enum으로 카운터를 정의 할 수 있습니다.

    static enum UpdateCount{
      CNT
     }
    

    그런 다음지도 / 축소 작업에서 카운터를 증가시킵니다.

    public class CntReducer extends Reducer<IntWritable, Text, IntWritable, Text>{
     public void reduce(IntWritable key,Iterable<Text> values,Context context)  {
          //do something
          context.getCounter(UpdateCount.CNT).increment(1);
     }
    }
    

    Driver 클래스에서 액세스하십시오.

    public int run(String[] args) throws Exception {
     .
     .
     .
     job.setInputFormatClass(TextInputFormat.class);
     job.setOutputFormatClass(TextOutputFormat.class);
     FileInputFormat.setInputPaths(job,in );
     FileOutputFormat.setOutputPath(job, out);
     job.waitForCompletion(true);
     c = job.getCounters().findCounter(UpdateCount.CNT).getValue();
     //Print "c"
     }
    }
    

    c는 카운터 값을 제공합니다.

    여기에서 예제를 찾을 수 있습니다.

  2. ==============================

    2.방금 대답을 찾았습니다.

    방금 대답을 찾았습니다.

    카운터에 액세스하려면 작업 개체가 필요합니다.

    Counters counters = job.getCounters();
    Counter counter = counters.findCounter(MyCountersEnum.SomeCounter);
    System.out.println(counter.getDisplayName() + ": " + counter.getValue());
    
  3. from https://stackoverflow.com/questions/27325536/how-to-access-hadoop-counters-values-via-api by cc-by-sa and MIT license