Hive调优

Fetch抓取

hive中对某些情况的查询可以不用MapReduce计算。例如select * from emp,可以简单的读取emp文件,输出结果。

在hive-default.xml.template文件中的hive.fetch.task.conversion默认为more,老版本默认为minimal。该值设为more后,在全局查找、字段查找和limit查找等都不使用MapReduce。

<property>
    <name>hive.fetch.task.conversion</name>
    <value>more</value>
    <description>
      Expects one of [none, minimal, more].
      Some select queries can be converted to single FETCH task minimizing latency.
      Currently the query should be single sourced not having any subquery and should not have
      any aggregations or distincts (which incurs RS), lateral views and joins.
      0. none : disable hive.fetch.task.conversion
      1. minimal : SELECT STAR, FILTER on partition columns, LIMIT only
      2. more  : SELECT, FILTER, LIMIT only (support TABLESAMPLE and virtual columns)
    </description>
  </property>
hive>set hive.fetch.task.conversion=more;
hive>select * from emp;
hive>select name from emp;
hive>select name from emp limit 3;
#以上在将值设为more后,都不会执行MapReduce,设为none,都会执行MapReduce。

本地模式

大多数hadoop job是需要hadoop提供完整的可拓展性来处理大数据集的,不过,有时hive的输入数据量比较小。在这种情况下,为查询触发任务消耗的时间可能比实际job执行时间多的多。对这种情况,hive可以通过本地模式在单台机器上处理所有的任务,对于小数据集,执行时间被明显缩短。

通过设置hive.exec.mode.local.auto的值为true,让hive在适当的时候自动启用这个优化。

# 开启本地mr
hive>set hive.exec.mode.local.auto=true;
# 设置local mr的最大输入数据量,当输入数据量小于这个值时,采用local mr,默认134217728,即128M
hive>set hive.exec.mode.local.auto.inputbytes=50000000;
# 设置local mr的最大输入文件个数,当输入文件个数小于这个值时,采用loacl mr,默认4
hive>set hive.exec.mode.local.auto.input.files.max=10;

1)开启本地模式,并执行查询语句

hive (default)> set hive.exec.mode.local.auto=true; 
hive (default)> select * from emp cluster by deptno;
Time taken: 1.328 seconds, Fetched: 14 row(s)

2)关闭本地模式,并执行查询语句

hive (default)> set hive.exec.mode.local.auto=false;
hive (default)> select * from emp distribute by deptno;
Time taken: 20.09 seconds, Fetched: 14 row(s)

严格模式

防止用户执行那些可能意向不到的不好的影响的查询。

设置属性hive.mapred.mode的值,默认为nonstrict(非严格模式)。当值为strict时,为严格模式,会禁止特定的查询。

<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>

对于使用了order by语句的查询,要求必须使用limit语句。因为order by为了执行排序过程会将所有的数据发送个同一个reducer进行处理。强制要求用户增加这个limit语句可以防止reducer额外执行很长一段时间。

限制笛卡尔积的查询。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值