Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the Java options for Kafka?

I've been experimenting with Kafka and saw from the documentation on the main site that you're able to set different options for the jvm like heap size and the garbage collector that it uses:

http://kafka.apache.org/documentation.html#java

What it doesn't say, however, is how/where to set these options. The application comes with a /config directory containing a lot of files used for configuration purposes but none that are for Java. It also comes with a /bin directory containing a bunch of scripts for Kafka but again, nothing really indicating how to configure Java.

So my question is, how do I configure the Java options that Kafka uses? Is it done through a file or is there a different way?

like image 830
Luis Medina Avatar asked Dec 28 '14 23:12

Luis Medina


People also ask

Does Kafka need JVM?

Kafka uses heap space very carefully and does not require setting heap sizes more than 5GB. Kafka uses page cache memory as a buffer for active writers and readers, so after you specify JVM size (using -Xmx and -Xms Java options), leave the remaining RAM available to the operating system for page caching.


2 Answers

Modifying a script in the bin directory is highly unrecommended. When upgrading Kafka to the next version, extracting the new binaries would override the changes made in the script.

The preferred way should be to set the environment variable KAFKA_HEAP_OPTS outside the script.

export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"

If the var is set before starting Kafka via the script it will use the var instead of the default values defined in /bin/kafka-server-start.sh

like image 161
benny.la Avatar answered Sep 20 '22 13:09

benny.la


Another way to do this is by modifying information written in /bin/kafka-server-start.sh:

export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G" 

or in /bin/kafka-run-class.sh:

KAFKA_JVM_PERFORMANCE_OPTS="-server -XX:+UseCompressedOops -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:+DisableExplicitGC -Djava.awt.headless=true" 
like image 45
Salvador Dali Avatar answered Sep 18 '22 13:09

Salvador Dali