Skip to content

Kafka Best Practices + how to set recommended setting for JVM

A recommended setting for JVM looks like following

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

my question is – How do I set the above Java options for Kafka?

I know for sure that we can set

export KAFKA_HEAP_OPTS="-Xmx8G -Xms8G"

but not sure if we can append the whole line

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

to KAFKA_HEAP_OPTS variable

reference –



you can check, here you can see what env variables kafka uses to start the java process:


and then it run the java application passing them:


basically the content of the env variables are just appended as is to the command, it does not really matter where you put the settings as soon as the jvm parameters are in the correct order.

So, you can simply change $KAFKA_HEAP_OPTS however to keep the variable names consistent with their content I would put -Xmx8g -Xms8g in KAFKA_HEAP_OPTS and the remaining optimization to KAFKA_JVM_PERFORMANCE_OPTS.