tonykang22 / study

0 stars 0 forks source link

09. MapReduce #165

Open leeyuunsung opened 1 year ago

leeyuunsung commented 1 year ago

09. MapReduce 기초

MapReduce 란?

MapReduce 용어

InputSplit vs Block

image

image

원본 파일

image

해당 파일이 HDFS 에 Block 단위로 저장되는 경우

image

InputSplit 은 논리적 Record 단위로 읽어오게 된다

MapReduce 란?

image

MapReduce Word Count 처리 과정 예시

image

leeyuunsung commented 1 year ago

10 MapReduce 처리 과정

MapReduce 처리 과정

image

InputFormat

public interface InputFormat<K, V> {

  InputSplit[] getSplits(JobConf job, int numSplits) throws IOException;

  RecordReader<K, V> getRecordReader(InputSplit split,
                                     JobConf job, 
                                     Reporter reporter) throws IOException;
}

InputFormat 종류

SequenceFile

InputSplit

public interface InputSplit extends Writable {

  long getLength() throws IOException;

  String[] getLocations() throws IOException;
}

RecordReader

Mapper

public class Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT> {
  ...
  public void run(Context context) throws IOException, InterruptedException {
    setup(context);
    try {
      while (context.nextKeyValue()) {
        map(context.getCurrentKey(), context.getCurrentValue(), context);
      }
    } finally {
      cleanup(context);
    }
  }
}

Combiner

Partitioner

public class HashPartitioner<K2, V2> implements Partitioner<K2, V2> {
  ...
  public int getPartition(K2 key, V2 value,
                          int numReduceTasks) {
    return (key.hashCode() & Integer.MAX_VALUE) % numReduceTasks;
  }

}

Shuffling and Sorting

Reducer

public class Reducer<KEYIN,VALUEIN,KEYOUT,VALUEOUT> {
  ...
  public void run(Context context) throws IOException, InterruptedException {
    setup(context);
    try {
      while (context.nextKey()) {
        reduce(context.getCurrentKey(), context.getValues(), context);
        // If a back up store is used, reset it
        Iterator<VALUEIN> iter = context.getValues().iterator();
        if(iter instanceof ReduceContext.ValueIterator) {
          ((ReduceContext.ValueIterator<VALUEIN>)iter).resetBackupStore();        
        }
      }
    } finally {
      cleanup(context);
    }
  }
}

OutputFormat

OutputFormat 종류

leeyuunsung commented 1 year ago

11 MapReduce 작동 방식

image

MapReduce 컴포넌트

MapReduce 작동 방식 상세

MapReduce Job 제출

MapReduce Job 초기화

MapReduce Task 할당

MapReduce Task 실행

MapReduce 진행 상황과 상태 업데이트

image

MapReduce Job 완료