Hive 查询卡在 99%
Hive query stuck at 99%
我正在使用左连接插入记录 Hive.When 我设置了限制 1 查询有效但是对于所有记录查询卡在 99% 减少作业。
以下查询有效
Insert overwrite table tablename select a.id , b.name from a left join b on a.id = b.id limit 1;
但这并没有
Insert overwrite table tablename select table1.id , table2.name from table1 left join table2 on table1.id = table2.id;
我增加了 reducer 的数量,但仍然不起作用。
Hive 在连接时会自动进行一些优化,如果符合要求,会将连接的一侧加载到内存中。然而,在某些情况下,这些作业会卡在 99% 并且永远不会真正完成。
我已经多次遇到过这种情况,并且我通过显式指定一些设置来避免这种情况。试试下面的设置,看看它是否适合你。
- hive.auto.convert.join=false
- mapred.compress.map.output=真
- hive.exec.parallel=真
以下是一些 Hive 优化,可能有助于查询优化器并减少通过线路发送的数据的开销。
set hive.exec.parallel=true;
set mapred.compress.map.output=true;
set mapred.output.compress=true;
set hive.exec.compress.output=true;
set hive.exec.parallel=true;
set hive.cbo.enable=true;
set hive.compute.query.using.stats=true;
set hive.stats.fetch.column.stats=true;
set hive.stats.fetch.partition.stats=true;
但是,我认为潜在问题更有可能是连接的关键。有关偏斜和可能的解决方法的完整描述,请参阅此 https://cwiki.apache.org/confluence/display/Hive/Skewed+Join+Optimization
您还提到 table1 比 table2 小得多。您可以根据您的硬件限制尝试映射端连接。 (https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Joins)
使用这些配置并尝试
hive> set mapreduce.map.memory.mb=9000;
hive> set mapreduce.map.java.opts=-Xmx7200m;
hive> set mapreduce.reduce.memory.mb=9000;
hive> set mapreduce.reduce.java.opts=-Xmx7200m
如果您的查询卡在 99%,请查看以下选项 -
- 数据偏斜,如果你有偏斜数据,可能 1 个 reducer 正在做所有的工作
- 两侧都有重复的键 - 如果两侧都有许多重复的连接键,您的输出可能会爆炸并且查询可能会卡住
- 您的 table 中的一个很小,请尝试使用 map join 或如果可能的话 SMB join,这比 reduce side join
具有巨大的性能提升
- 转到资源管理器日志,查看作业正在访问和写入的数据量。
我遇到了类似左外连接的相同问题:
select bt.*, sm.newparam from
big_table bt
left outer join
small_table st
on bt.ident = sm.ident
and bt.cate - sm.cate
我根据已经给出的答案进行了分析,我看到了两个给定的问题:
左边 table 比右边 table
大 100 倍以上
select count(*) from big_table -- returned 130M
select count(*) from small_table -- returned 1.3M
我还检测到其中一个连接变量偏向右侧 table:
select count(*), cate
from small_table
group by cate
-- returned
-- A 70K
-- B 1.1M
-- C 120K
我尝试了其他答案中给出的大部分解决方案以及我发现的一些额外参数here没有成功。:
set hive.optimize.skewjoin=true;
set hive.skewjoin.key=500000;
set hive.skewjoin.mapjoin.map.tasks=10000;
set hive.skewjoin.mapjoin.min.split=33554432;
最后我发现 left table 的连接列 的空值百分比非常高:bt.ident
和 bt.cate
所以我尝试了最后一件事,它最终对我有用:根据 bt.ident
和 bt.cate
是否为 null 拆分左侧 table,稍后制作 union all
两个分支:
select * from
(select bt.*, sm.newparam from
select * from big_table bt where ident is not null or cate is not null
left outer join
small_table st
on bt.ident = sm.ident
and bt.cate - sm.cate
union all
select *, null as newparam from big_table nbt where ident is null and cate is null) combined
确保您的数据之一中没有包含重复 ID 值的行 tables!
我最近遇到了同样的问题,左连接的 map-reduce 进程在 Hue 中卡在了 99%。
经过一番探查,我发现了问题的根源:在我的 table 之一中,有行具有重复的 member_id 匹配变量。加入所有重复的 member_id 会创建一个包含数亿行的新 table,消耗的内存超过我在公司 Hadoop 服务器上分配的内存。
我正在使用左连接插入记录 Hive.When 我设置了限制 1 查询有效但是对于所有记录查询卡在 99% 减少作业。
以下查询有效
Insert overwrite table tablename select a.id , b.name from a left join b on a.id = b.id limit 1;
但这并没有
Insert overwrite table tablename select table1.id , table2.name from table1 left join table2 on table1.id = table2.id;
我增加了 reducer 的数量,但仍然不起作用。
Hive 在连接时会自动进行一些优化,如果符合要求,会将连接的一侧加载到内存中。然而,在某些情况下,这些作业会卡在 99% 并且永远不会真正完成。
我已经多次遇到过这种情况,并且我通过显式指定一些设置来避免这种情况。试试下面的设置,看看它是否适合你。
- hive.auto.convert.join=false
- mapred.compress.map.output=真
- hive.exec.parallel=真
以下是一些 Hive 优化,可能有助于查询优化器并减少通过线路发送的数据的开销。
set hive.exec.parallel=true;
set mapred.compress.map.output=true;
set mapred.output.compress=true;
set hive.exec.compress.output=true;
set hive.exec.parallel=true;
set hive.cbo.enable=true;
set hive.compute.query.using.stats=true;
set hive.stats.fetch.column.stats=true;
set hive.stats.fetch.partition.stats=true;
但是,我认为潜在问题更有可能是连接的关键。有关偏斜和可能的解决方法的完整描述,请参阅此 https://cwiki.apache.org/confluence/display/Hive/Skewed+Join+Optimization
您还提到 table1 比 table2 小得多。您可以根据您的硬件限制尝试映射端连接。 (https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Joins)
使用这些配置并尝试
hive> set mapreduce.map.memory.mb=9000;
hive> set mapreduce.map.java.opts=-Xmx7200m;
hive> set mapreduce.reduce.memory.mb=9000;
hive> set mapreduce.reduce.java.opts=-Xmx7200m
如果您的查询卡在 99%,请查看以下选项 -
- 数据偏斜,如果你有偏斜数据,可能 1 个 reducer 正在做所有的工作
- 两侧都有重复的键 - 如果两侧都有许多重复的连接键,您的输出可能会爆炸并且查询可能会卡住
- 您的 table 中的一个很小,请尝试使用 map join 或如果可能的话 SMB join,这比 reduce side join 具有巨大的性能提升
- 转到资源管理器日志,查看作业正在访问和写入的数据量。
我遇到了类似左外连接的相同问题:
select bt.*, sm.newparam from
big_table bt
left outer join
small_table st
on bt.ident = sm.ident
and bt.cate - sm.cate
我根据已经给出的答案进行了分析,我看到了两个给定的问题:
左边 table 比右边 table
大 100 倍以上select count(*) from big_table -- returned 130M
select count(*) from small_table -- returned 1.3M
我还检测到其中一个连接变量偏向右侧 table:
select count(*), cate
from small_table
group by cate
-- returned
-- A 70K
-- B 1.1M
-- C 120K
我尝试了其他答案中给出的大部分解决方案以及我发现的一些额外参数here没有成功。:
set hive.optimize.skewjoin=true;
set hive.skewjoin.key=500000;
set hive.skewjoin.mapjoin.map.tasks=10000;
set hive.skewjoin.mapjoin.min.split=33554432;
最后我发现 left table 的连接列 的空值百分比非常高:bt.ident
和 bt.cate
所以我尝试了最后一件事,它最终对我有用:根据 bt.ident
和 bt.cate
是否为 null 拆分左侧 table,稍后制作 union all
两个分支:
select * from
(select bt.*, sm.newparam from
select * from big_table bt where ident is not null or cate is not null
left outer join
small_table st
on bt.ident = sm.ident
and bt.cate - sm.cate
union all
select *, null as newparam from big_table nbt where ident is null and cate is null) combined
确保您的数据之一中没有包含重复 ID 值的行 tables!
我最近遇到了同样的问题,左连接的 map-reduce 进程在 Hue 中卡在了 99%。
经过一番探查,我发现了问题的根源:在我的 table 之一中,有行具有重复的 member_id 匹配变量。加入所有重复的 member_id 会创建一个包含数亿行的新 table,消耗的内存超过我在公司 Hadoop 服务器上分配的内存。