┌─────────────────────────────────────────────────────────────────┐
│ Kafka Performance Tuning Areas │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Broker │ │ Producer │ │ Consumer │ │
│ │ - 스레드 설정 │ │ - 배치 설정 │ │ - Fetch 설정 │ │
│ │ - 메모리 설정 │ │ - 압축 설정 │ │ - 처리 설정 │ │
│ │ - 디스크 I/O │ │ - 버퍼 설정 │ │ - 병렬 처리 │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Network │ │ OS │ │ JVM │ │
│ │ - 소켓 버퍼 │ │ - 파일 시스템 │ │ - 힙 크기 │ │
│ │ - 연결 관리 │ │ - 커널 파라미터│ │ - GC 설정 │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
Broker 튜닝
스레드 설정
# server.properties# 네트워크 스레드 (클라이언트 요청 처리)# 권장: CPU 코어 수 또는 그 이상num.network.threads=8# I/O 스레드 (디스크 읽기/쓰기)# 권장: 디스크 수 * 2 ~ 디스크 수 * 8num.io.threads=16# 복제 스레드num.replica.fetchers=4# 백그라운드 스레드background.threads=10
메모리 설정
# 소켓 버퍼socket.send.buffer.bytes=102400 # 100KBsocket.receive.buffer.bytes=102400 # 100KBsocket.request.max.bytes=104857600 # 100MB# 로그 플러시 (성능 vs 내구성 트레이드오프)log.flush.interval.messages=10000log.flush.interval.ms=1000# 메시지 최대 크기message.max.bytes=10485760 # 10MBreplica.fetch.max.bytes=10485880 # 약간 더 큰 값
복제 설정
# 복제 처리량 조절replica.fetch.wait.max.ms=500replica.fetch.min.bytes=1# ISR 관리replica.lag.time.max.ms=30000# 리더 밸런싱auto.leader.rebalance.enable=trueleader.imbalance.check.interval.seconds=300leader.imbalance.per.broker.percentage=10
로그 관리
# 세그먼트 크기 (작을수록 빠른 삭제)log.segment.bytes=1073741824 # 1GB# 인덱스 크기log.index.size.max.bytes=10485760 # 10MBlog.index.interval.bytes=4096# Retentionlog.retention.hours=168log.retention.bytes=-1log.cleanup.policy=delete
Producer 튜닝
처리량 최적화
Properties props = new Properties();// 배치 설정 (처리량 ↑)props.put("batch.size", 65536); // 64KB (기본 16KB)props.put("linger.ms", 10); // 10ms 대기props.put("buffer.memory", 67108864); // 64MB 버퍼// 압축 (네트워크 ↓, CPU ↑)props.put("compression.type", "lz4"); // lz4 권장 (빠름)// 병렬 처리props.put("max.in.flight.requests.per.connection", 5);// acks 설정 (처리량 vs 내구성)props.put("acks", "1"); // 리더만 확인 (빠름)// props.put("acks", "all"); // 모든 ISR 확인 (안전)
지연 시간 최적화
Properties props = new Properties();// 즉시 전송 (지연 시간 ↓)props.put("linger.ms", 0);props.put("batch.size", 1); // 배치 없음// acks 설정props.put("acks", "1"); // 빠른 응답// 재시도 설정props.put("retries", 3);props.put("retry.backoff.ms", 100);// 타임아웃props.put("delivery.timeout.ms", 30000);props.put("request.timeout.ms", 10000);
Properties props = new Properties();// 즉시 Fetchprops.put("fetch.min.bytes", 1); // 즉시 반환props.put("fetch.max.wait.ms", 100); // 짧은 대기// 작은 배치props.put("max.poll.records", 100);// 빠른 재연결props.put("reconnect.backoff.ms", 50);props.put("reconnect.backoff.max.ms", 1000);
안정성 최적화
Properties props = new Properties();// 수동 커밋props.put("enable.auto.commit", false);// 세션 관리 (Rebalance 안정성)props.put("session.timeout.ms", 45000);props.put("heartbeat.interval.ms", 15000);props.put("max.poll.interval.ms", 300000);// 격리 수준 (트랜잭션)props.put("isolation.level", "read_committed");
Consumer 설정 시나리오별 권장값
시나리오
fetch.min.bytes
fetch.max.wait.ms
max.poll.records
최대 처리량
1048576
500
2000
최소 지연
1
100
100
배치 처리
5242880
1000
5000
균형
524288
300
500
OS 튜닝
Linux 커널 파라미터
# /etc/sysctl.conf# 파일 디스크립터fs.file-max=1000000# 네트워크 버퍼net.core.wmem_default=1048576net.core.wmem_max=16777216net.core.rmem_default=1048576net.core.rmem_max=16777216net.core.netdev_max_backlog=30000# TCP 설정net.ipv4.tcp_wmem=4096 65536 16777216net.ipv4.tcp_rmem=4096 65536 16777216net.ipv4.tcp_max_syn_backlog=8096net.ipv4.tcp_tw_reuse=1net.ipv4.tcp_fin_timeout=15# VM 설정vm.swappiness=1vm.dirty_ratio=60vm.dirty_background_ratio=5# 적용sysctl -p
파일 디스크립터 제한
# /etc/security/limits.confkafka soft nofile 128000kafka hard nofile 128000kafka soft nproc 128000kafka hard nproc 128000# 확인ulimit -n
# kafka-server-start.sh 또는 KAFKA_HEAP_OPTS# 기본 권장 (메모리의 25-50%)export KAFKA_HEAP_OPTS="-Xms6g -Xmx6g"# 대규모 클러스터export KAFKA_HEAP_OPTS="-Xms12g -Xmx12g"# 주의: 힙이 너무 크면 GC 일시 정지 증가# 31GB 이하 권장 (Compressed OOPs)
# Java 11+-Xlog:gc*:file=/var/log/kafka/gc.log:time,tags:filecount=10,filesize=100M# 분석 도구# GCViewer, GCEasy 등 사용
네트워크 튜닝
Broker 네트워크 설정
# server.properties# 연결 관리connections.max.idle.ms=600000max.connections=1000max.connections.per.ip=100# 요청 큐queued.max.requests=500# 요청 처리 제한max.incremental.fetch.session.cache.slots=1000
# End-to-End 지연kafka-run-class.sh kafka.tools.EndToEndLatency \ localhost:9092 perf-test 10000 all 1024# 결과: Avg latency: 5.0 ms
튜닝 체크리스트
처리량 최적화
□ batch.size 증가 (Producer)
□ linger.ms 증가 (Producer)
□ compression.type 설정 (lz4)
□ fetch.min.bytes 증가 (Consumer)
□ num.network.threads 증가 (Broker)
□ num.io.threads 증가 (Broker)
□ 파티션 수 증가
지연 시간 최적화
□ linger.ms = 0 (Producer)
□ fetch.min.bytes = 1 (Consumer)
□ fetch.max.wait.ms 감소 (Consumer)
□ 네트워크 대역폭 확인
□ 디스크 I/O 확인
□ GC 튜닝
댓글 (0)