map reduce模型

Post on 27-Jan-2015

252 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Map reduce模型

TRANSCRIPT

《MapReduce模型》

丁海亮 2013-02-27

议程

l 计算模型

l 基础架构

l HDFS

l MapReduce

l 集群部署

典型例子

计算模型

基础架构

基础架构

基础架构

HDFS

读取数据

写入数据

MapReduce

MapReduce

MapReduce

public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable>{ private final static IntWritable one = new IntWritable(1); private Text word = new Text(); public void map(Object key, Text value, Context context ) throws IOException, InterruptedException { StringTokenizer itr = new StringTokenizer(value.toString()); while (itr.hasMoreTokens()) { word.set(itr.nextToken()); context.write(word, one); } } }

MapReduce

public static class IntSumReducer extends Reducer<Text,IntWritable,Text,IntWritable> { private IntWritable result = new IntWritable(); public void reduce(Text key, Iterable<IntWritable> values, Context context ) throws IOException, InterruptedException { int sum = 0; for (IntWritable val : values) { sum += val.get(); } result.set(sum); context.write(key, result); } }

MapReduce

public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length != 2) { System.err.println("Usage: wordcount <in> <out>"); System.exit(2); } Job job = new Job(conf, "word count"); job.setJarByClass(WordCount.class); job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(IntSumReducer.class); job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path(otherArgs[0])); FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); System.exit(job.waitForCompletion(true) ? 0 : 1); }

实施流程

硬件选型(商用机)

操作系统选型(Linux)

内核调优

硬盘配置 DataNode无须RAID和LVM

网络配置

Hadoop环境配置

运维支撑 rsync自动化同步配置部署

vm.overcommit_memory

集群部署

集群部署

集群部署

论文参考

Thank You

top related