cp-docker-images icon indicating copy to clipboard operation
cp-docker-images copied to clipboard

Kafka Docker - How to increase memory settings

Open Tin-Nguyen opened this issue 5 years ago • 6 comments

I'm using Confluent Kafka image to run Kafka via docker container on my machine. the kafka broker is often hang and unable to be connected when I did run some tests. It doesn't back to work normally even I killed the container and re-inited it or restarted Docker, etc... I had to use Reset to Factory default , then init the docker container again to make it back to work normally.

It takes my time. I dig into investigating the problem and figured out it may be caused by the memory configuration in the Java process running Kafka

java -Xmx1G -Xms1G -server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+ExplicitGCInvokesConcurrent -Djava.awt.headless=true -Xloggc:/var/log/kafka/kafkaServer-gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dkafka.logs.dir=/var/log/kafka -Dlog4j.configuration=file:/etc/kafka/log4j.properties -cp /usr/bin/../share/java/kafka/*:/usr/bin/../share/java/confluent-support-metrics/*:/usr/share/java/confluent-support-metrics/* io.confluent.support.metrics.SupportedKafka /etc/kafka/kafka.properties

It seems 1Gb memory isn't enough and made the kafka in the container hang. I'm looking for a way to increase that configuration to be higher. Anyone knows which ENV var or configuration helps to do that?

Tin-Nguyen avatar Jun 06 '19 08:06 Tin-Nguyen

KAFKA_HEAP_OPTS - https://github.com/apache/kafka/blob/trunk/bin/kafka-run-class.sh#L231-L239

OneCricketeer avatar Jul 25 '19 16:07 OneCricketeer

KAFKA_HEAP_OPTS - https://github.com/apache/kafka/blob/trunk/bin/kafka-run-class.sh#L231-L239

how to pass this option to the docker image of the confluent Kafka?

ethicalmohit avatar Oct 09 '19 16:10 ethicalmohit

That's the environment variable name, so pass it like all the others

OneCricketeer avatar Oct 09 '19 16:10 OneCricketeer

That's the environment variable name, so pass it like all the others

KAFKA_HEAP_OPTS="-Xmx512M -Xms512M"

I passed it and I am getting below error.

===> Launching kafka ...
hostname: Name or service not known
Error: Could not find or load main class "-Xmx512M

ethicalmohit avatar Oct 09 '19 16:10 ethicalmohit

Should work, there's an example here that also logs JVM events out to a directory

https://docs.confluent.io/current/installation/docker/development.html#write-garbage-collection-logs-to-an-external-volume

OneCricketeer avatar Oct 09 '19 16:10 OneCricketeer

Should work, there's an example here that also logs JVM events out to a directory

https://docs.confluent.io/current/installation/docker/development.html#write-garbage-collection-logs-to-an-external-volume

@cricket007 This works. KAFKA_HEAP_OPTS=-Xmx512M -Xms512M without the double quote. Thanks.

ethicalmohit avatar Oct 09 '19 19:10 ethicalmohit