Kafka - Primie Number of Partitions Issue & Consumer Group Rebalance

Article directory


insert image description here


insert image description here

  • Producers: Clients that write data to Kafka.

  • Consumer: A client that reads data from Kafka.

  • Topic: A logical concept used to organize and store data in Kafka, similar to a database table.

  • Record: The message sent to Topic is called Record.

  • Partition: Topic partition, used for horizontal expansion and improved concurrency performance.

  • Offset: Indicates the order of Record in Partition.

  • Consumer Group: A group of consumers jointly consume data in a Topic.

  • Broker: A node in the Kafka cluster for storing and processing data.

  • Consumer Group State: __consumer_offsetsThe consumer group state written by the Broker to the internal Kafka topic named .

  • Consumer Group ID: A parameter that identifies a consumer group with an independent state.

  • Consumer Group Coordinator: Broker responsible for managing Consumer Group State.

  • Consumer Group Assignment Strategy: Determines how partitions are assigned to consumers in the Consumer Group.

    Kafka provides two Consumer Group Assignment Strategies:

    Range Assignment Strategy: This strategy sorts each Partition of the Topic according to the Partition ID, and then distributes them equally to each consumer in the Consumer Group. In this way, each consumer will consume some consecutive Partitions.

    Round Robin Assignment Strategy: This strategy evenly assigns all Partitions of the Topic to each consumer in the Consumer Group. In this way, each consumer will consume some Partitions in order, and then start from the beginning.

    Which Consumer Group Assignment Strategy to use can be selected by setting the partition.assignment.strategy parameter in the Consumer Group.

    By default, Kafka uses the Range Assignment Strategy.

  • Primie Number of Partitions Issue: If the number of partitions in a Topic is a prime number, it may cause consumers in some Consumer Groups to consume fewer partitions than consumers in other Consumer Groups.

  • Multiple Consumer Groups: Multiple Consumer Groups can independently read the same Topic with its own independent state.

  • Consumer Group Rebalance: The allocation strategy rebalances the partition allocation when consumers are added or removed from the Consumer Group.

In Kafka, Consumer Group Rebalance refers to the process of reassigning Topic partitions when consumers are added or deleted in the Consumer Group. Consumer Group Rebalance is triggered by Consumer Group Coordinator (Broker responsible for managing Consumer Group State), and uses Consumer Group Assignment Strategy (determines how to assign partitions to consumers in Consumer Group) to rebalance partition assignments.

The process of Consumer Group Rebalance is as follows:

When consumers are added or removed from the Consumer Group, the Consumer Group Coordinator triggers Consumer Group Rebalance.

The Consumer Group Coordinator uses the Consumer Group Assignment Strategy to rebalance partition assignments.

The Consumer Group Coordinator writes the new partition assignment to an __consumer_offsetsinternal Kafka topic named .

Consumers use __consumer_offsetsthe information in the topic to resume their consumption progress and continue consuming data.

Consumer Group Rebalance is an important concept in Kafka, which can help achieve high availability and scalability. However, if Consumer Group Rebalance occurs too frequently, it may affect the performance and stability of the Kafka cluster. Therefore, when using Kafka, it is necessary to reasonably set the number of Consumer Groups and the number of consumers to avoid too frequent Consumer Group Rebalance.

insert image description here

Guess you like

Origin blog.csdn.net/yangshangwei/article/details/131813361