【问题标题】:Issue in Hive Query due to memory由于内存导致 Hive 查询中的问题
【发布时间】:2019-09-19 00:06:54
【问题描述】:

我们有插入查询,我们试图通过从非分区表中读取数据来将数据插入到分区表中。

查询-

 insert into db1.fact_table PARTITION(part_col1, part_col2) 
 ( col1,
 col2,
 col3,
 col4,
 col5,
 col6,
 .
 .
 .
 .
 .
 .
 .
 col32
 LOAD_DT,
 part_col1,
 Part_col2 ) 
 select 
 col1,
 col2,
 col3,
 col4,
 col5,
 col6,
 .
 .
 .
 .
 .
 .
 .
 col32,
 part_col1,
 Part_col2
 from db1.main_table WHERE col1=0;

表有 34 列,主表中的记录数取决于我们每天收到的输入文件的大小。 并且我们在每次运行中插入的分区数(part_col1、part_col2)可能从 4000 到 5000 不等

有时此查询会因以下问题而失败。

2019-04-28 13:23:31,715 第一阶段地图 = 95%,减少 = 0%,累积 CPU 177220.23 sec 2019-04-28 13:24:25,989 Stage-1 map = 100%,减少 = 0%,累积 CPU 163577.82 秒 MapReduce 总累积 CPU 时间:1 天 21 小时 26 分 17 秒 820 毫秒结束的作业 = job_1556004136988_155295 with errors 作业期间出错,获取 调试信息... 检查任务 ID: 来自工作的task_1556004136988_155295_m_000003(以及更多) job_1556004136988_155295 检查任务 ID: 来自工作的task_1556004136988_155295_m_000004(以及更多) job_1556004136988_155295 失败次数最多的任务(4): ----- 任务ID:task_1556004136988_155295_m_000000
----- 此任务的诊断消息:容器启动异常。容器编号: container_e81_1556004136988_155295_01_000015 退出代码:255 堆栈 跟踪:ExitCodeException 退出代码 = 255: 在 org.apache.hadoop.util.Shell.runCommand(Shell.java:563) 在 org.apache.hadoop.util.Shell.run(Shell.java:460) 在 org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:748) 在 org.apache.hadoop.yarn.server.nodemanager.LinuxContainerExecutor.launchContainer(LinuxContainerExecutor.java:305) 在 org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.call(ContainerLaunch.java:356) 在 org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.call(ContainerLaunch.java:88) 在 java.util.concurrent.FutureTask.run(FutureTask.java:266) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 在 java.lang.Thread.run(Thread.java:748) Shell 输出:main:提供的命令 1 main:用户是 bldadmin main: 请求的纱线用户是 bldadmin 容器以非零值退出 退出代码 255 失败:执行错误,从返回代码 2 org.apache.hadoop.hive.ql.exec.mr.MapRedTask MapReduce Jobs Launched: Stage-Stage-1:映射:10 累积 CPU:163577.82 秒 MAPRFS 读取: 0 MAPRFS 写入:0 FAIL 总 MapReduce CPU 时间花费:1 天 21 小时 26 分 17 秒 820 毫秒

当前配置单元属性。

使用 Tez 引擎 -

set hive.execution.engine=tez;
set hive.tez.container.size=3072;
set hive.tez.java.opts=-Xmx1640m;
set hive.vectorized.execution.enabled=false;
set hive.vectorized.execution.reduce.enabled=false;
set hive.enforce.bucketing=true;
set hive.exec.parallel=true;
set hive.auto.convert.join=false;
set hive.enforce.bucketmapjoin=true;
set hive.optimize.bucketmapjoin.sortedmerge=true;
set hive.optimize.bucketmapjoin=true;
set hive.exec.tmp.maprfsvolume=false;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.dynamic.partition=true;
set hive.stats.fetch.partition.stats=true;
set hive.support.concurrency=true;
set hive.exec.max.dynamic.partitions=999999999;
set hive.enforce.bucketing=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
set hive.compactor.initiator.on=true;

根据其他团队的意见,我们将引擎更改为 mr 并且属性是 -

set hive.execution.engine=mr;
set hive.auto.convert.join=false;
set mapreduce.map.memory.mb=16384;
set mapreduce.map.java.opts=-Xmx14745m;
set mapreduce.reduce.memory.mb=16384;
set mapreduce.reduce.java.opts=-Xmx14745m;

这些属性查询完成几次,没有任何错误。

我如何调试这些问题,是否有任何我们可以设置的配置单元属性,以便我们以后不会遇到这些问题。

【问题讨论】:

    标签: hive insert hiveql partition hive-partitions


    【解决方案1】:

    添加按分区键分发。每个reducer只会处理一个分区,而不是每个分区,这样会减少内存消耗,因为reducer会创建更少的文件,保留更少的缓冲区。

    insert into db1.fact_table PARTITION(part_col1, part_col2) 
    select 
    col1,
    ...
    
    col32,
    part_col1,
    Part_col2
     from db1.main_table WHERE col1=0
    distribute by part_col1, Part_col2; --add this
    

    使用谓词下推,如果源文件是 ORC,它可能有助于过滤:

    SET hive.optimize.ppd=true;
    SET hive.optimize.ppd.storage=true;
    SET hive.optimize.index.filter=true;
    

    调整适当的 mapper 和 reducer 并行度:https://stackoverflow.com/a/48487306/2700344

    如果您的数据太大并且分区键分布不均匀,则除了分区键外,还添加随机分布。这将有助于处理偏斜的数据:

    distribute by part_col1, Part_col2, FLOOR(RAND()*100.0)%20;
    

    另请阅读https://stackoverflow.com/a/55375261/2700344

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-05
      • 2020-09-03
      • 2013-04-01
      • 2021-02-05
      • 2021-11-19
      • 2023-03-05
      • 2013-05-24
      • 2011-10-19
      相关资源
      最近更新 更多