Skip to content

Instantly share code, notes, and snippets.

@BoboTiG
Last active January 25, 2018 08:38
Show Gist options
  • Save BoboTiG/1ad8b1f4c1b2a453d674115bb479b75c to your computer and use it in GitHub Desktop.
Save BoboTiG/1ad8b1f4c1b2a453d674115bb479b75c to your computer and use it in GitHub Desktop.
Concurrent calls to NuxeoDrive.GetChangeSummary.
# coding: utf-8
"""
Requires Python 3 and the Python client >= 2.0.0.
Usage:
python get_change_summary.py --users=30
"""
import argparse
import sys
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
from nuxeo.client import Nuxeo
URL = 'http://localhost:8080/nuxeo/'
AUTH = ('Administrator', 'Administrator')
NUXEO = Nuxeo(host=URL, auth=AUTH, timeout=60 * 5)
STATS = {'ok': 0, 'ko': 0, 'offset': 1}
def concurrent(users=1):
with ThreadPoolExecutor(max_workers=users) as executor:
futures = [executor.submit(get, uid + 1) for uid in range(users)]
for future in as_completed(futures):
future.result()
def sequential(users=1):
for uid in range(users):
get(uid + 1)
def get(uid):
start = time.time()
data = NUXEO.operations.execute(
command='NuxeoDrive.GetChangeSummary',
params={'lowerBound': 0},
default='')
end = time.time()
if not data:
status, events = False, 0
STATS['ko'] += 1
else:
status, events = True, len(data['fileSystemChanges'])
STATS['ok'] += 1
print('>>> User {:•>{}} OK={} (events={}), time={}s'.format(
uid, STATS['offset'], status, events, int(end - start)))
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--users', type=int, default=1, help='Number of users.')
parser.add_argument(
'--sequential', action='store_true', help='One request at a time.')
args = parser.parse_args(sys.argv[1:])
STATS['offset'] = len(str(args.users))
print('Simulating', args.users, 'users calling GetChangeSummary ... ')
start = time.time()
(concurrent, sequential)[args.sequential](users=args.users)
end = time.time()
print('Requests: good={ok} bad={ko} (success={0}%), elapsed={1}s'.format(
int(STATS['ok'] * 100 / args.users), int(end - start), **STATS))
if __name__ == '__main__':
exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment