Last active
December 1, 2015 20:41
-
-
Save eapache/cd5464bf2218ad4b56af to your computer and use it in GitHub Desktop.
Theoretical global-knowledge algorithm for smart kafka partition rebalancing
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
brokers = [1,2,...] | |
# ensure exactly 3 replicas per partition | |
for p in partitions | |
if len(p) > 3; p = p[0...2] | |
if len(p) < 3; p += (brokers - p).sample(3 - len(p)) | |
weights = {} | |
for p in partitions | |
for b in p | |
weights[b]++ | |
while max(weight) - min(weight) > 3 # any proof 3 is always possible? | |
let p = (find partition whose list contains the max-weight broker but not the min-weight broker) | |
p.replace(max-weight-broker, min-weight-broker) | |
weights = {} | |
for p in partitions | |
weights[p.leader]++ | |
while max(weight) - min(weight) > 1 # any proof 1 is always possible? | |
let p = (find partition led by max-weight broker also replicated on min-weight broker) | |
p = [min-weight, max-weight, the-other-one] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment