hadoop之mr

文章目录

    • 1.mr之CombineTextInputFormat
    • 2.split size
    • 2.按行分片NLineInputFormat
    • 4.split大小与block的关系:
    • 5.reduce数量大于分区数

1.mr之CombineTextInputFormat

  • 处理一个文件夹下的四个小文件,未使用CombineTextInputFormat.class
       //默认走的是TextInputFormat
        //job.setInputFormatClass(CombineTextInputFormat.class);

        //6.设置输入输出路径
        FileInputFormat.setInputPaths(job, new Path(input));
        FileOutputFormat.setOutputPath(job, new Path(output));

输出:

INFO FileInputFormat: Total input paths to process : 4
INFO JobSubmitter: number of splits:4
  • 使用CombineTextInputFormat.class

        //默认走的是TextInputFormat
        job.setInputFormatClass(CombineTextInputFormat.class);

        //6.设置输入输出路径
        FileInputFormat.setInputPaths(job, new Path(input));
        FileOutputFormat.setOutputPath(job, new Path(output));

输出:

INFO FileInputFormat: Total input paths to process : 4
INFO CombineFileInputFormat: DEBUG: Terminated node allocation with : CompletedNodes: 1, size left: 57
INFO JobSubmitter: number of splits:1
INFO JobSubmitter: Submitting tokens for job: job_local656404029_0001

2.split size

hadoop之mr_第1张图片

  • 将block设置成4兆

hadoop之mr_第2张图片
有三个split

  • 第一阶段

1.4 <4 1.4
4.2 >4 <42 2.1 2.1
2.8 <4 2.8
5.7 >4 <4
2 2.85 2.85

  • CombineTextInputFormat只能合文本

2.按行分片NLineInputFormat

  • 业务场景:
    一般: 100列 100行 5G
    特殊: 2列 ? 5G

eg:10w行数据
未设置NLineInputFormat.1个split

       job.setInputFormatClass(NLineInputFormat.class);
        NLineInputFormat.setNumLinesPerSplit(30000);

设置NLineInputFormat后,3个splits

4.split大小与block的关系:

(1)block块的小于split分片的最小值,那split的值就是split分片的大小

(2)block块的小大介于split分片配置的最小值和最大值之间,block的大小就是split的大小。

(3)block块的大小大于split分片的最大值,split的大小就是split配置的最大值。但会增加map执行的并发度,但是会造成在节点之间拉取数据

也有公式可以计算split也就是map任务数,这里就不做讨论了。

  • 一个map对应一个split分片吗?
    经过上面的讨论,答案是显而易见的:
    map个数:由任务切片spilt决定的,默认情况下一个split的大小就是block
    由参与任务的文件个数决定的

5.reduce数量大于分区数

  • 后面的part文件是空的—小文件越多
    hadoop之mr_第3张图片

  • reduce数量不可以小于分区数

  • reduce数量可以等于1,全写入一个文件

  • reduce增加,并行度增加,速度会快.但是,jvm开销会大,小文件也增加.离线处理对速度要求不太高.

你可能感兴趣的:(hadoop,mr,hadoop)