Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Apache Kafka Kafka Run Class JVM Options

From Leeroopedia


Knowledge Sources
Domains Operations, JVM_Configuration
Last Updated 2026-02-09 12:00 GMT

Overview

Concrete tool for assembling JVM runtime options for Kafka processes provided by kafka-run-class.sh.

Description

The JVM configuration section of kafka-run-class.sh assembles all Java options from environment variables. It detects the Java version to select appropriate GC logging format, configures JMX for remote monitoring, sets default heap and performance options, and handles debug mode. Each option category uses a separate environment variable with sensible defaults.

Usage

Override individual environment variables before running any Kafka script to customize JVM behavior. The defaults are suitable for development; production deployments should tune heap size and GC settings.

Code Reference

Source Location

  • Repository: Apache Kafka
  • File: bin/kafka-run-class.sh
  • Lines: L201-332

Signature

# Environment variables assembled into JVM options:
# KAFKA_HEAP_OPTS         - Heap size (default: -Xmx256M)
# KAFKA_JVM_PERFORMANCE_OPTS - GC settings (default: G1GC with tuning)
# KAFKA_GC_LOG_OPTS       - GC logging (auto-detected for Java 8 vs 9+)
# KAFKA_JMX_OPTS          - JMX monitoring (enabled when JMX_PORT is set)
# KAFKA_LOG4J_OPTS        - Log4j configuration path
# KAFKA_DEBUG             - Enable Java debug agent
# JAVA_DEBUG_PORT         - Debug agent port (default: 5005)
# KAFKA_OPTS              - Additional JVM options (passthrough)

Import

# Set environment variables before running Kafka:
export KAFKA_HEAP_OPTS="-Xmx6G -Xms6G"
export JMX_PORT=9999
bin/kafka-server-start.sh config/server.properties

I/O Contract

Inputs

Name Type Required Description
KAFKA_HEAP_OPTS env No JVM heap options (default: -Xmx256M)
KAFKA_JVM_PERFORMANCE_OPTS env No GC and performance options
JMX_PORT env No Enable JMX on this port
KAFKA_DEBUG env No Enable Java debug agent
JAVA_HOME env No Java installation path

Outputs

Name Type Description
JVM options string Complete JVM command-line options for the Java process

Usage Examples

Production Broker Configuration

# Set production heap size
export KAFKA_HEAP_OPTS="-Xmx6G -Xms6G"

# Enable JMX monitoring
export JMX_PORT=9999

# Custom GC settings
export KAFKA_JVM_PERFORMANCE_OPTS="-server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35"

# Start broker
bin/kafka-server-start.sh config/server.properties

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment