Kafka Operations Troubleshooting
Quick troubleshooting guide for operational issues.
Quick Diagnosis
Section titled “Quick Diagnosis”Health Check
Section titled “Health Check”#!/bin/bashBOOTSTRAP=${1:-"localhost:9092"}
echo "=== Kafka Quick Health Check ==="
# Connectivityecho -n "Connectivity: "kafka-broker-api-versions.sh --bootstrap-server $BOOTSTRAP > /dev/null 2>&1 \ && echo "OK" || echo "FAILED"
# Offline partitionsOFFLINE=$(kafka-topics.sh --bootstrap-server $BOOTSTRAP \ --describe --unavailable-partitions 2>/dev/null | grep -c "Topic:")echo "Offline partitions: $OFFLINE"
# Under-replicatedURP=$(kafka-topics.sh --bootstrap-server $BOOTSTRAP \ --describe --under-replicated-partitions 2>/dev/null | grep -c "Topic:")echo "Under-replicated: $URP"Common Issues
Section titled “Common Issues”Issue: Under-Replicated Partitions
Section titled “Issue: Under-Replicated Partitions”Symptoms: UnderReplicatedPartitions > 0
Quick Check:
kafka-topics.sh --bootstrap-server kafka:9092 \ --describe --under-replicated-partitionsCommon Causes:
| Cause | Check | Resolution |
|---|---|---|
| Broker down | Broker connectivity | Restart broker |
| Slow broker | Disk I/O, CPU | Address bottleneck |
| Network issues | ping, netstat | Fix connectivity |
| Large messages | Message size | Increase replica.fetch.max.bytes |
Issue: Consumer Lag Growing
Section titled “Issue: Consumer Lag Growing”Symptoms: Lag increasing over time
Quick Check:
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \ --describe --group my-groupCommon Causes:
| Cause | Check | Resolution |
|---|---|---|
| Slow processing | Consumer metrics | Optimize processing |
| Too few consumers | Consumer count | Add consumers |
| Rebalancing | Group state | Fix rebalance storms |
| External dependency | External latency | Add buffering |
Issue: Producer Timeouts
Section titled “Issue: Producer Timeouts”Symptoms: TimeoutException in producer
Quick Check:
# Check broker healthkafka-broker-api-versions.sh --bootstrap-server kafka:9092
# Check partition leaderskafka-topics.sh --bootstrap-server kafka:9092 \ --describe --topic my-topicCommon Causes:
| Cause | Check | Resolution |
|---|---|---|
| Broker unavailable | Broker status | Restart broker |
| No leader | Partition describe | Wait for election |
| ISR too small | min.insync.replicas | Fix broker health |
| Network issues | Connectivity | Fix network |
Issue: Frequent Rebalances
Section titled “Issue: Frequent Rebalances”Symptoms: Consumers constantly rebalancing
Quick Check:
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \ --describe --group my-group --stateCommon Causes:
| Cause | Check | Resolution |
|---|---|---|
| Session timeout | Processing time | Increase max.poll.interval.ms |
| Consumer crashes | Consumer logs | Fix stability |
| Heartbeat issues | Network | Check connectivity |
| GC pauses | GC logs | Tune JVM |
Resolution:
# Increase timeoutsmax.poll.interval.ms=600000session.timeout.ms=45000heartbeat.interval.ms=3000
# Use cooperative rebalancingpartition.assignment.strategy=org.apache.kafka.clients.consumer.CooperativeStickyAssignor
# Static membershipgroup.instance.id=consumer-1Issue: High Latency
Section titled “Issue: High Latency”Symptoms: Request latency exceeds SLA
Quick Check:
# Check broker metrics# kafka.network:type=RequestMetrics,name=TotalTimeMsCommon Causes:
| Cause | Check | Resolution |
|---|---|---|
| Disk I/O | iostat | Faster disks |
| Network | netstat, ping | Fix network |
| GC pauses | GC logs | Tune JVM |
| Request queue | RequestQueueTimeMs | More network threads |
Issue: Disk Full
Section titled “Issue: Disk Full”Symptoms: No space left on device
Quick Check:
df -h /var/kafka-logsdu -sh /var/kafka-logs/*Resolution:
# Reduce retentionkafka-configs.sh --bootstrap-server kafka:9092 \ --entity-type topics --entity-name big-topic \ --alter --add-config retention.ms=86400000
# Delete old topicskafka-topics.sh --bootstrap-server kafka:9092 \ --delete --topic unused-topic
# Add storage# Mount additional diskLog Analysis
Section titled “Log Analysis”Find Errors
Section titled “Find Errors”# Recent errorsgrep "ERROR" /var/log/kafka/server.log | tail -50
# Specific exceptiongrep "OutOfMemoryError" /var/log/kafka/server.log
# Time-based searchgrep "2024-01-15 10:" /var/log/kafka/server.log | grep ERRORKey Patterns
Section titled “Key Patterns”| Pattern | Meaning | Action |
|---|---|---|
OutOfMemoryError | Heap exhausted | Increase heap |
KafkaStorageException | Disk failure | Check disk |
NotLeaderOrFollower | Stale metadata | Usually transient |
ISR shrunk | Replica fell behind | Check broker |
Emergency Procedures
Section titled “Emergency Procedures”Broker Won’t Start
Section titled “Broker Won’t Start”# Check for port conflictnetstat -tlnp | grep 9092
# Check log for errorstail -100 /var/log/kafka/server.log | grep -E "ERROR|FATAL"
# Verify disk spacedf -h /var/kafka-logs
# Check file descriptorsulimit -nOffline Partitions
Section titled “Offline Partitions”# Identify offline partitionskafka-topics.sh --bootstrap-server kafka:9092 \ --describe --unavailable-partitions
# Check replica statuskafka-topics.sh --bootstrap-server kafka:9092 \ --describe --topic affected-topic
# If broker recoverable, restart it# If not, consider unclean election (data loss risk)kafka-leader-election.sh --bootstrap-server kafka:9092 \ --election-type unclean \ --topic affected-topic --partition 0Consumer Group Stuck
Section titled “Consumer Group Stuck”# Check group statekafka-consumer-groups.sh --bootstrap-server kafka:9092 \ --describe --group stuck-group --state
# Force delete (consumers must be stopped)kafka-consumer-groups.sh --bootstrap-server kafka:9092 \ --delete --group stuck-group
# Recreate with offset reset if neededRelated Documentation
Section titled “Related Documentation”- Troubleshooting Guide - Complete troubleshooting
- Common Errors - Error reference
- Log Analysis - Log interpretation
- Monitoring - Metrics and alerting