Java堆空间不足错误:在Hive中发生

12

我使用的是hadoop hive 0.9.0和1.1.2以及netbeans, 但是我遇到了这个错误,而且我无法解决这个问题。 请帮帮我。 代码:

public class Hive_test {

private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";

   @SuppressWarnings("CallToThreadDumpStack")
public static void main(String[] args) throws SQLException {
    try {
        Class.forName(driverName);
    } catch (ClassNotFoundException e){
        e.printStackTrace();
        System.exit(1);
    }
            System.out.println("commencer la connexion");
    Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default",""," ");
    Statement stmt = con.createStatement();
    ResultSet res = stmt.executeQuery("select * from STATE");
    while (res.next()){
        System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
                    System.out.println("sql terminer");
    }
}

以下为错误信息:

error :
commencer la connexion
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at org.apache.thrift.protocol.TBinaryProtocol.readStringBody(TBinaryProtocol.java:353)
    at org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:215)
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:69)
    at org.apache.hadoop.hive.service.ThriftHive$Client.recv_execute(ThriftHive.java:116)
    at org.apache.hadoop.hive.service.ThriftHive$Client.execute(ThriftHive.java:103)
    at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:192)
    at org.apache.hadoop.hive.jdbc.HiveStatement.execute(HiveStatement.java:132)
    at org.apache.hadoop.hive.jdbc.HiveConnection.configureConnection(HiveConnection.java:132)
    at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:122)
    at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:106)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at hive.Hive_test.main(Hive_test.java:22)

你尝试过使用更多内存吗?使用 -Xmx 参数。 - Jayan
@Jayan 不好意思,我不知道怎么做,因为我使用的是NetBeans。 - kawther
3个回答

25

您可以在Hive中设置容器堆大小并解决此错误:

大多数在Hadoop MapReduce框架上运行的工具都提供了调整其作业的Hadoop级别设置的方法。在Hive中有多种方法可以实现这一点,其中三种如下所示:

1)直接通过Hive命令行传递它:

hive -hiveconf mapreduce.map.memory.mb=4096 -hiveconf mapreduce.reduce.memory.mb=5120 -e "select count(*) from test_table;"

2) 调用Hive之前设置ENV变量:

export HIVE_OPTS="-hiveconf mapreduce.map.memory.mb=4096 -hiveconf mapreduce.reduce.memory.mb=5120"

3) 在 hive CLI 中使用 "set" 命令。

hive> set mapreduce.map.memory.mb=4096;
hive> set mapreduce.reduce.memory.mb=5120;
hive> select count(*) from test_table;

我该如何在Hive中设置容器堆大小?我使用NetBeans,请帮忙。 - kawther
这个设置对于Java的GC超时限制错误没有帮助,我说得对吗? - Reihan_amn

6

对于我的情况,我还需要在java.opts中设置内存。

set mapreduce.map.memory.mb=4096;
set mapreduce.map.java.opts=-Xmx3686m;
set mapreduce.reduce.memory.mb=4096;
set mapreduce.reduce.java.opts=-Xmx3686m;

5

对我而言,以下解决方案可行。
在启动hive CLI之前使用export HADOOP_CLIENT_OPTS="-Xmx8192m",然后启动CLI。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接