-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The rate balance module is a variant on size balance, except that it scales the size used based on the retention of the topic. Topics that are retained longer than the cluster default (now specified on the command line with --default-retention) will be weighted lower, such that if a topic has double the retention of the cluster, its scaled size will be half its actual size on disk. This will more closely approximate data rate balancing, which was the original intention of the size module.
- Loading branch information
1 parent
b4d894a
commit 1f4a7e4
Showing
11 changed files
with
166 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from kafka.tools.assigner.actions.balancemodules.size import ActionBalanceSize | ||
from kafka.tools.assigner.actions import ActionBalanceModule | ||
|
||
|
||
class ActionBalanceRate(ActionBalanceModule): | ||
name = "rate" | ||
helpstr = "Move the busiest partitions in the cluster to even the total bytes rate per-broker for each replica position" | ||
|
||
def __init__(self, args, cluster): | ||
super(ActionBalanceRate, self).__init__(args, cluster) | ||
|
||
# This module merely calls the balance "size" module with the scaled_size attr, so we're going to instantiate a copy of that | ||
self._size = ActionBalanceSize(args, cluster, size_attr='scaled_size') | ||
|
||
def process_cluster(self): | ||
# Call the size module | ||
self._size.process_cluster() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import sys | ||
import unittest | ||
|
||
from argparse import Namespace | ||
from ..fixtures import set_up_cluster, set_up_subparser | ||
|
||
from kafka.tools.assigner.actions.balance import ActionBalance | ||
from kafka.tools.assigner.actions.balancemodules.rate import ActionBalanceRate | ||
|
||
|
||
class ActionBalanceRateTests(unittest.TestCase): | ||
def setUp(self): | ||
self.cluster = set_up_cluster() | ||
self.cluster.topics['testTopic1'].partitions[0].set_size(1000) | ||
self.cluster.topics['testTopic1'].partitions[1].set_size(1000) | ||
self.cluster.topics['testTopic2'].partitions[0].set_size(2000) | ||
self.cluster.topics['testTopic2'].partitions[1].set_size(2000) | ||
|
||
(self.parser, self.subparsers) = set_up_subparser() | ||
self.args = Namespace(exclude_topics=[]) | ||
|
||
def test_configure_args(self): | ||
ActionBalance.configure_args(self.subparsers) | ||
sys.argv = ['kafka-assigner', 'balance', '-t', 'rate'] | ||
parsed_args = self.parser.parse_args() | ||
assert parsed_args.action == 'balance' | ||
|
||
def test_create_class(self): | ||
action = ActionBalanceRate(self.args, self.cluster) | ||
assert isinstance(action, ActionBalanceRate) | ||
|
||
# This is a duplicate of the size test, but we need at least one test to make sure it does work | ||
def test_process_cluster_one_move(self): | ||
b1 = self.cluster.brokers[1] | ||
b2 = self.cluster.brokers[2] | ||
self.cluster.topics['testTopic1'].partitions[0].swap_replica_positions(b1, b2) | ||
|
||
action = ActionBalanceRate(self.args, self.cluster) | ||
action.process_cluster() | ||
|
||
assert sum([p.scaled_size for p in self.cluster.brokers[1].partitions[0]], 0) == 3000 | ||
assert sum([p.scaled_size for p in self.cluster.brokers[1].partitions[1]], 0) == 3000 | ||
assert sum([p.scaled_size for p in self.cluster.brokers[2].partitions[0]], 0) == 3000 | ||
assert sum([p.scaled_size for p in self.cluster.brokers[2].partitions[1]], 0) == 3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters