<s> import socket <EOL> import string <EOL> from supervisor . medusa import asyncore_25 as asyncore <EOL> from supervisor . medusa import asynchat_25 as asynchat <EOL> class test_client ( asynchat . async_chat ) : <EOL> ac_in_buffer_size = <NUM_LIT> <EOL> ac_out_buffer_size = <NUM_LIT> <EOL> total_in = <NUM_LIT:0> <EOL> concurrent = <NUM_LIT:0> <EOL> max_concurrent = <NUM_LIT:0> <EOL> def __init__ ( self , addr , chain ) : <EOL> asynchat . async_chat . __init__ ( self ) <EOL> self . create_socket ( socket . AF_INET , socket . SOCK_STREAM ) <EOL> self . set_terminator ( '<STR_LIT>' ) <EOL> self . connect ( addr ) <EOL> self . push ( chain ) <EOL> def handle_connect ( self ) : <EOL> test_client . concurrent = test_client . concurrent + <NUM_LIT:1> <EOL> if ( test_client . concurrent > test_client . max_concurrent ) : <EOL> test_client . max_concurrent = test_client . concurrent <EOL> def handle_expt ( self ) : <EOL> print '<STR_LIT>' <EOL> self . close ( ) <EOL> def close ( self ) : <EOL> test_client . concurrent = test_client . concurrent - <NUM_LIT:1> <EOL> asynchat . async_chat . close ( self ) <EOL> def collect_incoming_data ( self , data ) : <EOL> test_client . total_in = test_client . total_in + len ( data ) <EOL> def found_terminator ( self ) : <EOL> pass <EOL> def log ( self , * args ) : <EOL> pass <EOL> import time <EOL> class timer : <EOL> def __init__ ( self ) : <EOL> self . start = time . time ( ) <EOL> def end ( self ) : <EOL> return time . time ( ) - self . start <EOL> def build_request_chain ( num , host , request_size ) : <EOL> s = '<STR_LIT>' % ( request_size , host ) <EOL> sl = [ s ] * ( num - <NUM_LIT:1> ) <EOL> sl . append ( <EOL> '<STR_LIT>' % ( <EOL> request_size , host <EOL> ) <EOL> ) <EOL> return string . join ( sl , '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import string <EOL> import sys <EOL> if len ( sys . argv ) != <NUM_LIT:6> : <EOL> print '<STR_LIT>' % sys . argv [ <NUM_LIT:0> ] <EOL> else : <EOL> host = sys . argv [ <NUM_LIT:1> ] <EOL> ip = socket . gethostbyname ( host ) <EOL> [ port , request_size , num_requests , num_conns ] = map ( <EOL> string . atoi , sys . argv [ <NUM_LIT:2> : ] <EOL> ) <EOL> chain = build_request_chain ( num_requests , host , request_size ) <EOL> t = timer ( ) <EOL> for i in range ( num_conns ) : <EOL> test_client ( ( host , port ) , chain ) <EOL> asyncore . loop ( ) <EOL> total_time = t . end ( ) <EOL> total_bytes = test_client . total_in <EOL> num_trans = num_requests * num_conns <EOL> throughput = float ( total_bytes ) / total_time <EOL> trans_per_sec = num_trans / total_time <EOL> sys . stderr . write ( '<STR_LIT>' % total_time ) <EOL> sys . stderr . write ( '<STR_LIT>' % num_trans ) <EOL> sys . stderr . write ( '<STR_LIT>' % total_bytes ) <EOL> sys . stderr . write ( '<STR_LIT>' % throughput ) <EOL> sys . stderr . write ( '<STR_LIT>' % trans_per_sec ) <EOL> sys . stderr . write ( '<STR_LIT>' % test_client . max_concurrent ) <EOL> sys . stdout . write ( <EOL> string . join ( <EOL> map ( str , ( num_conns , num_requests , request_size , throughput , trans_per_sec ) ) , <EOL> '<STR_LIT:U+002C>' <EOL> ) + '<STR_LIT:\n>' <EOL> ) </s>
