Skip to content

Instantly share code, notes, and snippets.

@sloppyfocus
Created July 16, 2014 22:27
Show Gist options
  • Save sloppyfocus/8aed3b4dc9d4319c905c to your computer and use it in GitHub Desktop.
Save sloppyfocus/8aed3b4dc9d4319c905c to your computer and use it in GitHub Desktop.
Clusto performance testing script
import logging
import ConfigParser
import clusto
import time
from clusto.drivers import Pool, Driver
DB='sqlite:///:memory:'
def init_clusto():
conf = ConfigParser.ConfigParser()
conf.add_section('clusto')
conf.set('clusto', 'dsn', DB)
conf.set('clusto', 'versioning', '1')
clusto.connect(conf,echo=False)
clusto.clear()
clusto.SESSION.close()
clusto.init_clusto()
def preseed_data():
all_pools = [Pool('p%s' % (i+1,)) for i in xrange(15)]
p1 = all_pools[0]
p2 = all_pools[1]
p1.add_attr('im_a_p1', 1)
p1.add_attr('im_a_p2', 1)
for pool in all_pools:
for i in xrange(5):
pool.add_attr('attr%s'%i, 1)
for i in xrange(500):
d = Driver('d%i' % i)
p1.insert(d)
if i < 10:
p2.insert(d)
if i == 5:
for pool in all_pools[2:]:
pool.insert(d)
if __name__ == '__main__':
logging.basicConfig()
init_clusto()
preseed_data()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
s1 = clusto.get_by_name('d5')
test_start = time.time()
s1.attrs(merge_container_attrs=True)
test_attrs_call = time.time()
clusto.get_from_pools(['p1', 'p2'], clusto_types=['server'])
test_pool_intersection_call = time.time()
print 'Attrs call time: %.4f' % (test_attrs_call - test_start,)
print 'Pool intersection time: %.4f' % (test_pool_intersection_call - test_attrs_call,)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment