hadoop之mr
文章目录1.mr之CombineTextInputFormat2.split size2.按行分片NLineInputFormat4.split大小与block的关系5.reduce数量大于分区数1.mr之CombineTextInputFormat处理一个文件夹下的四个小文件,未使用CombineTextInputFormat.class//默认走的是TextInputFormat//job.setInputFormatClass(CombineTextInputFormat.class);//6.设置输入输出路径FileInputFormat.setInputPaths(job,newPath(input));FileOutputFormat.setOutputPath(job,newPath(output));输出:INFO FileInputFormat:Total input paths to process:4INFO JobSubmitter:number of splits:4使用CombineTextInputFormat.class//默认走的是TextInputFormatjob.setInputFormatClass(CombineTextInputFormat.class);//6.设置输入输出路径FileInputFormat.setInputPaths(job,newPath(input));FileOutputFormat.setOutputPath(job,newPath(output));输出:INFO FileInputFormat:Total input paths to process:4INFO CombineFileInputFormat:DEBUG:Terminated node allocation with:CompletedNodes:1,size left:57INFO JobSubmitter:number of splits:1INFO JobSubmitter:Submitting tokensforjob:job_local656404029_00012.split size将block设置成4兆有三个split第一阶段1.4 4 1.44.2 4 42 2.1 2.12.8 4 2.85.7 4 42 2.85 2.85CombineTextInputFormat只能合文本2.按行分片NLineInputFormat业务场景:一般: 100列 100行 5G特殊: 2列 5Geg:10w行数据未设置NLineInputFormat.1个splitjob.setInputFormatClass(NLineInputFormat.class);NLineInputFormat.setNumLinesPerSplit(30000);设置NLineInputFormat后,3个splits4.split大小与block的关系1block块的小于split分片的最小值那split的值就是split分片的大小2block块的小大介于split分片配置的最小值和最大值之间block的大小就是split的大小。3block块的大小大于split分片的最大值split的大小就是split配置的最大值。但会增加map执行的并发度但是会造成在节点之间拉取数据也有公式可以计算split也就是map任务数这里就不做讨论了。一个map对应一个split分片吗经过上面的讨论答案是显而易见的map个数由任务切片spilt决定的默认情况下一个split的大小就是block由参与任务的文件个数决定的5.reduce数量大于分区数后面的part文件是空的—小文件越多reduce数量不可以小于分区数reduce数量可以等于1,全写入一个文件reduce增加,并行度增加,速度会快.但是,jvm开销会大,小文件也增加.离线处理对速度要求不太高.