kafka 8与内存 - Java运行环境的内存不足,无法继续。

33

我正在使用512兆内存的DigiOcean实例,使用kafka时出现以下错误。我不是一名熟练的Java开发人员。如何调整kafka以利用少量内存?这是一个开发服务器。我不想为更大的机器支付更多的费用。

#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 986513408 bytes for committing reserved memory.
# An error report file with more information is saved as:
# //hs_err_pid6500.log
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000bad30000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)
7个回答

73

您可以通过编辑kafka-server-start.shzookeeper-server-start.sh等文件来调整JVM堆大小:

export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"

-Xms参数指定最小堆大小。为了确保您的服务器至少启动,请尝试将其更改为使用较少的内存。考虑到您只有512M,您还应该更改最大堆大小(-Xmx):

export KAFKA_HEAP_OPTS="-Xmx256M -Xms128M"

我不确定kafka在默认配置下的最小内存要求是多少 - 也许您需要调整kafka中的消息大小才能使其运行。


1

领域:热点 / 垃圾回收

简介

Crashes due to failure to allocate large pages.

On Linux, failures when allocating large pages can lead to crashes. When running JDK 7u51 or later versions, the issue can be recognized in two ways:

    Before the crash happens, one or more lines similar to the following example will have been printed to the log:

    os::commit_memory(0x00000006b1600000, 352321536, 2097152, 0) failed;
    error='Cannot allocate memory' (errno=12); Cannot allocate large pages, 
    falling back to regular pages

    If a file named hs_err is generated, it will contain a line similar to the following example:

    Large page allocation failures have occurred 3 times

The problem can be avoided by running with large page support turned off, for example, by passing the "-XX:-UseLargePages" option to the java binary.

1

添加环境变量JAVA_OPTS。

在Linux中,编辑~/.bashrc文件,并最好对其进行源。

export JAVA_OPTS="$JAVA_OPTS -Xms128M -Xmx128M"

在Windows中,添加系统变量。
JAVA_OPTS "-Xms128M -Xmx128M"

然后重新启动。

如果不起作用,需要更改许多文件,例如bin/kafka-server-start.shconfig/server.properties。在这些文件中减少数字。


0
在您的环境变量中将Java路径更改为JDK64而不是JDK32。这解决了我的问题,我拥有64GB的内存并使用32位JVM,将路径更改为JDK64(64位JVM)解决了问题。

0
针对我的情况,我之前一直在使用Android Studio开发Android应用,并且一整夜都在运行虚拟机。当我尝试启动Apache Kafka服务器时,我才意识到出现了错误。我重启了电脑以释放内存,然后重新启动Kafka服务器。希望这能够帮助到其他人!

0

这里的答案也可以用于在运行Kafka的Docker容器中解决同样的问题。

只需将以下ENV变量添加到您的docker-compose文件(或运行脚本)中:

KAFKA_HEAP_OPTS: "-Xmx512M -Xms256M"

当然,您应该调整您的托管机器资源可用性上的值。


0
在AWS上遇到了相同的错误。我发现我至少需要一个t2.medium才能让我的broker和zookeeper正常工作。

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