Skip to content

Instantly share code, notes, and snippets.

@breu
Last active August 29, 2015 14:01
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 breu/11544202 to your computer and use it in GitHub Desktop.
Save breu/11544202 to your computer and use it in GitHub Desktop.
swift ring-tester.py
#!/usr/bin/env python
from swift.common.ring import Ring
from swift.common.utils import hash_path
import random
import locale
locale.setlocale(locale.LC_ALL, '')
ring_file = "/home/rack/object.ring.gz"
account = "test"
container = "test"
obj="mytestfilename"
disk_hash={}
ring = Ring(ring_file)
fixed = 1000000
sizes = {
'4096': [],
'8192': [],
'16384': [],
'32768': [],
'65536': [],
'131072': [],
'262144': [],
'524288': [],
'1048576': [],
'2097152': [],
'4194304': [],
'8388608': [],
}
for i in sizes.keys():
x = random.randrange(0,fixed)
for r in range(1,x):
sizes[i].append('x')
fixed = fixed - x
for j in sizes.keys():
print "%s: %s" % (j,len(sizes[j]))
for i in xrange(len(sizes[j])):
find_obj='%s%d' % (obj,i)
hash_str = hash_path(account,container,find_obj)
part,nodes=ring.get_nodes(account,container,find_obj)
str='%s,%s,%s,%s,%s,' % (account,container,find_obj,part,hash_str)
for node in nodes:
node_id = '%s:%s,' % (node['ip'], node['device'])
str += node_id
if not node_id in disk_hash:
disk_hash[node_id]={}
disk_hash[node_id]["count"]=0
disk_hash[node_id]["used"]=0
for jj in sizes.keys():
disk_hash[node_id][jj]=0
disk_hash[node_id]["count"]+=1
disk_hash[node_id]["used"]+=int(j)
disk_hash[node_id][j]+=1
str+='%d' % i
#print str
min_used=0
max_used=0
for nodes in disk_hash:
print "%s: %d (%d) bytes (MB=%d, GB=%d)" % (nodes,disk_hash[nodes]["count"],
disk_hash[nodes]["used"],
disk_hash[nodes]["used"] / 2**20,
disk_hash[nodes]["used"] / 2**30)
if disk_hash[nodes]["used"]<min_used or min_used==0:
min_used=disk_hash[nodes]["used"]
if disk_hash[nodes]["used"]>max_used:
max_used=disk_hash[nodes]["used"]
for jj in sizes.keys():
print "\t%s:%d" % (jj,disk_hash[nodes][jj])
print "min used: %s MB" % locale.format("%d", (min_used / 2**20),grouping=True)
print "max used: %s MB" % locale.format("%d", (max_used / 2**20),grouping=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment