<s> __author__ = '<STR_LIT>' <EOL> import gevent <EOL> import random <EOL> from pyon . datastore . datastore import DatastoreManager <EOL> from pyon . public import IonObject <EOL> import ooi . timer <EOL> """<STR_LIT>""" <EOL> class CouchConcurrencyEval ( object ) : <EOL> def __init__ ( self ) : <EOL> from pyon . core . bootstrap import container_instance <EOL> self . container = container_instance <EOL> self . rr = self . container . resource_registry <EOL> self . rr_store = DatastoreManager . get_datastore_instance ( "<STR_LIT>" ) <EOL> self . timer = ooi . timer . Timer ( ) <EOL> def prepare_scenario1 ( self , nums ) : <EOL> num_objects = nums . get ( "<STR_LIT>" , <NUM_LIT> ) <EOL> self . res_objs = [ IonObject ( "<STR_LIT>" , name = "<STR_LIT>" + str ( i ) ) for i in xrange ( num_objects ) ] <EOL> res = self . rr_store . create_mult ( self . res_objs ) <EOL> self . res_ids = [ res_id for _ , res_id , _ in res ] <EOL> self . timer . complete_step ( '<STR_LIT>' ) <EOL> self . rr_store . read_doc ( self . res_ids [ <NUM_LIT:0> ] ) <EOL> self . timer . complete_step ( '<STR_LIT>' ) <EOL> def run_cceval1 ( self , nums ) : <EOL> num_read = nums . get ( "<STR_LIT>" , <NUM_LIT> ) <EOL> num_thread = nums . get ( "<STR_LIT>" , <NUM_LIT:5> ) <EOL> def _proc ( ) : <EOL> for i in xrange ( int ( num_read / num_thread ) ) : <EOL> res_obj = self . rr . read ( self . res_ids [ random . randint ( <NUM_LIT:0> , len ( self . res_ids ) - <NUM_LIT:1> ) ] ) <EOL> gls = [ gevent . spawn ( _proc ) for i in xrange ( num_thread ) ] <EOL> gevent . joinall ( gls ) <EOL> self . timer . complete_step ( '<STR_LIT>' ) <EOL> def _proc ( ) : <EOL> rr_store = DatastoreManager . get_datastore_instance ( "<STR_LIT>" ) <EOL> for i in xrange ( int ( num_read / num_thread ) ) : <EOL> res_obj = rr_store . read ( self . res_ids [ random . randint ( <NUM_LIT:0> , len ( self . res_ids ) - <NUM_LIT:1> ) ] ) <EOL> gls = [ gevent . spawn ( _proc ) for i in xrange ( num_thread ) ] <EOL> gevent . joinall ( gls ) <EOL> self . timer . complete_step ( '<STR_LIT>' ) <EOL> self . timer . complete_step ( '<STR_LIT:end>' ) <EOL> def print_timers ( self ) : <EOL> prior_t = <NUM_LIT:0> <EOL> for l , t in self . timer . times : <EOL> print l , t - prior_t <EOL> prior_t = t <EOL> def runcc ( nums = None ) : <EOL> nums = nums if nums is not None else { } <EOL> cce = CouchConcurrencyEval ( ) <EOL> cce . prepare_scenario1 ( nums ) <EOL> cce . run_cceval1 ( nums ) <EOL> cce . print_timers ( ) </s>
