Quota 관리
Kafka에서 클라이언트의 리소스 사용량을 제한하여 클러스터를 보호합니다.
Quota 개요
Quota 유형
┌─────────────────────────────────────────────────────────────────┐
│ Kafka Quotas │
├─────────────────────────────────────────────────────────────────┤
│ │
│ 1. Network Bandwidth Quotas │
│ - producer_byte_rate: Producer 전송 속도 제한 │
│ - consumer_byte_rate: Consumer 수신 속도 제한 │
│ - 단위: bytes/second │
│ │
│ 2. Request Rate Quotas │
│ - request_percentage: 요청 처리 시간 비율 제한 │
│ - 단위: percentage (0-100) │
│ │
│ 3. Controller Mutation Quotas │
│ - controller_mutation_rate: 메타데이터 변경 속도 제한 │
│ - 단위: mutations/second │
│ │
└─────────────────────────────────────────────────────────────────┘
Quota 적용 대상
| 대상 | 설명 |
|---|---|
| User | SASL 인증된 사용자 |
| Client ID | client.id 설정값 |
| User + Client ID | 사용자와 클라이언트 조합 |
| Default | 기본값 (모든 클라이언트) |
Bandwidth Quota 설정
기본 Quota
# 모든 사용자의 기본 Quota
kafka-configs.sh --bootstrap-server localhost:9092 \
--alter \
--add-config 'producer_byte_rate=10485760,consumer_byte_rate=20971520' \
--entity-type users \
--entity-default
# Producer: 10MB/s, Consumer: 20MB/s사용자별 Quota
# 특정 사용자 Quota
kafka-configs.sh --bootstrap-server localhost:9092 \
--alter \
--add-config 'producer_byte_rate=52428800,consumer_byte_rate=104857600' \
--entity-type users \
--entity-name alice
# alice: Producer 50MB/s, Consumer 100MB/sClient ID별 Quota
# 특정 Client ID Quota
kafka-configs.sh --bootstrap-server localhost:9092 \
--alter \
--add-config 'producer_byte_rate=5242880' \
--entity-type clients \
--entity-name batch-producer
# batch-producer: Producer 5MB/sUser + Client ID Quota
# 사용자 + 클라이언트 조합
kafka-configs.sh --bootstrap-server localhost:9092 \
--alter \
--add-config 'producer_byte_rate=10485760' \
--entity-type users \
--entity-name alice \
--entity-type clients \
--entity-name my-appRequest Rate Quota
설정
# 요청 처리 시간 비율 제한 (50%)
kafka-configs.sh --bootstrap-server localhost:9092 \
--alter \
--add-config 'request_percentage=50' \
--entity-type users \
--entity-name heavy-user동작 방식
request_percentage = 50
의미:
- I/O 스레드 시간의 50%까지 사용 가능
- 초과 시 스로틀링 (지연 응답)
예:
- num.io.threads = 8
- 이 사용자는 4개 스레드 시간만 사용 가능
Controller Mutation Quota
설정
# 메타데이터 변경 속도 제한
kafka-configs.sh --bootstrap-server localhost:9092 \
--alter \
--add-config 'controller_mutation_rate=10' \
--entity-type users \
--entity-name admin-user
# 초당 10개 메타데이터 변경까지 허용적용 대상 작업
- 토픽 생성/삭제
- 파티션 추가
- 설정 변경
- ACL 변경
Quota 조회
모든 Quota 조회
# 사용자 Quota 조회
kafka-configs.sh --bootstrap-server localhost:9092 \
--describe \
--entity-type users
# 클라이언트 Quota 조회
kafka-configs.sh --bootstrap-server localhost:9092 \
--describe \
--entity-type clients
# 특정 사용자 Quota 조회
kafka-configs.sh --bootstrap-server localhost:9092 \
--describe \
--entity-type users \
--entity-name alice출력 예시
Quota configs for user-principal 'alice' are
producer_byte_rate=52428800
consumer_byte_rate=104857600
Quota 삭제
# 특정 Quota 삭제
kafka-configs.sh --bootstrap-server localhost:9092 \
--alter \
--delete-config 'producer_byte_rate' \
--entity-type users \
--entity-name alice
# 모든 Quota 삭제
kafka-configs.sh --bootstrap-server localhost:9092 \
--alter \
--delete-config 'producer_byte_rate,consumer_byte_rate' \
--entity-type users \
--entity-name aliceQuota 우선순위
적용 순서
1. /config/users/<user>/clients/<client-id>
2. /config/users/<user>/clients/<default>
3. /config/users/<user>
4. /config/users/<default>/clients/<client-id>
5. /config/users/<default>/clients/<default>
6. /config/users/<default>
7. /config/clients/<client-id>
8. /config/clients/<default>
예시
User: alice, Client ID: my-app
적용되는 Quota:
1. alice + my-app 조합 Quota (있으면)
2. alice의 기본 클라이언트 Quota (있으면)
3. alice 사용자 Quota (있으면)
4. default + my-app Quota (있으면)
5. default 사용자 + default 클라이언트 Quota
6. default 사용자 Quota
7. my-app 클라이언트 Quota (있으면)
8. default 클라이언트 Quota
스로틀링 동작
스로틀링 발생 시
┌─────────────────────────────────────────────────────────────────┐
│ Throttling Behavior │
├─────────────────────────────────────────────────────────────────┤
│ │
│ 1. Quota 초과 감지 │
│ ↓ │
│ 2. Broker가 응답 지연 │
│ ↓ │
│ 3. 클라이언트가 throttle_time_ms 응답 수신 │
│ ↓ │
│ 4. 클라이언트가 해당 시간만큼 대기 │
│ ↓ │
│ 5. 전송률이 Quota 이하로 조절됨 │
│ │
└─────────────────────────────────────────────────────────────────┘
클라이언트 동작
// Producer 응답에서 throttle_time_ms 확인
RecordMetadata metadata = future.get();
// Consumer 폴링 시 자동 스로틀링
ConsumerRecords<String, String> records = consumer.poll(...);
// Quota 초과 시 poll()이 더 오래 걸림모니터링
JMX 메트릭
Broker 메트릭:
kafka.server:type=FetchThrottleMetrics,user=<user>,client-id=<client-id>
kafka.server:type=ProduceThrottleMetrics,user=<user>,client-id=<client-id>
├── throttle-time: 총 스로틀 시간
├── byte-rate: 현재 전송률
└── quota: 설정된 Quota
클라이언트 메트릭
Producer:
kafka.producer:type=producer-metrics,client-id=<client-id>
├── produce-throttle-time-avg
└── produce-throttle-time-max
Consumer:
kafka.consumer:type=consumer-fetch-manager-metrics,client-id=<client-id>
├── fetch-throttle-time-avg
└── fetch-throttle-time-max
알림 설정
# Prometheus Alert
groups:
- name: kafka-quota-alerts
rules:
- alert: KafkaClientThrottled
expr: kafka_producer_produce_throttle_time_avg > 1000
for: 5m
labels:
severity: warning
annotations:
summary: "Client is being throttled"사용 사례
멀티 테넌트 환경
# 테넌트별 Quota 할당
# 테넌트 A: 프리미엄 (높은 Quota)
kafka-configs.sh --bootstrap-server localhost:9092 \
--alter \
--add-config 'producer_byte_rate=104857600,consumer_byte_rate=209715200' \
--entity-type users \
--entity-name tenant-a
# 테넌트 B: 기본 (낮은 Quota)
kafka-configs.sh --bootstrap-server localhost:9092 \
--alter \
--add-config 'producer_byte_rate=10485760,consumer_byte_rate=20971520' \
--entity-type users \
--entity-name tenant-b배치 작업 제한
# 배치 작업 클라이언트 제한
kafka-configs.sh --bootstrap-server localhost:9092 \
--alter \
--add-config 'producer_byte_rate=5242880' \
--entity-type clients \
--entity-name batch-job
# 실시간 트래픽 보호잘못된 클라이언트 제한
# 문제 클라이언트 즉시 제한
kafka-configs.sh --bootstrap-server localhost:9092 \
--alter \
--add-config 'producer_byte_rate=1024' \
--entity-type users \
--entity-name misbehaving-user
# 거의 차단 수준Best Practices
1. 기본 Quota 설정
# 항상 기본 Quota 설정
kafka-configs.sh --bootstrap-server localhost:9092 \
--alter \
--add-config 'producer_byte_rate=10485760,consumer_byte_rate=20971520' \
--entity-type users \
--entity-default2. 여유 있는 Quota
# 정상 사용량의 2-3배로 설정
# 정상: 10MB/s → Quota: 30MB/s3. 모니터링 연동
# 스로틀링 발생 시 알림
# Quota 사용률 대시보드4. 정기 검토
# 주기적으로 사용량 분석
# Quota 적정성 검토
# 불필요한 Quota 정리
댓글 (0)