21企业级调优3

四、数据倾斜

1.合理设置map数量
	并不是map数越多越好,若是逻辑比较复杂应增加map任务。

2.小文件进行合并
	设置可进行合并:
	set hive.input.format= org.apache.hadoop.hive.ql.io.CombineHiveInputFormat;
	
3.复杂文件增加map数
	实例:
		(1)执行查询
			select count(*) from emp;
		(2)设置最大切片值为100个字节
			set mapreduce.input.fileinputformat.split.maxsize=100;
			select count(*) from emp;
4.合理设置reduce数
	4.1 方法一
		(1)每个Reduce处理的数据量默认是256MB
			hive.exec.reducers.bytes.per.reducer=256000000
		(2)每个任务最大的reduce数,默认为1009
			hive.exec.reducers.max=1009
		(3)计算reducer数的公式
			N=min(参数2,总输入数据量/参数1)
	
	4.2 方法二
		在hadoop的mapred-default.xml文件中修改
		设置每个job的Reduce个数
			set mapreduce.job.reduces = 15;
	
	4.3 reduce个数并不是越多越好
		(1)过多的启动和初始化reduce也会消耗时间和资源;
		(2)另外,有多少个reduce,就会有多少个输出文件,如果生成了很多个小文件,
			那么如果这些小文件作为下一个任务的输入,则也会出现小文件过多的问题;
		两个原则:处理大数据量利用合适的reduce数;使单个reduce任务处理数据量大小要合适;

五、并行处理

通过设置参数hive.exec.parallel值为true,就可以开启并发执行。
在共享集群中,需要注意下,如果job中并行阶段增多,那么集群利用率就会增加

	set hive.exec.parallel=true;            //打开任务并行执行
	set hive.exec.parallel.thread.number=16;  //同一个sql允许最大并行度,默认为8。

六、严格模式

通过设置属性hive.mapred.mode值为默认是非严格模式nonstrict 。
开启严格模式需要修改hive.mapred.mode值为strict,开启严格模式可以禁止3种类型的查询。		

<property>
	<name>hive.mapred.mode</name>
	<value>strict</value>
	<description>
		The mode in which the Hive operations are being performed. 
		In strict mode, some risky queries are not allowed to run. They include:
			Cartesian Product.
			No partition being picked up for a query.
			Comparing bigints and strings.
			Comparing bigints and doubles.
			Orderby without limit.
	</description>
</property>

(1)对于分区表,除非where语句中含有分区字段过滤条件来限制范围,否则不允许执行。
(2)对于使用了order by语句的查询,要求必须使用limit语句。
(3)限制笛卡尔积的查询。

七、JVM重用

Hadoop的默认配置通常是使用派生JVM来执行map和Reduce任务的。
	它的启动会有相当大的开销,尤其是执行job包含成百上千task任务的情况。
JVM重用可以使得JVM实例在同一个job中重新使用N次。
N的值可以在Hadoop的mapred-site.xml文件中进行配置。

	<property>
		<name>mapreduce.job.jvm.numtasks</name>
		<value>10</value>
		<description>How many tasks to run per jvm. If set to -1, there is
		no limit. 
		</description>
	</property>
	
缺点:开启JVM重用将一直占用使用到的task插槽,以便进行重用,直到任务完成后才能释放。

八、推测执行

1.设置开启推测执行参数:
	Hadoop的mapred-site.xml文件中进行配置
		<property>
			<name>mapreduce.map.speculative</name>
			<value>true</value>
			<description>If true, then multiple instances of some map tasks 
			may be executed in parallel.</description>
		</property>
		<property>
			<name>mapreduce.reduce.speculative</name>
			<value>true</value>
			<description>If true, then multiple instances of some reduce tasks 
			may be executed in parallel.</description>
		</property>

2.hive本身也提供配置
	控制reduce-side的推测执行:
		<property>
			<name>hive.mapred.reduce.tasks.speculative.execution</name>
			<value>true</value>
			<description>Whether speculative execution for reducers should be turned on. 
			</description>
		</property>

3.建议
	如果用户对于运行时的偏差非常敏感的话,那么可以将这些功能关闭掉。
	如果用户因为输入数据量很大而需要执行长时间的map或者Reduce task的话,
		那么启动推测执行造成的浪费是非常巨大的。

九、执行计划

(1)查看下面这条语句的执行计划
	explain select * from emp;
	explain select deptno, avg(sal) avg_sal from emp group by deptno;

(2)查看详细执行计划
	explain extended select * from emp;
	explain extended select deptno, avg(sal) avg_sal from emp group by deptno;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hao难懂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值