<s> import zmq <EOL> import json <EOL> import time <EOL> class ClientExample ( object ) : <EOL> def __init__ ( self , server = "<STR_LIT>" ) : <EOL> self . server = server <EOL> self . socket = self . _connect ( ) <EOL> self . count = <NUM_LIT:0> <EOL> self . start_time = None <EOL> def _connect ( self ) : <EOL> print "<STR_LIT>" <EOL> context = zmq . Context ( <NUM_LIT:8> ) <EOL> socket = context . socket ( zmq . REQ ) <EOL> socket . connect ( self . server ) <EOL> return socket <EOL> def send_request ( self , path , params , data ) : <EOL> request = dict ( path = path , params = params , data = data ) <EOL> message = json . dumps ( request ) <EOL> self . socket . send ( message ) <EOL> raw = self . socket . recv ( ) <EOL> resp = json . loads ( raw ) <EOL> return resp <EOL> def start_timer ( self ) : <EOL> self . start_time = time . time ( ) <EOL> def stop_timer ( self ) : <EOL> end_time = time . time ( ) <EOL> run_time = end_time - self . start_time <EOL> print "<STR_LIT>" , self . count / run_time <EOL> def display_progress ( self ) : <EOL> if self . start_time : <EOL> self . count = self . count + <NUM_LIT:1> <EOL> if ( self . count % <NUM_LIT:1000> ) == <NUM_LIT:0> : <EOL> elapsed = time . time ( ) - self . start_time <EOL> print self . count , elapsed , elapsed / self . count , self . count / elapsed <EOL> def run_test ( self , requests = <NUM_LIT> ) : <EOL> path = "<STR_LIT>" <EOL> self . start_timer ( ) <EOL> for x in range ( <NUM_LIT:0> , requests ) : <EOL> self . send_request ( path , params = { } , data = { } ) <EOL> self . display_progress ( ) <EOL> self . stop_timer ( ) <EOL> def create_node ( self ) : <EOL> path = "<STR_LIT>" <EOL> data = dict ( name = "<STR_LIT>" , city = "<STR_LIT>" ) <EOL> params = None <EOL> resp = self . send_request ( path , params , data ) <EOL> print resp <EOL> node_id = resp [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> return node_id <EOL> client = ClientExample ( ) <EOL> client . run_test ( ) </s>
