티스토리 뷰

개발

kafka rebalance protocol

달리는개발자 2022. 12. 16. 14:30

kafka consumer rebalance 란?

토픽의 파티션이 다른 consumer에게로 할당될 때 이것을 consumer rebalance라고 한다.

다음과 같은 상황에서 발생한다.

  • consumer가 그룹을 떠날 때(leave)
  • group에 다시 들어올 때(join)
  • topic에 파티션이 추가될 때

 

기본적으로 eager rebalancing이 이뤄지면 아래와 같이 전체 consumer가 할당 받은 partition을 revoke하고 다시 할당을 받는다

이때 모든 consumer는 메시지 consuming을 중지하면서 이 기간 동안 모든 처리가 멈춘다.

이걸 stop the world 라고 부른다.

 

기본적으로 consumer의 partition.assignment.strategy 설정을 하지 않으면 RangeAssinor가 사용된다.

2.4부터 incremental cooperative rebalancing 을 지원하는 group protocol을 제공한다.

3.0.0부터는 기본값이 [RangeAssignor, CooperativeStickyAssignor] 로 변경됐으나 첫번째 Assignor가 사용되기 때문에 RangeAssignor가 사용된다. 그러나 기본값이 변경됨에 따라서 partition.assignment.strategy 설정을 CooperativeStickyAssignor로만 해줘도 된다.

CooperativeStickyAssignor 를 설정했을 때 cooperative rebalacing이 이루어지고 가장 이상적인 리밸런싱이 진행된다.

incremental cooperative rebalancing

위에 그림처럼 consumer C가 들어왔지만 consumer B는 할당 받은 2번 partition에 대해서 stop the world 없이 계속 처리가 가능하다.

consumer A는 할당 받은 partition 3에 대해서만 revoke하고 consumer C는 partition 3을 할당 받으면서 rebalacing이 종료된다.

 

CooperativeStickyAssignor 로 설정하기 위한 방법

- 2.4 이상 지원

- 1차로 partition.assignment.strategy 에 [RangeAssignor, CooperativeStickyAssignor] 설정

- 2차로 partition.assignment.strategy 에 [CooperativeStickyAssignor] 설정해서 적용함.

3.0부터는 바로 [CooperativeStickyAssignor] 로 설정해서 적용할 수 있지만 2.4 ~ 3.0 미만에서는 아래와 같은 오류가 발생한다.

org.apache.kafka.common.errors.InconsistentGroupProtocolException: The group member's supported protocols are incompatible with those of existing members or first group member tried to join with empty protocol type or empty protocol list

 

Static Membership

기본적으로 consumer가 그룹을 떠날 때 partition들이 revoke 되고 다시 할당된다.

배포 등으로 consumer가 다시 들어올 때 새로운 member.id를 가지고 있고 새로운 파티션이 할당된다.

2.3 이상부터 group.instance.id를 명시하면 static member로 만들 수 있다.

static member인 consumer가 떠날 때 session.timeout.ms 안에 다시 들어오면 리밸런싱없이 다시 파티션을 가져올 수 있다.

group.instance.id와 session.timout.ms를 조정해서 불필요한 리밸런싱을 줄일 수 있다.

3.0.0 부터 session.timeout.ms 기본값이 10초에서 45초로 변경됨

 

아래 참고 자료들 중에 kafka 기본 문서와 더불어 conduktor kafkademy, confluent 자료를 같이 보면 도움이 많이 된다.

 

참고

https://www.conduktor.io/kafka/consumer-incremental-rebalance-and-static-group-membership

https://www.confluent.io/online-talks/everything-you-always-wanted-to-know-about-kafkas-rebalance-protocol-but-were-afraid-to-ask-on-demand/?utm_medium=sem&utm_source=google&utm_campaign=ch.sem_br.nonbrand_tp.prs_tgt.dsa_mt.dsa_rgn.apac_lng.eng_dv.all_con.online-talks&utm_term=&creative=&device=c&placement=&gclid=Cj0KCQiAqOucBhDrARIsAPCQL1ak1m0G8ttMFzN7_09dZUpn_ve1HApAA65v3vQYspTfJ-DtLEEj4yUaAkh5EALw_wcB 

 

Everything You Always Wanted to Know About Kafka’s Rebalance Protocol but Were Afraid to Ask - Confluent

This talk provides a deep dive into the details of the rebalance protocol, starting from its original design in version 0.9 up to the latest improvements and future work. We discuss internal technical details, pros and cons of the existing approaches, ...

www.confluent.io

 

https://www.verica.io/blog/understanding-kafkas-consumer-group-rebalancing/

 

Understanding Kafka's Consumer Group Rebalancing – Verica

The Kafka producer-cluster-consumer system is a great way to funnel high volumes of messages with spectacular reliability and order from place-to-place within your product’s architecture. However, it isn’t without its drawbacks. As with any system, som

www.verica.io

 

https://www.conduktor.io/blog/kafka-partition-assignment-strategy

 

Apache Kafka Partition Assignment Strategy

How are topic partitions assigned to a consumer? What happens when a consumer dies? Find out the different strategies you can use with Apache Kafka

www.conduktor.io

 

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함