You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "Dong Lin (JIRA)" <ji...@apache.org> on 2018/07/11 21:32:00 UTC

[jira] [Comment Edited] (KAFKA-7126) Reduce number of rebalance period for large consumer groups after a topic is created

    [ https://issues.apache.org/jira/browse/KAFKA-7126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16540687#comment-16540687 ] 

Dong Lin edited comment on KAFKA-7126 at 7/11/18 9:31 PM:
----------------------------------------------------------

Suppose there is no error such as network disconnection or timeout, the consumer rebalance will be triggered in the following scenarios:

1) Leader consumer in the consumer group sees different metadata

2) Consumer in the consumer group which uses pattern-subscription sees different subscribed topics. The set of subscribed topics is the union of topics assigned to this consumer and topics in the metadata that matches the subscription pattern. Thus the subscribed topics can change in the following scenarios:

    2.1) Consumer#subscribe(...) is called and subscription pattern is changed.
     2.2) Metadata is updated and there exists a new topic in the metadata that matches the subscription pattern and the topic is not yet assigned to this consumer.

 

The observation here is that, if a metadata is updated, it should be sufficient for leader to trigger rebalance in 1) and it is not necessary for follower to trigger rebalance again in 2.2). As long as the leader consumer has the latest metadata and its knows the latest subscription pattern from all consumers, leader can ensure that every member in the group is assigned the partitions properly. So the proposal is to trigger rebalance using the following logic:

1) Leader consumer in the consumer group sees different metadata

2) Consumer#subscribe(...) is called and subscription pattern is changed.

 

The above solution should ensure when a topic is created, it triggers exactly one rebalance in the consumer group. Here is another much simpler solution which probably triggers only a small constant number of rebalance after topic creation. The idea is for every non-leader consumer to refresh metadata after rebalance is triggered. The metadata refresh should respect the retry.backoff.ms.

 

Ping [~hachikuji] for comments.
  
  
  


was (Author: lindong):
Suppose there is no error such as network disconnection or timeout, the consumer rebalance will be triggered in the following scenarios:

1) Leader consumer in the consumer group sees different metadata

2) Consumer in the consumer group which uses pattern-subscription sees different subscribed topics. The set of subscribed topics is the union of topics assigned to this consumer and topics in the metadata that matches the subscription pattern. Thus the subscribed topics can change in the following scenarios:

    2.1) Consumer#subscribe(...) is called and subscription pattern is changed.
    2.2) Metadata is updated and there exists a new topic in the metadata that matches the subscription pattern and the topic is not yet assigned to this consumer.

 

The observation here is that, if a metadata is updated, it should be sufficient for leader to trigger rebalance in 1) and it is not necessary for follower to trigger rebalance again in 2.2). As long as the leader consumer has the latest metadata and its knows the latest subscription pattern from all consumers, leader can ensure that every member in the group is assigned the partitions properly. So the proposal is to trigger rebalance using the following logic:

1) Leader consumer in the consumer group sees different metadata

2) Consumer#subscribe(...) is called and subscription pattern is changed.

Ping [~hachikuji] for comments.
 
 
 

> Reduce number of rebalance period for large consumer groups after a topic is created
> ------------------------------------------------------------------------------------
>
>                 Key: KAFKA-7126
>                 URL: https://issues.apache.org/jira/browse/KAFKA-7126
>             Project: Kafka
>          Issue Type: Improvement
>            Reporter: Dong Lin
>            Assignee: Dong Lin
>            Priority: Major
>
> For a group of 200 MirrorMaker consumers with patten-based topic subscription, a single topic creation caused 50 rebalances for each of these consumer over 5 minutes period. This causes the MM to significantly lag behind during this 5 minutes period and the clusters may be considerably out-of-sync during this period.
> Ideally we would like to trigger only 1 rebalance in the MM group after a topic is created. And conceptually it should be doable.
>  
> Here is the explanation of this repeated consumer rebalance based on the consumer rebalance logic in the latest Kafka code:
> 1) A topic of 10 partitions are created in the cluster and it matches the subscription pattern of the MM consumers.
> 2) The leader of the MM consumer group detects the new topic after metadata refresh. It triggers rebalance.
> 3) At time T0, the first rebalance finishes. 10 consumers are assigned 1 partition of this topic. The other 190 consumers are not assigned any partition of this topic. At this moment, the newly created topic will appear in `ConsumerCoordinator.subscriptions.subscription` for those consumers who is assigned partition of this consumer or who has refreshed metadata before time T0.
> 4) In the common case, half of the consumers has refreshed metadata before the leader of the consumer group refreshed metadata. Thus around 100 + 10 = 110 consumers has the newly created topic in `ConsumerCoordinator.subscriptions.subscription`. The other 90 consumers do not have this topic in `ConsumerCoordinator.subscriptions.subscription`.
> 5) For those 90 consumers, if any consumer refreshes metadata, it will add this topic to `ConsumerCoordinator.subscriptions.subscription`, which causes `ConsumerCoordinator.rejoinNeededOrPending()` to return true and triggers another rebalance. If a few consumers refresh metadata almost at the same time, they will jointly trigger one rebalance. Otherwise, they each trigger a separate rebalance.
> 6) The default metadata.max.age.ms is 5 minutes. Thus in the worse case, which is probably also the average case if number of consumers in the group is large, the latest consumer will refresh its metadata 5 minutes after T0. And the rebalance will be repeated during this 5 minutes interval.
>  
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)