Study on hive small file merging

Source: Internet
Author: User

Background

Hive Query writes the calculated data back to HDFs (such as INSERT INTO statement), sometimes produces a large number of small files, if you do not use Combinehiveinputformat to operate on these small files will produce a large number of map tasks, Consuming a lot of cluster resources, and too much small files can cause great pressure on namenode. So after the normal job is done, Hive will start a conditional task to determine whether the small files need to be merged, and if the requirements are met, another map-only job or mapred job will be initiated to complete the merge

Parameter explanation

Hive.mergejob.maponly (default is True)

If the Hadoop version supports Combinefileinputformat, start the map-only job for merge, otherwise it is more efficient to start the MapReduce merge Job,map end combine file

Hive.merge.mapfiles (default is True)

After the normal map-only job, whether to start the merge job to merge the results of the map-side output

Hive.merge.mapredfiles (default to False)

After the normal map-reduce job, whether to start the merge job to merge the results of the reduce-side output, it is recommended to open

Hive.merge.smallfiles.avgsize (default is 16MB)

If it is not partitioned table, the average size of the output table file is less than this value, the merge job is started, and if it is partitioned table, the average file size under each partition is calculated, Only the partition with the average size of the merge is less than this value. This value is valid only if the Hive.merge.mapfiles or Hive.merge.mapredfiles is set to True

Hive.exec.reducers.bytes.per.reducer (default is 1G)

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/database/extra/

If the user does not actively set the number of mapred.reduce.tasks, the input directory will be calculated according to the input summary size of all read files, and then divided by this value to calculate reduce

reducers = (int) ((totalinputfilesize + bytesPerReducer-1)/bytesperreducer);

reducers = Math.max (1, reducers);

reducers = Math.min (maxreducers, reducers);

Hive.merge.size.per.task (default is 256MB)

The target size (targetsize) of each file after the merge job, divided by this value from the total size of the previous job output file, can determine the number of reduce for the merge job. The map end of the merge job is equivalent to the identity map, and then shuffle to reduce, with each reduce dump a file that controls the number and size of files in this way

Mapredwork work = (mapredwork) mrtask.getwork ();

if (work.getnumreducetasks () > 0) {

int maxreducers = Conf.getintvar (HiveConf.ConfVars.MAXREDUCERS);

int reducers = (int) ((totalsize +targetsize-1)/targetsize);

reducers = Math.max (1, reducers);

reducers = Math.min (maxreducers, reducers);

Work.setnumreducetasks (reducers);

}

Mapred.max.split.size (Default 256MB)

Mapred.min.split.size.per.node (default 1 byte)

Mapred.min.split.size.per.rack (default 1 byte)

These three parameters will be used in Combinefileinputformat, hive the default InputFormat is Combinehiveinputformat, All of the calls inside (including the most important getsplits and Getrecordreader) are converted into Combinefileinputformat calls, so they can be considered as a wrapper. Combinefileinputformat can combine many small files into a map input, and if the file is large, you can also split the large file into multiple map inputs. A combinefilesplit corresponds to the input of a map containing a set of paths (HDFs path list), Startoffset, lengths, locations (where the file is located hostname list) Mapred.max.split.size is the biggest size of a split, Mapred.min.split.size.per.node is a node (datanode) split at least the size of the mapred.min.split.size.per.rack is the same switch (rack locality) The lower split is at least the size of the three-digit adjustment, consisting of a string of combinefilesplit users can reduce the number of map tasks by increasing the value of mapred.max.split.size

Conclusion

Hive the above values to control whether to start the merge file job, usually recommended that everyone open, if it is a bunch of sequential operation chain, only the last table needs to be cured, the middle table is deleted, can be opened before the last insert into table, Preventing a previous job from launch the merge job slows the job down.

Last week it was also found that the currently launched block merger for Rcfile, in some rare cases, will generate duplicated files,hive the code itself has taken this into account, so it will be in the merger Task Rcfilemergemapper's Jobclose function calls Utilities.removetemporduplicatefiles (FS, IntermediatePath, DPCTX), but does not know why it is not effective, There will be duplicate files that need to be studied again

Hive whether or not the merge job is made by the conditional task at run time, if the Hadoop job or hive does not perform the merge job as expected, you can use the File Crush tool on GitHub to complete the merge. It also works by starting a mapreduce job to complete the merge, but currently only supports Textfile and Sequencefile

Link Address: Https://github.com/edwardcapriolo/filecrush

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.