Skip to content

Instantly share code, notes, and snippets.

@ahale
Created January 27, 2016 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahale/b91fc9bc745e710e070a to your computer and use it in GitHub Desktop.
Save ahale/b91fc9bc745e710e070a to your computer and use it in GitHub Desktop.
comparing the handoff distribution of a ring build with antique ringbuilder code and one built with swift master.
small cluster with one unbalanced node, imagine that it was two boxes or something, one exploded and has been removed for some administrative reason
test script at bottom of paste
swift-ring-builder object.builder create 18 3 1
swift-ring-builder object.builder add r1z1-172.1.1.1:6000/sda1 100
swift-ring-builder object.builder add r1z2-172.1.2.1:6000/sda1 100
swift-ring-builder object.builder add r1z2-172.1.2.2:6000/sda1 100
swift-ring-builder object.builder add r1z3-172.1.3.1:6000/sda1 100
swift-ring-builder object.builder add r1z3-172.1.3.2:6000/sda1 100
swift-ring-builder object.builder add r1z4-172.1.4.1:6000/sda1 100
swift-ring-builder object.builder add r1z4-172.1.4.2:6000/sda1 100
swift-ring-builder object.builder add r1z5-172.1.5.1:6000/sda1 100
swift-ring-builder object.builder add r1z5-172.1.5.2:6000/sda1 100
swift-ring-builder object.builder rebalance
-------------
no hosts down, each box gets balanced hits
root@saio:~# python ringviz.py old-object.ring.gz
9 hosts
172.1.2.2: 87381
172.1.2.1: 87381
172.1.1.1: 87382
172.1.4.1: 87381
172.1.4.2: 87382
172.1.5.1: 87382
172.1.5.2: 87381
172.1.3.2: 87381
172.1.3.1: 87381
root@saio:~# python ringviz.py object.ring.gz
9 hosts
172.1.2.2: 87381
172.1.2.1: 87382
172.1.1.1: 87382
172.1.4.1: 87381
172.1.4.2: 87381
172.1.5.1: 87381
172.1.5.2: 87381
172.1.3.2: 87381
172.1.3.1: 87382
-------------
one host down.
both new and old code look like get_mode_nodes will return the
a (the only) z1 box more than other zones. old ring-builder ring
looks more balanced on other zones than latest code
root@saio:~# python ringviz.py old-object.ring.gz 172.1.5.1
9 hosts
excluding: ['172.1.5.1']
172.1.2.2: 98978
172.1.2.1: 98844
172.1.1.1: 105346
172.1.4.1: 99122
172.1.4.2: 98865
172.1.5.1: 0
172.1.5.2: 87381
172.1.3.2: 98939
172.1.3.1: 98957
root@saio:~# python ringvis.py object.ring.gz 172.1.5.1
9 hosts
excluding: ['172.1.5.1']
172.1.2.2: 101000
172.1.2.1: 101254
172.1.1.1: 109446
172.1.4.1: 99946
172.1.4.2: 99864
172.1.5.1: 0
172.1.5.2: 87381
172.1.3.2: 93821
172.1.3.1: 93720
-------------
taking out only box in zone1.
old ring is pretty balanced across z2 to z5.
new ring seems to have something against z4.
root@saio:~#
root@saio:~# python ringviz.py old-object.ring.gz 172.1.1.1
9 hosts
excluding: ['172.1.1.1']
172.1.2.2: 98322
172.1.2.1: 98145
172.1.1.1: 0
172.1.4.1: 98220
172.1.4.2: 98250
172.1.5.1: 98457
172.1.5.2: 98259
172.1.3.2: 98210
172.1.3.1: 98569
root@saio:~# python ringvis.py object.ring.gz 172.1.1.1
9 hosts
excluding: ['172.1.1.1']
172.1.2.2: 98087
172.1.2.1: 98468
172.1.1.1: 0
172.1.4.1: 91074
172.1.4.2: 91022
172.1.5.1: 101909
172.1.5.2: 102029
172.1.3.2: 102020
172.1.3.1: 101823
-------------
two hosts down. both look pretty similar now.
they'll try to avoid using any ring that has a box out in it for handoff
and the usage is pretty spread out across all available
with the single box zone getting more than node in a two node zone does.
root@saio:~# python ringviz.py old-object.ring.gz 172.1.5.1,172.1.4.2
9 hosts
excluding: ['172.1.5.1', '172.1.4.2']
172.1.2.2: 109981
172.1.2.1: 109835
172.1.1.1: 149066
172.1.4.1: 99122
172.1.4.2: 0
172.1.5.1: 0
172.1.5.2: 98760
172.1.3.2: 109742
172.1.3.1: 109926
root@saio:~# python ringviz.py object.ring.gz 172.1.5.1,172.1.4.2
9 hosts
excluding: ['172.1.5.1', '172.1.4.2']
172.1.2.2: 114695
172.1.2.1: 115001
172.1.1.1: 149230
172.1.4.1: 99946
172.1.4.2: 0
172.1.5.1: 0
172.1.5.2: 94630
172.1.3.2: 106451
172.1.3.1: 106479
root@saio:~# cat ringvis.py
import sys
from swift.common.ring import Ring
from collections import Counter
ring_file = sys.argv[1]
try:
excludes = sys.argv[2].split(",")
except:
excludes = "123.123.123.123"
r = Ring(ring_file)
devices = [device for device in r.devs if device and device['weight']]
hosts = set()
for dev in devices:
hosts.add(dev["ip"])
c = Counter()
for host in hosts:
c[host] = 0
print("%s hosts" % len(hosts))
if "123.123.123.123" not in excludes:
print("excluding: %s" % excludes)
for part in xrange(r.partition_count):
nodes = [x["ip"] for x in r.get_part_nodes(part) if x["ip"] not in excludes]
more_nodes = r.get_more_nodes(part)
while len(nodes) < 3:
handoff = more_nodes.next()["ip"]
if handoff not in excludes:
nodes.append(handoff)
for node in nodes:
c[node] += 1
for ip in c:
print("%s: %s" % (ip, c[ip]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment