简体   繁体   English

Hive:java.lang.OutOfMemoryError:Java堆空间和正在运行的作业(本地Hadoop)

[英]Hive: java.lang.OutOfMemoryError: Java heap space and Job running in-process (local Hadoop)

My setup: 4 node cluster in Google Cloud Platform (1 master, 3 workers) running NixOS Linux. 我的设置:运行NixOS Linux的Google Cloud Platform中的4个节点集群(1个主服务器,3个工作人员)。

I have been using the TPC-DS toolkit to generate both data and queries are standard. 我一直在使用TPC-DS工具包来生成数据和查询都是标准的。 On smaller dataset / more simpler queries they work just fine. 在较小的数据集/更简单的查询上,它们可以正常工作。 The queries I take from here: https://github.com/hortonworks/hive-testbench/tree/hdp3/sample-queries-tpcds 我从这里得到的查询: https//github.com/hortonworks/hive-testbench/tree/hdp3/sample-queries-tpcds

This is the first one, query1.sql : 这是第一个, query1.sql

WITH customer_total_return AS 
( 
         SELECT   sr_customer_sk AS ctr_customer_sk , 
                  sr_store_sk    AS ctr_store_sk , 
                  Sum(sr_fee)    AS ctr_total_return 
         FROM     store_returns , 
                  date_dim 
         WHERE    sr_returned_date_sk = d_date_sk 
         AND      d_year =2000 
         GROUP BY sr_customer_sk , 
                  sr_store_sk) 
SELECT   c_customer_id 
FROM     customer_total_return ctr1 , 
         store , 
         customer 
WHERE    ctr1.ctr_total_return > 
         ( 
                SELECT Avg(ctr_total_return)*1.2 
                FROM   customer_total_return ctr2 
                WHERE  ctr1.ctr_store_sk = ctr2.ctr_store_sk) 
AND      s_store_sk = ctr1.ctr_store_sk 
AND      s_state = 'NM' 
AND      ctr1.ctr_customer_sk = c_customer_sk 
ORDER BY c_customer_id limit 100;

At first I had the problem of not being able to run this at all to success, running into java.lang.OutOfMemoryError: Java heap space . 起初我遇到的问题是无法运行这个成功,遇到java.lang.OutOfMemoryError: Java heap space

What I did was: 我做的是:

  1. Increased GCP nodes power (up to 7.5 gb of RAM and dual core CPUs) 增加GCP节点功率(高达7.5 GB的RAM和双核CPU)
  2. Set these variables inside of the Hive CLI: 在Hive CLI中设置这些变量:
set mapreduce.map.memory.mb=2048;
set mapreduce.map.java.opts=-Xmx1024m;
set mapreduce.reduce.memory.mb=4096;
set mapreduce.reduce.java.opts=-Xmxe3072m;
set mapred.child.java.opts=-Xmx1024m;

  1. Restarted Hive 重新启动Hive

Then this query worked (along other similar ones) when it came to a 1 GB dataset. 然后,当涉及1 GB数据集时,此查询(与其他类似的查询)一起工作。 I've monitored the situation with htop and the memory usage does not exceed 2gb while both CPU cores are used to 100% almost constantly. 我用htop监视了这种情况,内存使用量不超过2GB,而两个CPU核心几乎不断地使用100%。

Now the problem is, when it comes to more complex queries with larger dataset, the error starts again: 现在问题是,当涉及到具有更大数据集的更复杂查询时,错误再次开始:

The query runs just fine for an entire minute or so, but ends in a FAIL. 查询运行一整分钟左右,但以FAIL结束。 Full stacktrace: 完整的堆栈跟踪:

