Commit b0676909 authored by davebshow's avatar davebshow
Browse files

got rid of old files, set version to beta 1

parent a9a1f6c1
"""Simple benchmark based on aiohttp benchmark client.
https://github.com/KeepSafe/aiohttp/blob/master/benchmark/async.py
"""
import argparse
import asyncio
import collections
import random
import aiogremlin
@asyncio.coroutine
def run(client, count, concurrency, loop):
processed_count = 0
execute = client.execute
inqueue = collections.deque()
popleft = inqueue.popleft
@asyncio.coroutine
def do_bomb():
nonlocal processed_count
while inqueue:
mssg, result = popleft()
try:
resp = yield from execute(mssg)
assert resp[0].status_code == 200, resp[0].status_code
assert resp[0].data[0] == result, resp[0].data[0]
processed_count += 1
except Exception:
raise
for i in range(count):
rnd1 = random.randint(1, 9)
rnd2 = random.randint(1, 9)
mssg = "{} + {}".format(rnd1, rnd2)
result = rnd1 + rnd2
inqueue.append((mssg, result))
bombers = []
for i in range(concurrency):
bomber = asyncio.async(do_bomb(), loop=loop)
bombers.append(bomber)
t1 = loop.time()
yield from asyncio.gather(*bombers, loop=loop)
t2 = loop.time()
mps = processed_count / (t2 - t1)
print("Benchmark complete: {} mps. {} messages in {}".format(
mps, processed_count, t2-t1))
return mps
@asyncio.coroutine
def main(client, tests, count, concurrency, warmups, loop):
execute = client.execute
# warmup
for x in range(warmups):
print("Warmup run {}:".format(x + 1))
yield from run(client, count, concurrency, loop)
print("Warmup successful!")
mps_list = []
for i in range(tests):
# Take a breather between tests.
yield from asyncio.sleep(1)
mps = yield from run(client, count, concurrency, loop)
mps_list.append(mps)
print("Average messages per second: {}".format(
sum(mps_list) / float(len(mps_list))))
ARGS = argparse.ArgumentParser(description="Run benchmark.")
ARGS.add_argument(
'-t', '--tests', action="store",
nargs='?', type=int, default=5,
help='number of tests (default: `%(default)s`)')
ARGS.add_argument(
'-n', '--count', action="store",
nargs='?', type=int, default=5000,
help='message count (default: `%(default)s`)')
ARGS.add_argument(
'-c', '--concurrency', action="store",
nargs='?', type=int, default=16,
help='count of parallel requests (default: `%(default)s`)')
ARGS.add_argument(
'-p', '--poolsize', action="store",
nargs='?', type=int, default=8,
help='num connected websockets (default: `%(default)s`)')
ARGS.add_argument(
'-w', '--warmups', action="store",
nargs='?', type=int, default=10,
help='num warmups (default: `%(default)s`)')
if __name__ == "__main__":
args = ARGS.parse_args()
num_tests = args.tests
num_mssg = args.count
concurr = args.concurrency
poolsize = args.poolsize
num_warmups = args.warmups
loop = asyncio.get_event_loop()
t1 = loop.time()
conn = aiogremlin.GremlinConnector(limit=poolsize)
client = aiogremlin.GremlinClient(ws_connector=conn)
t2 = loop.time()
print("time to establish conns: {}".format(t2 - t1))
try:
print(
"Runs: {}. Warmups: {}. Messages: {}. Concurrency: {}. Poolsize: {}.".format(
num_tests, num_warmups, num_mssg, concurr, poolsize))
main = main(client, num_tests, num_mssg, concurr, num_warmups, loop)
loop.run_until_complete(main)
finally:
loop.run_until_complete(client.close())
loop.close()
print("CLOSED CLIENT AND LOOP")
import argparse
import asyncio
import aiogremlin
@asyncio.coroutine
def create_destroy(loop, factory, poolsize):
client = yield from aiogremlin.create_client(loop=loop,
factory=factory,
poolsize=poolsize)
yield from client.close()
# NEED TO ADD MORE ARGS/CLEAN UP like benchmark.py
ARGS = argparse.ArgumentParser(description="Run benchmark.")
ARGS.add_argument(
'-t', '--tests', action="store",
nargs='?', type=int, default=10,
help='number of tests (default: `%(default)s`)')
ARGS.add_argument(
'-s', '--session', action="store",
nargs='?', type=str, default="false",
help='use session to establish connections (default: `%(default)s`)')
if __name__ == "__main__":
args = ARGS.parse_args()
tests = args.tests
print("tests", tests)
session = args.session
loop = asyncio.get_event_loop()
if session == "true":
factory = aiogremlin.WebSocketSession()
else:
factory = aiogremlin.AiohttpFactory()
print("factory: {}".format(factory))
try:
m1 = loop.time()
for x in range(50):
tasks = []
for x in range(tests):
task = asyncio.async(
create_destroy(loop, factory, 100)
)
tasks.append(task)
t1 = loop.time()
loop.run_until_complete(
asyncio.async(asyncio.gather(*tasks, loop=loop)))
t2 = loop.time()
print("avg: time to establish conn: {}".format(
(t2 - t1) / (tests * 100)))
m2 = loop.time()
print("time to establish conns: {}".format((m2 - m1)))
print("avg time to establish conns: {}".format(
(m2 - m1) / (tests * 100 * 50)))
finally:
loop.close()
print("CLOSED CLIENT AND LOOP")
......@@ -3,9 +3,9 @@ from setuptools import setup
setup(
name='aiogremlin',
version='3.2.4-rc.1',
version='3.2.4b1',
url='',
license='Apache',
license='Apache Software License',
author='davebshow',
author_email='davebshow@gmail.com',
description='Async Gremlin-Python',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment