Hadoop及Mapreduce入门 pub.ppt
Hadoop入门,卢学裕优酷网2014.07,Outlines,Hadoop OverviewHDFSMap-reduce Programming ParadigmHadoop Map-reduceJob SchedulerResources,Hadoop,Why?,数据太多了,需要能存储、快速分析Pb级数据集的系统单机的存储、IO、内存、CPU有限,需要可扩展的集群使用门槛低,数据分析是个庞杂的问题,MPI太复杂单点故障问题机器多了单点故障成为正常的异常节点有增有减Hadoop就是一个满足易用性、可靠性、可扩展性的存储计算平台,还是开源的!,Hadoop History,Dec 2004 Google GFS paper publishedJuly 2005 Nutch uses MapReduceFeb 2006 Becomes Lucene subprojectApr 2007 Yahoo!on 1000-node clusterApr 2008 Fastest QuickSort on 1TBJan 2008 An Apache Top Level ProjectJul 2008 A 4000 node test cluster,Hadoop-related projects,Hive:数据仓库,facebook贡献PIG:并行计算的一种高级语言,yahoo贡献Nutch:网页搜索软件,不只是爬虫Avro:数据序列化系统Chukwa:用于管理大规模分布式集群的数据收集系统ZooKeeper:用于分布式应用的高性能协同服务Hbase:类似于BigTable的,key-value数据库系统Mahout:分布式机器学习和数据挖掘的LibHama:基于BSP的超大规模科学计算框架,Who Uses Hadoop,Amazon 著名的AWSAdobeAdknowledge:behavioral targeting,clickstream analyticsAlibabaBaidu:搜索日志分析;每周处理3000TB 数据Bixo Labs:web miningDatagraph:处理RDF数据,存储、索引EBay:532 nodes,搜索优化和研究ETH Zurich Systems Group:教学 Massively Parallel Data Analysis with MapReduce Facebook:1100 nodes,12PB;300 nodes,3PBFOX:3个Cluster 用于日志分析、数据挖掘、机器学习Freestylers:构建基于图片的推荐系统GoogleGruter.Corp:索引、Link分析、数据挖掘Hulu:Hbase hosting IBMKrugle:源代码搜索Last.fm:图表计算、A/B测试,user profile分析,cookie级的报表处理Lineberger Comprehensive Cancer Center:癌症相关的研究,使用SeqWareLinkedIn:这人你可能认识The New York TimesPARC:分析Wikipedia里的冲突Pressflip:个性化搜索,训练SVM模型Yahoo!:4000 nodes(2*4cpu boxes w 4*1TB disk&16GB RAM)优酷土豆More on http:/wiki.apache.org/hadoop/PoweredBy,Goals of HDFS,大数据集存储 10K nodes,100 million files,10 PB 应付硬件故障 用文件多副本应付故障问题 故障自动检测和恢复更适合批量处理 搬移计算比搬移数据更廉价 数据一次写入,多次读取 更注重数据读取的高吞吐量,而不是低延时适应复杂的硬件及软件平台,The File System,一个集群只有一个Namespace跟Unix的文件系统Namespace很相似,不过不支持Hard link、Soft link文件分块存储一般一块大小为64M,可配置每块会被复制在多个DataNode上支持回收站当一个文件被删除时会先放入用户下的回收站回收站会被定期清除恢复的方式是将文件从回收站移出,NameNode Metadata,Meta-data 存在内存中 整个Meta-data放入主内存 No demand paging of meta-dataMeta-data记录了 文件列表信息 每个文件的块列表 每个块对应的DataNode 文件属性,如创建时间、创建者、几份副本等Transaction Log(EditLog)记录了文件系统的每个变化,如创建文件、删除文件、修改文件的副本数等 EditLog会被合并为FsImage并存入磁盘Meta-data 磁盘故障 NameNode可以维护多份数据,DataNode,A Block Server 将数据存储本机文件系统(e.g.ext3)存储数据块的Meta-data(e.g.CRC,ID)汇报 启动时向NameNode注册本地存储的文件块定期向NameNode报告本机存活(心跳)数据输送 接收来自客户端的写数据 向客户端发送数据将数据传输到指定的 DataNodes,Block Replica Placement,机架感知NameNode能感知机架,选择较优的方式假设有3份或以上,目前的策略是一份放在本地节点上第二份放在另外一个机架的节点上第三份放在跟第二份同机架的不同节点上其他的随机放置客户端从最近的块读取,Data Correctness,用CRC32来做数据校验 Use CRC32文件写入 由客户端负责计算CRC checksum存放在DataNode文件读取客户端从DataNode读取数据和checksum由客户端校验,如果不通过,则客户端尝试从其他的副本读取数据,FS Shell,FShadoop fs-mkdir/foodirhadoop fs-rmr/foodirhadoop fs-cat/foodir/myfile.txthadoop fs-tail/foodir/myfile.txtChmod,chown,put,mv,cp,du,dus更多命令请运行 hadoop fs help获取DFSAdminSafemode,upgradeProgress,refreshNodes,fsck文件系统检查Balancer集群均衡,Web UI,Map-reduce Programming Paradigm,Map-reduce是一种适合分布式计算的编程范式input|map|shuffle|reduce|output最简单的实现方式cat*|grep java|sort|uniq-c|cat file实现这种编程范式的有GoogleHadoopOracleTeradata,Hadoop Map/Reduce,(input)-map-combine*-reduce-(output),combine 过程可能没有,也可能有多次,WordCount(周敏Taobao),The weather is good,This guyis a man,Today is good,Good manis good,the 1weather 1is 1good 1,today 1is 1good 1,this 1guy 1is 1a 1man 1,good 1man 1is 1good 1,a 1,good 1good 1good 1good 1,man 1man 1,the 1,weather 1,today 1,guy 1,is 1is 1is 1is 1,this 1,a 1good 4,guy 1is 4man 2the 1,this 1today 1weather 1,WordCount Mapper,public static class WordCountMapper extends Mapper private final static IntWritable ONE=new IntWritable(1);private Text word=new Text();protected void map(LongWritable 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);,WordCount Reducer,public static class IntSumReducer extends Reducer private IntWritable result=new IntWritable();public void reduce(Text key,Iterable values,Context context)throws IOException,InterruptedException int sum=0;for(IntWritable val:values)sum+=val.get();result.set(sum);context.write(key,result);,WordCount Job Setup,public static void main(String args)throws Exception String otherArgs=new GenericOptionsParser(conf,args).getRemainingArgs();if(otherArgs.length!=2)System.err.println(Usage:wordcount);System.exit(2);Job job=new Job(new Configuration(),word count);job.setJarByClass(WordCount.class);/设置输入 job.setInputFormatClass(TextInputFormat.class);FileInputFormat.addInputPath(job,new Path(otherArgs0);/Map job.setMapperClass(WordCountMapper.class);/Combine job.setCombinerClass(IntSumReducer.class);/Reduce job.setReducerClass(IntSumReducer.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);/设置输出 FileOutputFormat.setOutputPath(job,new Path(otherArgs1);/提交Job并执行 System.exit(job.waitForCompletion(true)?0:1);,Inject Points,Inputjob.setInputFormatClass()Mapjob.setMapperClass()Combine*job.setCombinerClass()Shufflingjob.setPartitionerClass()Sortjob.setSortComparatorClass()Groupingjob.setGroupingComparatorClass()Reducejob.setReducerClass()Outputjob.setOutputFormatClass(),Job Tracker&Task Tracker,Job&Task一个Job会被分成多个Task执行一个Task对应一个Map或者ReduceJob Tracker运行在Master上,管理和跟踪每个Job收集Task的信息状态,并汇总重新调度失败的任务Task Tracker向Job Tracker汇报状态(心跳)运行在每个计算节点上,管理和跟踪每个Task收集task的信息,并提供给Job Tracker,FIFO先到先得,排队执行Fair Scheduler(公平调度器)它的目的是让所有的作业随着时间的推移,都能平均的获取等同的共享资源。按资源池(pool)来组织作业,并把资源按配置分到这些资源池里http:/hadoop.apache.org/common/docs/r0.20.2/fair_scheduler.htmlCapacity Scheduler(容量调度器)支持多个queue,每个Job提交到一个queue里支持内存调度,对于需要高内存的任务,调度到有足够内存的节点http:/hadoop.apache.org/common/docs/r0.20.2/capacity_scheduler.html,Job Sheduler,Job Scheduler Web UI,Job Shell,hadoop job kill hadoop job listhadoop job-set-priority hadoop job-status hadoop job-kill-task hadoop job-fail-task,Job Web UI,Hive,Select COUNT(DISTINCT guid)as uv from youku_pv;,Hadoop Next Generation,NameNode单点故障YARNResource ManagerJob Scheduling/monitoringApplication Submission ClientApplicationMasterNew Programming ParadigmMPIMaster-WorkerIterative models“Customize”by yourself,Hadoop Next Generation Architecture,网站,广告,无线,搜索,播放器,分布式日志收集系统,HADOOP HDFS,HBASE,HIVE,统计分析运营分析用户分析数据开放平台数据挖掘相关推荐个性化推荐精准广告,MAP-REDUCE,大数据批量计算系统,分布式实时计算系统,分布式实时数据流处理系统,反作弊系统,调度系统,接口系统监控广告计数播放计数计数/监控作弊监测PlayLog记录个性化推荐准实时计算,优酷数据平台V2,优酷推荐系统,指数&VideoProfile,演示指数,Resources,Hadoophttp:/hadoop.apache.org/http:/hive.apache.org/http:/pig.apache.org/http:/hbase.apache.org/http:/zookeeper.apache.org/Hadoop World http:/3rd Hadoop实战Hadoop权威指南hadoop开发者杂志,Thanks,