import gevent import gevent.pool import gevent.queue import gevent.monkey; gevent.monkey.patch_all() import itertools import optparse import os import sys import time import traceback import random import yaml import realistic import common NANOSECOND = int(1e9) def writer(bucket, objname, fp, queue): key = bucket.new_key(objname) result = dict( type='w', bucket=bucket.name, key=key.name, ) start = time.time() try: key.set_contents_from_file(fp) except gevent.GreenletExit: raise except Exception as e: # stop timer ASAP, even on errors end = time.time() result.update( error=dict( msg=str(e), traceback=traceback.format_exc(), ), ) # certain kinds of programmer errors make this a busy # loop; let parent greenlet get some time too time.sleep(0) else: end = time.time() elapsed = end - start result.update( start=start, duration=int(round(elapsed * NANOSECOND)), chunks=fp.last_chunks, ) queue.put(result) def reader(bucket, objname, queue): key = bucket.new_key(objname) fp = realistic.FileVerifier() result = dict( type='r', bucket=bucket.name, key=key.name, ) start = time.time() try: key.get_contents_to_file(fp) except gevent.GreenletExit: raise except Exception as e: # stop timer ASAP, even on errors end = time.time() result.update( error=dict( msg=str(e), traceback=traceback.format_exc(), ), ) # certain kinds of programmer errors make this a busy # loop; let parent greenlet get some time too time.sleep(0) else: end = time.time() if not fp.valid(): result.update( error=dict( msg='md5sum check failed', ), ) elapsed = end - start result.update( start=start, duration=int(round(elapsed * NANOSECOND)), chunks=fp.chunks, ) queue.put(result) def parse_options(): parser = optparse.OptionParser( usage='%prog [OPTS]