update from Atlas

This commit is contained in:
Luciano Ramalho
2014-12-29 03:51:34 -02:00
parent 9db73c75ef
commit 08b7bce340
12 changed files with 801 additions and 21 deletions

View File

@@ -16,7 +16,11 @@ NGINX_URL = 'http://localhost:8080/ciaflags/{gec}.gif'
# Vaurien
VAURIEN_URL = 'http://localhost:8000/ciaflags/{gec}.gif'
BASE_URL = VAURIEN_URL
SOURCE_URLS = {
'CIA' : CIA_URL,
'NGINX' : NGINX_URL,
'VAURIEN' : VAURIEN_URL,
}
DEST_PATH_NAME = 'img/{cc}.gif'
@@ -34,8 +38,9 @@ def _load():
cc2gec[iso_cc] = gec
def flag_url(iso_cc):
return BASE_URL.format(gec=cc2gec[iso_cc].lower())
def flag_url(iso_cc, source='CIA'):
base_url = SOURCE_URLS[source.upper()]
return base_url.format(gec=cc2gec[iso_cc].lower())
def iso_file_name(iso_cc):
return DEST_PATH_NAME.format(cc=iso_cc.lower())

View File

@@ -5,8 +5,8 @@ import time
times = {}
def fetch(iso_cc):
resp = requests.get(cf.flag_url(iso_cc))
def fetch(iso_cc, source):
resp = requests.get(cf.flag_url(iso_cc, source))
if resp.status_code != 200:
resp.raise_for_status()
file_name = cf.iso_file_name(iso_cc)
@@ -14,7 +14,7 @@ def fetch(iso_cc):
written = img.write(resp.content)
return written, file_name
def main():
def main(source):
pending = sorted(cf.cc2name)
to_download = len(pending)
downloaded = 0
@@ -23,7 +23,7 @@ def main():
print('get:', iso_cc)
try:
times[iso_cc] = [time.time() - t0]
octets, file_name = fetch(iso_cc)
octets, file_name = fetch(iso_cc, source)
times[iso_cc].append(time.time() - t0)
downloaded += 1
print('\t--> {}: {:5d} bytes'.format(file_name, octets))
@@ -36,7 +36,14 @@ def main():
print('{}\t{:.6g}\t{:.6g}'.format(iso_cc, start, end))
if __name__ == '__main__':
main()
import argparse
source_names = ', '.join(sorted(cf.SOURCE_URLS))
parser = argparse.ArgumentParser(description='Download flag images.')
parser.add_argument('source', help='one of: ' + source_names)
args = parser.parse_args()
main(args.source)
"""
From cia.gov:
@@ -53,4 +60,4 @@ From localhost nginx via Vaurien with .5s delay
real 1m40.519s
user 0m1.103s
sys 0m0.243s
"""
"""

View File

@@ -11,7 +11,7 @@ GLOBAL_TIMEOUT = 300 # seconds
times = {}
def main(num_threads):
def main(source, num_threads):
pool = futures.ThreadPoolExecutor(num_threads)
pending = {}
t0 = time.time()
@@ -19,7 +19,7 @@ def main(num_threads):
for iso_cc in sorted(cf.cc2name):
print('get:', iso_cc)
times[iso_cc] = [time.time() - t0]
job = pool.submit(fetch, iso_cc)
job = pool.submit(fetch, iso_cc, source)
pending[job] = iso_cc
to_download = len(pending)
downloaded = 0
@@ -39,18 +39,23 @@ def main(num_threads):
print('{}\t{:.6g}\t{:.6g}'.format(iso_cc, start, end))
if __name__ == '__main__':
if len(sys.argv) == 2:
num_threads = int(sys.argv[1])
else:
num_threads = DEFAULT_NUM_THREADS
main(num_threads)
import argparse
source_names = ', '.join(sorted(cf.SOURCE_URLS))
parser = argparse.ArgumentParser(description='Download flag images.')
parser.add_argument('source', help='one of: ' + source_names)
parser.add_argument('-t', '--threads', type=int, default=DEFAULT_NUM_THREADS,
help='number of threads (default: %s)' % DEFAULT_NUM_THREADS)
args = parser.parse_args()
main(args.source, args.threads)
"""
From localhost nginx:
real 0m1.163s
user 0m1.001s
sys 0m0.289s
From CIA, 1 thread:
real 2m0.832s
user 0m4.685s
sys 0m0.366s
"""
"""

BIN
concurrency/flags/img.zip Normal file

Binary file not shown.