简体   繁体   English

kafka-设置Java启动参数的正确方法

[英]kafka - proper way to set java startup params

There seem to be conflicting schools of thought when it comes to setting the various heap, GC, etc java params for a Kafka process. 在为Kafka进程设置各种堆,GC等Java参数时,似乎存在着不同的思想流派。

One group says to edit the kafka-server-start bash file 一组人说要编辑kafka-server-start bash文件

Another group says to set a system var and let the kafka startup pick it up 另一个小组说要设置系统变量,然后让kafka初创公司接手

In the latest instructions from Confluent the follow 'recommendations' appear: 在Confluent的最新说明中,出现以下“建议”:

-Xms6g -Xmx6g -XX:MetaspaceSize=96m -XX:+UseG1GC -XX:MaxGCPauseMillis=20
   -XX:InitiatingHeapOccupancyPercent=35 -XX:G1HeapRegionSize=16M
   -XX:MinMetaspaceFreeRatio=50 -XX:MaxMetaspaceFreeRatio=80

What's the official Confluent party-line on where to set these? 关于在哪里设置这些, Confluent官方的官方说法是什么? (I assume the defaults don't use these to accommodate smaller test machines) (我假设默认值不使用这些值来容纳较小的测试机)

Both of these things are essentially telling you to do the same thing, which is manually overriding the value of KAFKA_HEAP_OPTS . 从本质KAFKA_HEAP_OPTS ,这两种方法都告诉您执行相同的操作,即手动覆盖KAFKA_HEAP_OPTS的值。

It looks like this is what you are looking for from kafka-server-start.sh 看起来这是您在 kafka-server-start.sh 中寻找的 kafka-server-start.sh

if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
    export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"
fi

EXTRA_ARGS=${EXTRA_ARGS-'-name kafkaServer -loggc'}

If you are starting this from the command line, you can call 如果您是从命令行启动的,则可以调用

export KAFKA_HEAP_OPTS="-Xmx2g -Xms2g"
./kafka-server-start.sh

Or, if you are editing the startup script first, you do not need to export , because the variable is used locally. 或者,如果您首先编辑启动脚本,则不需要export ,因为该变量在本地使用。

KAFKA_HEAP_OPTS="-Xmx2g -Xms2g"
if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
    export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"
fi

The benefit of the first, is that it does not require changes to kafka-source, and allows for the environment to be configured via just shell variables; 第一个的好处是,它不需要更改kafka-source,并允许仅通过shell变量配置环境。

The second is convenient in that you do not need to remember to setup your environment variables before starting the server. 第二个方便之处在于,您无需记住在启动服务器之前设置环境变量。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM