4. What is MapReduce?
텍스트 검색 라이브러리 아파치 루씬 창시자 '더그 커팅'에
의해 시작
오픈소스 웹 검색엔진 아파치 너치(Apache Nutch)에서 탄생
구글 MapReduce 프로그래밍 모델을 제안
• 소스를 공개를 하지 않음
5. HDFS와 MapReduce
오픈소스 분산 어플리케이션 프레임워크
파일시스템: HDFS
컴퓨팅 프레임워크: MapReduce
수천 대의 클러스터까지 확장 가능
대용량 데이터의 처리에 적합
Google에 의해 MapReduce 모델 제안
HDFS MapReduce
6. Hadoop
Open Source in Java
Yahoo에서 구현하여 공개
Hadoop
HDFS
( Hadoop Distributed File System )
MapReduce
Java Virtual Machine
7. HDFS
클러스터 파일 시스템 (Cluster File System)
일반 파일 시스템 클러스터 파일 시스템
Network Network
물리 디스크 물리 디스크 물리 디스크 물리 디스크
논리 디스크 논리 디스크
8. MapReduce
분산 처리 모델 (Distributed Computing Model)
일반 처리 모델 분산 처리 모델
Network Network
12. HDFS: Metadata
파일의 위치 + 파일 이름 + 복제 수
메모리에 상주하면서 빠르게 정보를 전달
/home/test/test_file
어디에 있나?
Name Node
CLIEN
X 노드, Y 블럭
T
Metadata
/home/root/test, 3 …..
/home/test/test_file,3 …..
/home/micle/miracle, 3 ….
13. HDFS: Block
저장 공간의 단위
사용자의 설정에 의해 변경될 수 있다.
저장공간 보다 작은 다 수의 파일은?
40M 128M
88M
40M 128M
88M
기본 블록 사이즈는 128MB 라고 가정
128M 40MB 크기의 파일 2 개를 복사
저장공간 보다 큰 파일은?
128M
72M128M 56M
기본 블록 사이즈는 128MB 라고 가정
128 200MB 크기의 파일 1 개를 복사
14. HDFS: Replication
Replication 복제
왜 복제를 하는가?
DATA
복제가 존재하는 서버
복제가 없는 서버
16. MapReduce
Split Data
(key, value) (key, value)
Data Split 1 Mapper Temp Disk
Reducer
Large
Data Data Split 2 Mapper Temp Disk Result
Reducer
Data Split 3 Mapper Temp Disk
1. (Key,Value) 로 자료를 가져온다. 1. (Key,Value) 로 자료를 가져온다.
2. 분석 후 (Key,Value) 를 생성한다. 2. 같은 key 값에 대한 분석을 진행한다.
3. 분석 된 (Key,Value) 를 저장한다 3. 최종 결과 (Key,Value) 를 저장한다.
18. Hadoop의 하위 프로젝트
• Avro
– 직렬화 시스템
• Chukwa
– 분산된 데이터를 수집 시스템
• Hbase
– 큰 테이블을 지원하는 데이터 베이스 시스템
• Hive
– 데이터를 통합하고 SQL-like 쿼리 지원
• Pig
– 흐름제어를 위한 Script 언어 지원
• Zookeeper
– 분산 어플리케이션을 위한 coordination 서비스
19. 사례: Amazon EC2, S3 서비스
왜 Amazon의 서비스를 이용하는가?
성능 향상
다수의 컴퓨터를 이용한 성능 향상
비용 절감
수 백대 혹은 그 이상의 컴퓨터를 유지하는 비용 절감
설치가 필요 없음
기본적인 MapReduce를 제공
20. 뉴욕타임즈 사례
1851年 – 1981年 12月
1100만매의 신문
Amazon S3 Service
TIFF Image ( 4TB ) PDF File ( 1.5TB )
Amazon EC2 Service
Hadoop AMI
(Hadoop Amazon Machine Image)
X 100
소요 비용
S3 EC2
Storage – 5.5TB $ 1465
Data Transfer – 4TB Instances 100 x 24 Hour
21. 사례 : Facebook 로그 분석
Scribe 를 이용한 로그 수집 후
MapReduce를 이용한 분석
Hadoop의 하위 프로젝트 Hive를 이용
22. 사례 : 트래픽 분석
Snort 로그 분석
방화벽 로그 분석
Flow Data 분석
대용량의 플로우 데이터를 분석
http://wiki.apache.org/hadoop/PoweredBy#G
23. MapReduce 프로그래밍 구성요소
InputFormat Mapper Key1 Combiner Key1 Reducer OutputFormat
Value1 Partitioner Value1
RecorderReader RecorderWriter
InputSplit
Key2 Value2
맵리듀스 프레임워크
입력 데이터 출력 데이터
23
24. MapReduce 프로그래밍 구성요소
1. InputFormat
입력데이터를 map() 메소드로 전달
몇 개의 맵 태스크로 분리해야 하는지에 대한 정보
getSplit()
하나의 레코드 씩 map() 메소드로에 전달
RecordReader가 담당
2. Mapper
RecordReader에 의해 전달된 각 레코드를 읽어 새로운 키-값 생성
3. Combiner
맵의 결과로 생성된 임시 로컬 데이터에 대한 리듀스 작업 수행
리듀스로 전달되는 데이터의 양을 줄임으로써 네트워크 성능 문제
해결
24
25. MapReduce 프로그래밍 구성요소
4. Partitioner
키를 이용해 맵의 출력 데이터를 각 리듀스로 분배하는 규칙 적용
5. Reducer
새로운 키를 기준으로 의미있는 결과 생성
6. OutputFormat
리듀스의 결과를 출력
25
27. MapReduce Programming
Mapper 클래스
키-값의 쌍을 생성
Reduce 클래스
입력은 키와 값 목록
키를 기준으로 여러 개의 값을 출력
메인 클래스(Driver)
작업의 설정과 실행 map (k1, v1) list (k2, v2)
Reduce (k2, list (v2) list (v2)
27
29. MapReduce: WordCount 예제
public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, Context context) {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
context.write(word, one);
}
}
29
30. MapReduce: WordCount 예제
public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable>
{
public void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
context.write(key, new IntWritable(sum));
}
}
30
31. MapReduce: WordCount 예제
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = new Job(conf, "wordcount");
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.addInputPath( job, new Path(args[0]));
FileOutputFormat.setOutputPath( job, new Path(args[1]));
job.waitForCompletion(true);
}
31
32. Partitioner
public class HashPartitioner<K2, V2> implements Partitioner<K2, V2> {
public void configure(JobConf job) {}
public int getPartition(K2 key, V2 value, int numPartitions) {
return (key.hashCode() & Integer.MAX_VALUE) % numPartitions ;
}
}
32
33. Combiner
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = new Job(conf, "wordcount");
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setMapperClass(Map.class);
job.setCombinerClass(Reduce.class);
job.setReducerClass(Reduce.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.addInputPath( job, new Path(args[0]));
FileOutputFormat.setOutputPath( job, new Path(args[1]));
job.waitForCompletion(true);
} 33