Skip to content

Instantly share code, notes, and snippets.

@RafeKettler
Created May 17, 2011 15:07
Show Gist options
  • Save RafeKettler/976645 to your computer and use it in GitHub Desktop.
Save RafeKettler/976645 to your computer and use it in GitHub Desktop.
Stack overflow CDN request test in Python
#!/usr/bin/env python
"""
CDN tester for SO. Designed to make lives easier.
Usage:
python request_test.py # for default number of tries, 20
python request_test.py 100 # for a specific number of tries
Rafe Kettler, public domain.
"""
import sys
import urllib2
from time import time
sites = {'sstatic' : 'http://sstatic.net/js/full.js',
'NetDNA' : 'http://sstatic.stackexchange.netdna-cdn.com/js/full.js',
'Amazon' : 'http://d1d5ue6vu5b30i.cloudfront.net/js/full.js',
'EdgeCast' : 'http://wac.43df.edgecastcdn.net/8043DF/sstatic/js/full.js',
}
def measure_response_time(url, requests):
total_time = 0
for i in range(requests):
start = time()
urllib2.urlopen(url).read()
elapsed = time() - start
total_time += elapsed
return float(total_time * 1000) / requests
if __name__ == '__main__':
try:
tries = int(sys.argv[1])
except IndexError:
tries = 20
for name, url in sites.items():
average_response = measure_response_time(url, tries)
print "%s: %fms average over %d tries" % (name, average_response, tries)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment