cruise-control icon indicating copy to clipboard operation
cruise-control copied to clipboard

New soft goal TopicLeaderReplicaDistributionGoal?

Open rhardouin opened this issue 4 years ago • 14 comments

Hi, We would like to evenly distribute topics leadership across brokers. A kind of mix between TopicReplicaDistributionGoal and LeaderReplicaDistributionGoal.

We plan to implement a custom soft goal e.g. TopicLeaderReplicaDistributionGoal. The idea would be to use it along with TopicReplicaDistributionGoal to mimic the behavior of Kafka assigner mode but without moving all replicas "from scratch".

Is it a good approach? Does it make sense for an upstream contribution or is there a better option? (e.g. modify an existing goal) Thanks

rhardouin avatar Dec 30 '20 10:12 rhardouin

Hi @rhardouin Thanks for creating this issue! To better understand the motivation, could you tell a little bit about the scenarios that this goal intends to help with?

The #921 and corresponding PR would be relevant.

efeg avatar Jan 14 '21 00:01 efeg

Hi @efeg

We've split our workload into multiple Kafka clusters (roughly one cluster per service instead of having one big cluster with non-spanning topics). In each cluster, each topic spans all brokers and partitions load is homogeneous. Thus replicas and leader replicas must be spread evenly across all brokers to ensure an homogeneous load.

Images speak louder than words so here is the situation on a cluster:

TopicReplicaDistributionGoal is able to spread evenly replicas across brokers

replicas_distribution

But leadership is imbalanced because LeaderDistributionGoal works at broker level:

leader_replicas_distribution

Topic A handles more traffic than other topics so you can see that broker 13 with 2 leaders is idle compared to brokers having 7 or 8 leaders.

rhardouin avatar Jan 15 '21 10:01 rhardouin

I have the same needs and thoughts.It's a good idea, because most of the time the workload of each partition of a topic is closed to each other, but the workload between topics is different.

3286360470 avatar Jan 20 '21 09:01 3286360470

@rhardouin Thanks for the detailed explanation. The use-case seems reasonable, and creating a new goal rather than modifying an existing one is preferred.

We look forward to your upstream contribution with the new goal!

efeg avatar Jan 21 '21 02:01 efeg

Adding here another use-case for this:

the __consumer_offsets topic is one such example where the leaders should be evenly distributed across brokers ( when a consumer group is created in kafka the group coordinator is elected one of the leaders of this topic serving the randomly selected partition for that CG).

While "LeaderReplicaDistributionGoal" goal can be used to achieve this for all topics it is not easily configurable to target a specific set of topics.

As such a new soft goal should be added TopicLeaderDistributionGoal that requires a set of topics to be configured and balances evenly the leaders across all brokers

amuraru avatar Mar 12 '21 07:03 amuraru

I have the same needs and thoughts.It's a good idea, because most of the time the workload of each partition of a topic is closed to each other, but the workload between topics is different.

I have implemented TopicLeaderReplicaDistributionGoal locally, and the actual effect of the prd-cluster is also very good, Just poll the candidateBrokers(which sorted by comparing numLeaderReplicasOfTopicInBroker, then comparing the brokers' NW_OUT、NW_OUT、brokerId etg.)

3286360470 avatar Mar 12 '21 08:03 3286360470

Hey sorry for the delay, it's been a while since I pushed a draft on our fork , I still have to:

  • make all tests green
  • make the goal work correctly when combined with TopicReplicaDistributionGoal

Despite these rough edges we tested it on production clusters and it worked well... if not combined with TopicReplicaDistributionGoal. When we use both goals it seems they work against each other instead of converging to a good solution.

NOTE: I had to use a ConcurrentHashMap in Broker class to avoid a race condition. It could also occur with existing goal TopicReplicaDistributionGoal because the for loop over topics is the same

rhardouin avatar Mar 29 '21 14:03 rhardouin

@rhardouin Hi Romain - any progress on. this? I can help with testing if needed. thanks

amuraru avatar May 21 '21 11:05 amuraru

@amuraru Unfortunately I wasn't able to put more time on it since my last commit

rhardouin avatar May 27 '21 14:05 rhardouin

@amuraru Yes some help would be welcome :pray:

rhardouin avatar May 27 '21 15:05 rhardouin

@rhardouin I have same needs and can you please let me know how I can test your goal? do I use only this goal to rebalance or I can combine all other goals(except TopicReplicaDistributionGoal I guess). thanks.

bpux avatar Aug 25 '21 22:08 bpux

@bpux There is no silver bullet: sometimes we run the goal alone sometimes we can add another goal but usually we use multiple passes (we tend to do that without this new goal anyway). For instance a first iteration with DiskUsageDistributionGoal + TopicReplicaDistributionGoal + ... and once done we equalize leaders with TopicLeaderReplicaDistributionGoal. This step often requires to exlude other topics e.g. __.* or even some other business topics e.g. ([^t].+|specific_topic_name)

rhardouin avatar Sep 07 '21 07:09 rhardouin

Hello @efeg! I'm wondering if you could point me in the right direction. I have an implementation of this but as a hard goal that I was thinking about PR-ing. Should I open a new issue or would it be ok to piggy-back on this one?

jlei-nr avatar Dec 02 '21 02:12 jlei-nr

Hi @jlei-nr, Please feel free to create a PR and link it to this issue.

efeg avatar Dec 04 '21 01:12 efeg