saay, hi
partition 증설 후 consumer 데이터 취득 변화 테스트 본문
Test 목표 | 1) Partition 증량 시 consumer1,2가 중복으로 partition을 바라보는지 확인 2) consumer가 중단될 경우 partition의 consumer.id가 바뀌는지 확인 (=소유권 교체되는지) 3) 소유권 교체 시, 끊긴 partition의 데이터는 언제 취득하는지 확인 |
Test 시나리오 | 1) 기존 topic partition + 1 증량 2) producer에서 topic 생성 3) topic 이 partition 개수만큼 분할됐는지 확인 4) consumer1,2기동 후 각각 consumer group의 partition offset확인 5) partition-0,1을 consumer끼리 중복 데이터 취득하는지 확인 6) consumer 기동 중단 시, partition의 변화 있는지 확인 – consumer.id / offset 확인 /server.log 확인 |
Test 구성 |
![]() |
[ 기존 옵션 변경 및 확인 ]
Topic partition 개수 2개로 증량 | $>./kafka-topics.sh --bootstrap-server 192.168.56.105:9092 --alter --topic basic-consumer -partitions 2 |
partition 확인 | $>./kafka-topics.sh --describe --bootstrap-server 192.168.56.105:9092 --topic basic-consumer Topic: basic-consumer TopicId: iuxGbH4-SGOEd7h0th4dIQ PartitionCount: 2 ReplicationFactor: 1 Configs: Topic: basic-consumer Partition: 0 Leader: 0 Replicas: 0 Isr: 0 Topic: basic-consumer Partition: 1 Leader: 0 Replicas: 0 Isr: 0 |
[ test 방법 ]
1-1. test 전 kafka bin directory에서 consumer group 상태를 조회 ( 명령어 : ./kafka-consumer-groups.sh --bootstrap-server 192.168.56.105:9092 --describe --group basic-consumer )
$>./kafka-consumer-groups.sh --bootstrap-server 192.168.56.105:9092 --describe --group basic-consumer Consumer group 'basic-consumer' has no active members. GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID basic-consumer basic-consumer 0 4785786 5330528 544742 - - - basic-consumer basic-consumer 1 99470 99470 0 - - - |
1-2. producer에게 topic 받은 후 consumer group 상태 다시 조회 ( 명령어 : ./kafka-consumer-groups.sh --bootstrap-server 192.168.56.105:9092 --describe --group basic-consumer )
$>./kafka-consumer-groups.sh --bootstrap-server 192.168.56.105:9092 --describe --group basic-consumer Consumer group 'basic-consumer' has no active members. GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID basic-consumer basic-consumer 0 4785786 5380793 595007 - - - basic-consumer basic-consumer 1 99470 149205 49735 - - - |
2-1. consumer1 실행 && 데이터 취득 도중 일시정지
… Topic: basic-consumer, Partition: 0, Offset: 4791285, Key: 61287, Value: |
2-2. consumer1 중단되어진 뒤, consumer group 상태 확인 ( 명령어 : ./kafka-consumer-groups.sh --bootstrap-server 192.168.56.105:9092 --describe --group basic-consumer )
GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID basic-consumer basic-consumer 0 4790786 5380793 590007 2ndConsumer-b6add984-ed94-42e7-9fe1-17ac217c729c /192.168.56.105 consumer-basic-consumer-2ndC onsumer basic-consumer basic-consumer 1 110970 149205 38235 2ndConsumer-b6add984-ed94-42e7-9fe1-17ac217c729c /192.168.56.105 consumer-basic-consumer-2ndC onsumer |
2-3. consumer1 중단 후 server.log 상태 확인 ( kafka 엔진 내의 log dir 有 )
[2024-01-25 14:19:43,307] INFO [GroupCoordinator 0]: Member 1stConsumer-9041e8de-7f06-4407-9ae6-276bf9264593 in group basic-consumer has failed, removing it from the group (kafka.coordinator.group.GroupCoordinator) [2024-01-25 14:19:43,307] INFO [GroupCoordinator 0]: Preparing to rebalance group basic-consumer in state PreparingRebalance with old generation 221 (__consumer_offsets-19) (reason: removing member 1stConsumer-9041e8de-7f06-4407-9ae6-276bf9264593 on heartbeat expiration) (kafka.coordinator.group.GroupCoordinator) [2024-01-25 14:19:48,462] INFO [GroupCoordinator 0]: Stabilized group basic-consumer generation 222 (__consumer_offsets-19) with 1 members (kafka.coordinator.group.GroupCoordinator) [2024-01-25 14:19:48,489] INFO [GroupCoordinator 0]: Assignment received from leader 2ndConsumer-b6add984-ed94-42e7-9fe1-17ac217c729c for group basic-consumer for generation 222. The group has 1 members, 1 of which are static. (kafka.coordinator.group.GroupCoordinator) |
3-1. consumer2가 데이터 partition-1의 데이터를 모두 취득 후, consumer group 상태 확인
GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID basic-consumer basic-consumer 0 4790786 5380793 590007 2ndConsumer-b6add984-ed94-42e7-9fe1-17ac217c729c /192.168.56.105 consumer-basic-consumer-2ndConsumer basic-consumer basic-consumer 1 148970 149205 235 2ndConsumer-b6add984-ed94-42e7-9fe1-17ac217c729c /192.168.56.105 consumer-basic-consumer-2ndConsumer ... GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID basic-consumer basic-consumer 0 4791051 5380793 589742 2ndConsumer-b6add984-ed94-42e7-9fe1-17ac217c729c /192.168.56.105 consumer-basic-consumer-2ndConsumer basic-consumer basic-consumer 1 149205 149205 0 2ndConsumer-b6add984-ed94-42e7-9fe1-17ac217c729c /192.168.56.105 consumer-basic-consumer-2ndConsumer |
3-2. consumer2가 consumer1의 partition-0 데이터 취득하기 시작
records:500 Topic: basic-consumer, Partition: 0, Offset: 4791051, Key: 61053, Value: |
3-3. consumer2가 이어받은 데이터를 정상 취득했는지 확인
GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID basic-consumer basic-consumer 0 4792051 5380793 588742 2 ndConsumer-b6add984-ed94-42e7-9fe1-17ac217c729c /192.168.56.105 consumer-basic-consumer-2ndConsumer basic-consumer basic-consumer 1 149205 149205 0 2 ndConsumer-b6add984-ed94-42e7-9fe1-17ac217c729c /192.168.56.105 consumer-basic-consumer-2ndC onsumer ... GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID basic-consumer basic-consumer 0 4792551 5380793 588242 2ndConsumer-b6add984-ed94-42e7-9fe1-17ac217c729c /192.168.56.105 consumer-basic-consumer-2ndConsumer basic-consumer basic-consumer 1 149205 149205 0 2ndConsumer-b6add984-ed94-42e7-9fe1-17ac217c729c /192.168.56.105 consumer-basic-consumer-2ndConsumer |
[ 결과 ]
1)partition 증량 시 consumer 1,2는 각각 다른 partition에서 데이터 취득하며, partition 별로 50% 가량 나눠서 데이터 취득
2)consumer가 data 취득 중 끊기면 나머지 consumer에게 소유권 전달 (중단된 offset과 group 에서 조회된 current-offset의 차이는 어느정도 있음 (중복 데이터 취득) )
3)소유권 교체 시, 기존의 가지고 있던 partition에서 데이터 취득 완료 후, 넘겨받은 partition-0의 데이터를 받기 시작. 가져오는 records default가 500이므로, 기존 partition에서 다 가져온 나머지 값으로 소유권 이어받은 partition의 데이터 취득 시작
[ 의견 ]
- partitions을 나누면, topic의 100%/{partition 개수}별로 나눠서 취득함. partitions 개수가 많으면 많을수록 하나의 partition 보다 topic하나를 처리하는 부담감이 적음
- 각 consumer group내로 데이터를 취득하다가 group 내의 consumer 가 죽으면 broker에서 재조정을 하고 리더로 부터 남은 topic을 취득해줄 팔로워를 찾음
Preparing to rebalance group basic-consumer in state PreparingRebalance with old generation 221 (__consumer_offsets-19) (reason: removing member 1stConsumer-9041e8de-7f06-4407-9ae6-276bf9264593 on heartbeat expiration) (kafka.coordinator.group.GroupCoordinator) Assignment received from leader 2ndConsumer-b6add984-ed94-42e7-9fe1-17ac217c729c for group basic-consumer for generation 222. The group has 1 members, 1 of which are static. (kafka.coordinator.group.GroupCoordinator) |
3. 찾은 팔로워는 바로 이어받은 topic을 취득하나, 본인이 이미 데이터 취득 중이라면 본인 topic을 다 받고난 후 이어받은 topic을 취득하기 시작
→ consumer 가 다운돼버리면 다른 follower가 이어받긴하나, 이어받은 follower가 이전부터 이전부터 큰 용량의 topic을 취득 중이라면, 이어받는 시간이 지체될 수 있음. 따라서 중요한 데이터를 받을 계획이라면 cluster하여 데이터를 복제해 두기를 권장함.
'kafka 테스트 > 데이터 테스트' 카테고리의 다른 글
중복 취득 확인 테스트 (0) | 2024.06.27 |
---|---|
동일 consumer group 데이터 취득 테스트 (0) | 2024.06.27 |