Last active
April 20, 2016 20:38
-
-
Save acdha/626daedaafa1226fe25f916cbc193ab6 to your computer and use it in GitHub Desktop.
Quick and dirty scripts to measure performance of IIIF servers
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| """ | |
| Collect test URLs using something like this:: | |
| for collection in https://www.loc.gov/{maps,photos,newspapers}/collections/; do | |
| for item in $(http "${collection}?fo=json" | jq -r '.featured_items[] | .url'); do | |
| http "https://www.loc.gov$(echo $item | sed -e 's/^.*\/item/\/item/' )?fo=json" | extract-urls | grep -E '(iiif|[.]jp2)'; | |
| done; | |
| done | |
| """ | |
| import fileinput | |
| IIIF_SUFFIXES = [ | |
| '/full/!128,128/180/default.jpg', | |
| '/full/!510,510/0/default.jpg', | |
| '/full/!510,510/90/default.jpg', | |
| '/0,0,256,256/full/0/default.jpg', | |
| '/256,256,512,512/full/0/default.jpg', | |
| '/info.json', | |
| ] | |
| with open('tile.loc.gov.urls', 'w') as prod_urls, open('iipimage.urls', 'w') as iip_urls: | |
| for image_id in fileinput.input(): | |
| image_id = image_id.strip() | |
| for suffix in IIIF_SUFFIXES: | |
| print('http://rdcvld04.loctest.gov/%s.jp2%s' % (image_id.strip('/'), suffix), | |
| file=iip_urls) | |
| print('http://tile.loc.gov/image-services/iiif/%s%s' % (image_id.replace('/', ':'), suffix), | |
| file=prod_urls) |
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| import fileinput | |
| import random | |
| import sys | |
| from statistics import median | |
| import requests | |
| def measure_url(url): | |
| runs = [] | |
| for i in range(0, 5): | |
| r = requests.get(url) | |
| r.raise_for_status() | |
| runs.append(r.elapsed.total_seconds()) | |
| return runs | |
| urls = [i.strip() for i in fileinput.input()] | |
| random.shuffle(urls) | |
| print('{:10s}{:10s}{:10s}\t{}'.format("Max", "Median", "Min", "URL")) | |
| for url in urls: | |
| try: | |
| runs = measure_url(url) | |
| except KeyboardInterrupt: | |
| sys.exit(1) | |
| except IOError as exc: | |
| print(exc, file=sys.stderr) | |
| continue | |
| print('{max:8.2f}{median:8.2f}{min:8.2f}\t{url}'.format(median=median(runs), | |
| min=min(runs), | |
| max=max(runs), | |
| url=url)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment