Created
July 13, 2014 16:22
-
-
Save booxter/c4f3e743a2573ba7809f to your computer and use it in GitHub Desktop.
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
from neutronclient.v2_0.client import Client | |
import timeit | |
import futures | |
c = Client(username='admin', tenant_name='admin', password='1', auth_url='http://127.0.0.1:35357/v2.0') | |
def create_ports(id, n): | |
executor = futures.ThreadPoolExecutor(max_workers=10) | |
for i in range(0, n): | |
executor.submit(c.create_port, {'port': {'network_id': id, 'name': 'port' + str(i)}, 'tenant_id': 'admin'}) | |
executor.shutdown() | |
def delete_ports(id): | |
ports = [port for port in c.list_ports(network_id=id)['ports']] | |
port_ids = [port['id'] for port in ports] | |
for id in port_ids: | |
try: | |
c.delete_port(id) | |
except: | |
pass | |
def create_networks(n): | |
executor = futures.ThreadPoolExecutor(max_workers=10) | |
for i in range(0, n): | |
executor.submit(c.create_network, {'network': {'name': 'bench'}}) | |
#c.create_network({'network': {'name': 'bench'}}) | |
executor.shutdown() | |
def delete_networks(): | |
nets = [net for net in c.list_networks(name='bench')['networks']] | |
net_ids = [net['id'] for net in nets] | |
executor = futures.ThreadPoolExecutor(max_workers=10) | |
for id in net_ids: | |
executor.submit(c.delete_network, id) | |
executor.shutdown() | |
def benchmark(ports, repeat): | |
net = c.create_network({'network': {'name': 'benchmark'}})['network'] | |
subnet = c.create_subnet({'subnet': {'network_id': net['id'], 'cidr': '10.0.0.0/8', 'ip_version': 4, 'name': 'benchmark'}})['subnet'] | |
t = timeit.Timer(lambda: create_ports(net["id"], ports), setup='from __main__ import create_ports, c') | |
results = t.repeat(repeat=repeat, number=1) | |
print('Min: %s, Avg: %s, Max: %s' % (min(results), sum(results) / float(len(results)), max(results))) | |
delete_ports(net['id']) | |
c.delete_subnet(subnet['id']) | |
c.delete_network(net['id']) | |
def benchmark2(networks, repeat): | |
t = timeit.Timer(lambda: create_networks(networks), setup='from __main__ import create_networks, c') | |
results = t.repeat(repeat=repeat, number=1) | |
print('Min: %s, Avg: %s, Max: %s' % (min(results), sum(results) / float(len(results)), max(results))) | |
delete_networks() | |
#benchmark(200, 3) | |
benchmark2(2000, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment