hive中的local mr – 东杰书屋 – 博客频道 – CSDN.NET

在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的方式

这个两个条件是与的条件,一定要都满足才可以

来源URL:http://cache.baiducontent.com/c?m=9d78d513d99b1cff4fede53e4a4a8b3d450197634d8c8c027ea48448e5735a310526beea70635113d3b46b6770b8482cb4ad6721691420c6c19bde1780f9866f6fd6286e365ac45613a004b29b18789437902db8ee4fbbadf045cff994ce870f049c144420dbedd81a464f9b31a70967b4e0ca134b1e0db0ef3b61f5597d&p=9778c415d9c342af40bcc7710f4ac4&newp=882a9546d69e0efc57ef82684c4ea5231610db2151d4d615229b&user=baidu&fm=sc&query=Job+running+in%2Dprocess+%28local+Hadoop%29&qid=9f739f7800023c38&p1=1