Apache Kafka Streaming (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Tuning JVM Garbage Collection (G1GC) and Linux Kernel Parameters for Kafka Brokers.
senior LevelMemory ManagementSystem DesignApache Kafka
In Simple Words: Brokers require optimized OS kernel memory and disk flushing parameters:
Linux Kernel (/etc/sysctl.conf):
vm.dirty_background_ratio = 5: Begins background flushing of dirty page cache pages to disk when dirty memory reaches 5% of RAM.vm.dirty_ratio = 10: Blocks incoming writes if dirty memory reaches 10% until disk flushes catch up. Prevents massive I/O stalls.vm.swappiness = 1: Prevents the OS kernel from aggressively swapping Kafka JVM heap memory to disk.
JVM GC Flags:
- Keep broker JVM heap modest (typically 16GB to 32GB maximum) using G1GC with
-XX:MaxGCPauseMillis=20. Allow the remaining host RAM (e.g., 64GB-128GB) to be used exclusively by the Linux OS Page Cache.