在hive中运行的sql有很多是比较小的sql,数据量小,计算量小.这些比较小的sql如果也采用分布式的方式来执行,那么是得不偿失的.因为sql真正执行的时间可能只有10秒,但是分布式任务的生成得其他过程的执行可能要1分钟.这样的小任务更适合采用lcoal mr的方式来执行.就是在本地来执行,通过把输入数据拉回客户端来执行.
拿select 1 from dual来看下,两种执行方式的效率差距.
分布式mr:
hive> select 1 from dual;
Total MapReduce jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there’s no reduce operator
Selecting distributed mode: Input Size (= 10) is larger than hive.exec.mode.local.auto.inputbytes.max (= -1)
Starting Job = job_201208241319_7711163, Tracking URL = http://hdpjt:50030/jobdetails.jsp?jobid=job_201208241319_7711163
Kill Command = /dhwdata/hadoop/bin/../bin/hadoop job -Dmapred.job.tracker=hdpjt:9001 -kill job_201208241319_7711163
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2012-10-15 13:16:29,825 Stage-1 map = 0%, reduce = 0%
2012-10-15 13:16:38,044 Stage-1 map = 100%, reduce = 0%
Ended Job = job_201208241319_7711163
OK
1
Time taken: 15.278 seconds
本地mr:
hive> select 1 from dual;
Automatically selecting local only mode for query
Total MapReduce jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there’s no reduce operator
Execution log at: /tmp/dwapp/dwapp_20121015131717_eb78662f-2ccd-497c-a7eb-ba9a2234e153.log
Job running in-process (local Hadoop)
Hadoop job information for null: number of mappers: 0; number of reducers: 0
2012-10-15 13:17:28,644 null map = 0%, reduce = 0%
2012-10-15 13:17:29,646 null map = 100%, reduce = 0%
Ended Job = job_local_0001
2012-10-15 01:17:29 End of local task; Time Taken: 6.411 sec.
OK
1
Time taken: 7.859 seconds
因为仅仅是换了执行方式,效率提高了一倍.这还不算是差距大的,还遇到过效率差4倍以上的情况,如果jobtracker过忙,或者slots资源比较紧张的时候,这个差距会更大.
所以,合理的使用local mr对性能的提高有非常的提升.
下面两个参数是local mr中常用的控制参数:
1,hive.exec.mode.local.auto.inputbytes.max
设置local mr的最大输入数据量,当输入数据量小于这个值的时候会采用local mr的方式
2,hive.exec.mode.local.auto.tasks.max
设置local mr的最大输入文件个数,当输入文件个数小于这个值的时候会采用local mr的方式
这个两个条件是与的条件,一定要都满足才可以