hive> with customer_total_return as
    > (select sr_customer_sk as ctr_customer_sk
    > ,sr_store_sk as ctr_store_sk
    > ,sum(SR_FEE) as ctr_total_return
    > from store_returns
    > ,date_dim
    > where sr_returned_date_sk = d_date_sk
    > and d_year =2000
    > group by sr_customer_sk
    > ,sr_store_sk)
    >  select c_customer_id
    > from customer_total_return ctr1
    > ,store
    > ,customer
    > where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2
    > from customer_total_return ctr2
    > where ctr1.ctr_store_sk = ctr2.ctr_store_sk)
    > and s_store_sk = ctr1.ctr_store_sk
    > and s_state = 'TN'
    > and ctr1.ctr_customer_sk = c_customer_sk
    > order by c_customer_id
    > limit 100;
No Stats for default@store_returns, Columns: sr_returned_date_sk, sr_fee, sr_store_sk, sr_customer_sk
No Stats for default@date_dim, Columns: d_date_sk, d_year
No Stats for default@store, Columns: s_state, s_store_sk
No Stats for default@customer, Columns: c_customer_sk, c_customer_id
Query ID = root_20190811164854_c253c67c-ef94-4351-b4d3-74ede4c5d990
Total jobs = 14
Stage-29 is selected by condition resolver.
Stage-1 is filtered out by condition resolver.
Stage-30 is selected by condition resolver.
Stage-10 is filtered out by condition resolver.
SLF4J: Found binding in [jar:file:/nix/store/jjm6636r99r0irqa03dc1za9gs2b4fx6-source/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/nix/store/q9jpwzbqbg8k8322q785xfavg0p0v18i-hadoop-3.1.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
Execution completed successfully
MapredLocal task succeeded
SLF4J: Found binding in [jar:file:/nix/store/jjm6636r99r0irqa03dc1za9gs2b4fx6-source/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/nix/store/q9jpwzbqbg8k8322q785xfavg0p0v18i-hadoop-3.1.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Execution completed successfully
MapredLocal task succeeded
Launching Job 3 out of 14
Number of reduce tasks is set to 0 since there's no reduce operator
Job running in-process (local Hadoop)
2019-08-11 16:49:19,415 Stage-20 map = 0%,  reduce = 0%
2019-08-11 16:49:22,418 Stage-20 map = 100%,  reduce = 0%
Ended Job = job_local404291246_0005
Launching Job 4 out of 14
Number of reduce tasks is set to 0 since there's no reduce operator
Job running in-process (local Hadoop)
2019-08-11 16:49:24,718 Stage-22 map = 0%,  reduce = 0%
2019-08-11 16:49:27,721 Stage-22 map = 100%,  reduce = 0%
Ended Job = job_local566999875_0006
Launching Job 5 out of 14
Number of reduce tasks not specified. Estimated from input data size: 1
In order to change the average load for a reducer (in bytes):
  set hive.exec.reducers.bytes.per.reducer=<number>
In order to limit the maximum number of reducers:
  set hive.exec.reducers.max=<number>
In order to set a constant number of reducers:
  set mapreduce.job.reduces=<number>
Job running in-process (local Hadoop)
2019-08-11 16:49:29,958 Stage-2 map = 0%,  reduce = 0%
2019-08-11 16:49:33,970 Stage-2 map = 100%,  reduce = 0%
2019-08-11 16:49:35,974 Stage-2 map = 100%,  reduce = 100%
Ended Job = job_local1440279093_0007
Launching Job 6 out of 14
Number of reduce tasks not specified. Estimated from input data size: 1
In order to change the average load for a reducer (in bytes):
  set hive.exec.reducers.bytes.per.reducer=<number>
In order to limit the maximum number of reducers:
  set hive.exec.reducers.max=<number>
In order to set a constant number of reducers:
  set mapreduce.job.reduces=<number>
Job running in-process (local Hadoop)
2019-08-11 16:49:37,235 Stage-11 map = 0%,  reduce = 0%
2019-08-11 16:49:40,421 Stage-11 map = 100%,  reduce = 0%
2019-08-11 16:49:42,424 Stage-11 map = 100%,  reduce = 100%
Ended Job = job_local1508103541_0008
SLF4J: Found binding in [jar:file:/nix/store/jjm6636r99r0irqa03dc1za9gs2b4fx6-source/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/nix/store/q9jpwzbqbg8k8322q785xfavg0p0v18i-hadoop-3.1.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

2019-08-11 16:49:51 Dump the side-table for tag: 1 with group count: 21 into file: file:/tmp/root/3ab30b3b-380d-40f5-9f72-68788d998013/hive_2019-08-11_16-48-54_393_105456265244058313-1/-local-10019/HashTable-Stage-19/MapJoin-mapfile71--.hashtable
Execution completed successfully
MapredLocal task succeeded
Launching Job 7 out of 14
Number of reduce tasks is set to 0 since there's no reduce operator
Job running in-process (local Hadoop)
2019-08-11 16:49:53,956 Stage-19 map = 100%,  reduce = 0%
Ended Job = job_local2121921517_0009
Stage-26 is filtered out by condition resolver.
Stage-27 is selected by condition resolver.
Stage-4 is filtered out by condition resolver.

2019-08-11 16:50:01 Dump the side-table for tag: 0 with group count: 99162 into file: file:/tmp/root/3ab30b3b-380d-40f5-9f72-68788d998013/hive_2019-08-11_16-48-54_393_105456265244058313-1/-local-10017/HashTable-Stage-17/MapJoin-mapfile60--.hashtable
2019-08-11 16:50:02 Uploaded 1 File to: file:/tmp/root/3ab30b3b-380d-40f5-9f72-68788d998013/hive_2019-08-11_16-48-54_393_105456265244058313-1/-local-10017/HashTable-Stage-17/MapJoin-mapfile60--.hashtable (2832042 bytes)
Execution completed successfully
MapredLocal task succeeded
Launching Job 9 out of 14
Number of reduce tasks is set to 0 since there's no reduce operator
Job running in-process (local Hadoop)
2019-08-11 16:50:04,004 Stage-17 map = 0%,  reduce = 0%
2019-08-11 16:50:05,005 Stage-17 map = 100%,  reduce = 0%
Ended Job = job_local694362009_0010
Stage-24 is selected by condition resolver.
Stage-25 is filtered out by condition resolver.
Stage-5 is filtered out by condition resolver.

SLF4J: Found binding in [jar:file:/nix/store/q9jpwzbqbg8k8322q785xfavg0p0v18i-hadoop-3.1.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
2019-08-11 16:50:12 Starting to launch local task to process map join;  maximum memory = 239075328
Execution completed successfully
MapredLocal task succeeded
Launching Job 11 out of 14
Number of reduce tasks is set to 0 since there's no reduce operator
Job running in-process (local Hadoop)
2019-08-11 16:50:14,254 Stage-13 map = 100%,  reduce = 0%
Ended Job = job_local1812693452_0011
Launching Job 12 out of 14
Number of reduce tasks determined at compile time: 1
In order to change the average load for a reducer (in bytes):
  set hive.exec.reducers.bytes.per.reducer=<number>
In order to limit the maximum number of reducers:
  set hive.exec.reducers.max=<number>
In order to set a constant number of reducers:
  set mapreduce.job.reduces=<number>
Job running in-process (local Hadoop)
2019-08-11 16:50:15,481 Stage-6 map = 0%,  reduce = 0%
Ended Job = job_local920309638_0012 with errors
Error during job, obtaining debugging information...
FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask
MapReduce Jobs Launched: 
Stage-Stage-20:  HDFS Read: 8662606197 HDFS Write: 0 SUCCESS
Stage-Stage-22:  HDFS Read: 9339349675 HDFS Write: 0 SUCCESS
Stage-Stage-2:  HDFS Read: 9409277766 HDFS Write: 0 SUCCESS
Stage-Stage-11:  HDFS Read: 9409277766 HDFS Write: 0 SUCCESS
Stage-Stage-19:  HDFS Read: 4704638883 HDFS Write: 0 SUCCESS
Stage-Stage-17:  HDFS Read: 4771516428 HDFS Write: 0 SUCCESS
Stage-Stage-13:  HDFS Read: 4771516428 HDFS Write: 0 SUCCESS
Stage-Stage-6:  HDFS Read: 0 HDFS Write: 0 FAIL
Total MapReduce CPU Time Spent: 0 msec

The problem in the hive.log file is still the same: hive.log文件中的问题仍然相同:

java.lang.Exception: java.lang.OutOfMemoryError: Java heap space

And I realized my worker nodes don't actually do anything (htop showed that they were idle while only the master node was working) Even in the stack trace: 我意识到我的工作节点实际上并没有做任何事情(htop显示它们在空闲时只有主节点工作)即使在堆栈跟踪中:

Job running in-process (local Hadoop)

How can I make Hive use HDFS not just Local Hadoop? 如何让Hive使用HDFS而不仅仅是本地Hadoop? Running hdfs dfs -df -h hdfs:<redacted>:9000/ returns 运行hdfs dfs -df -h hdfs:<redacted>:9000/返回

Filesystem                   Size    Used  Available  Use%
hdfs://<redacted>:9000  88.5 G  34.3 G     35.2 G   39%

Which is correct, I have 3 worker nodes, each with 30 GB disks. 哪个是正确的,我有3个工作节点,每个节点有30 GB磁盘。

java.lang.OutOfMemoryError: Java heap space It will happen if you are trying to push too much data on the single machine. java.lang.OutOfMemoryError: Java heap space如果您尝试在单个计算机上推送过多数据,则会发生这种情况。

Based on the query provided, there are few things that you can try: 根据提供的查询,您可以尝试以下几种方法:

  1. Change your join conditions to explicit (remove WHERE CLAUSE and use INNER/LEFT JOIN ). 将您的连接条件更改为显式(删除WHERE CLAUSE并使用INNER / LEFT JOIN )。 eg 例如
FROM     customer_total_return ctr1 
         INNER JOIN store s
             ON ctr1.ctr_store_sk = s.s_store_sk
                AND s_state = 'NM'
         INNER JOIN customer c
             ON ctr1.ctr_customer_sk = c.c_customer_sk
  1. Check if you have skewed data for one of the following fields: 检查以下字段之一是否存在偏差数据:
    1. store_returns -> sr_returned_date_sk store_returns - > sr_returned_date_sk
    2. store_returns -> sr_store_sk store_returns - > sr_store_sk
    3. store_returns -> sr_customer_sk store_returns - > sr_customer_sk
    4. customer -> c_customer_sk 客户 - > c_customer_sk
    5. store -> s_store_sk 商店 - > s_store_sk

It might be possible the one of the KEY has high percent of values and that might cause 1 of the node to be overloaded (when data size is huge). 有可能其中一个KEY具有高百分比的值,并且可能导致1个节点过载(当数据大小很大时)。

Basically you are trying eliminate possible reasons of node overloading. 基本上你正在尝试消除节点重载的可能原因。

Let me know if it helps. 如果有帮助,请告诉我。

It could be resource issue. 这可能是资源问题。 Hive queries are internally executed as Map-Reduce jobs. Hive查询在内部执行为Map-Reduce作业。 You could check the Job History logs for the Hive Map-Reduce jobs failed. 您可以检查Hive Map-Reduce作业的作业历史记录日志失败。 Sometimes executing queries from shell are faster compared to the Hive-Query editor. 与Hive-Query编辑器相比,有时从shell执行查询更快。

OOM issues are related to query performance most of the time. OOM问题大多数时候都与查询性能有关。

There are two queries here: 这里有两个查询:

Part 1: 第1部分:

WITH customer_total_return AS 

( 
         SELECT   sr_customer_sk AS ctr_customer_sk , 
                  sr_store_sk    AS ctr_store_sk , 
                  Sum(sr_fee)    AS ctr_total_return 
         FROM     store_returns , 
                  date_dim 
         WHERE    sr_returned_date_sk = d_date_sk 
         AND      d_year =2000 
         GROUP BY sr_customer_sk , 
                  sr_store_sk)

Part 2: 第2部分:

SELECT   c_customer_id 
FROM     customer_total_return ctr1 , 
         store , 
         customer 
WHERE    ctr1.ctr_total_return > 
         ( 
                SELECT Avg(ctr_total_return)*1.2 
                FROM   customer_total_return ctr2 
                WHERE  ctr1.ctr_store_sk = ctr2.ctr_store_sk) 

AND      s_store_sk = ctr1.ctr_store_sk 
AND      s_state = 'NM' 
AND      ctr1.ctr_customer_sk = c_customer_sk 
ORDER BY c_customer_id limit 100;

Try enabling JMX for the hive cluster link 尝试为hive群集链接启用JMX

And see the memory usage of both the parts of query. 并查看查询部分的内存使用情况。 And the part2 inner query also. 而且part2内部查询也是。

Few hive optimizations for above queries can be tried out: 可以尝试对上述查询进行很少的hive优化:

  1. Use SORT BY instead of ORDER BY Clause -> SORT BY clause, that orders the data only within each reducer. 使用SORT BY代替ORDER BY子句 - > SORT BY子句,它仅在每个reducer中对数据进行排序

  2. Partition the tables on the join keys to read only specific data instead of whole table scan. 对连接键上的表进行分区以仅读取特定数据而不是整个表扫描。

  3. cache the small hive table in distributed cache and use map side join to reduce the shuffling For example: 将小hive表缓存在分布式缓存中并使用map side join来减少shuffling例如:

select /*+MAPJOIN(b)*/ col1,col2,col3,col4 from table_A a join table_B b on a.account_number=b.account_number

  1. If there is a possibility of skew data in any of the tables then use following parameters: 如果任何表中存在偏斜数据的可能性,则使用以下参数:

set hive.optimize.skewjoin=true; set hive.skewjoin.key=100000; (ie the threshold of the data should go to one node) (即数据的阈值应该转到一个节点)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.OutOfMemoryError:带有配置单元的 Java 堆空间 - java.lang.OutOfMemoryError: Java heap space with hive 优化 Hive 查询。 java.lang.OutOfMemoryError: Java 堆空间/GC 开销限制超出 - Optimize Hive Query. java.lang.OutOfMemoryError: Java heap space/GC overhead limit exceeded java.lang.OutOfMemoryError:批量插入mysql数据库期间Java堆空间错误? - java.lang.OutOfMemoryError: Java heap space error during bulk insert to mysql database? java.lang.OutOfMemoryError:Java 堆空间(“-Xmx1280M”) - java.lang.OutOfMemoryError: Java heap space (“-Xmx1280M”) 如何解决这个OutOfMemoryError:Java堆空间 - how to solve this OutOfMemoryError: Java heap space SPARK SQL java.lang.OutOfMemoryError:超出GC开销限制 - SPARK SQL java.lang.OutOfMemoryError: GC overhead limit exceeded Java.lang.OutOfMemoryError: null 同时写入 BufferedOutputStream - Java.lang.OutOfMemoryError: null while writing on BufferedOutputStream ExecuteQuery:Java 堆空间不足 - ExecuteQuery: Java out of Heap Space 如果我在sql而不是&#39;in&#39;中使用&#39;或&#39;,那么Java会出现堆空间错误 - Java out of heap space error if I use 'or' in sql instead of 'in' 在HIVE SQL上使用cte时出错 - java.lang - Error using cte on HIVE SQL - java.lang
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM