<s> import asyncore <EOL> import socket <EOL> import string <EOL> import sys <EOL> def blurt ( thing ) : <EOL> sys . stdout . write ( thing ) <EOL> sys . stdout . flush ( ) <EOL> total_sessions = <NUM_LIT:0> <EOL> class http_client ( asyncore . dispatcher_with_send ) : <EOL> def __init__ ( self , host = '<STR_LIT:127.0.0.1>' , port = <NUM_LIT> , uri = '<STR_LIT:/>' , num = <NUM_LIT:10> ) : <EOL> asyncore . dispatcher_with_send . __init__ ( self ) <EOL> self . create_socket ( socket . AF_INET , socket . SOCK_STREAM ) <EOL> self . host = host <EOL> self . port = port <EOL> self . uri = uri <EOL> self . num = num <EOL> self . bytes = <NUM_LIT:0> <EOL> self . connect ( ( host , port ) ) <EOL> def log ( self , * info ) : <EOL> pass <EOL> def handle_connect ( self ) : <EOL> self . connected = <NUM_LIT:1> <EOL> self . send ( '<STR_LIT>' % self . uri ) <EOL> def handle_read ( self ) : <EOL> d = self . recv ( <NUM_LIT> ) <EOL> self . bytes = self . bytes + len ( d ) <EOL> def handle_close ( self ) : <EOL> global total_sessions <EOL> self . close ( ) <EOL> total_sessions = total_sessions + <NUM_LIT:1> <EOL> if self . num : <EOL> http_client ( self . host , self . port , self . uri , self . num - <NUM_LIT:1> ) <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> from asyncore import socket_map , poll <EOL> MAX = <NUM_LIT:0> <EOL> def loop ( timeout = <NUM_LIT> ) : <EOL> global MAX <EOL> while socket_map : <EOL> if len ( socket_map ) > MAX : <EOL> MAX = len ( socket_map ) <EOL> poll ( timeout ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if len ( sys . argv ) < <NUM_LIT:6> : <EOL> print '<STR_LIT>' % sys . argv [ <NUM_LIT:0> ] <EOL> else : <EOL> [ host , port , uri , hits , num ] = sys . argv [ <NUM_LIT:1> : ] <EOL> hits = string . atoi ( hits ) <EOL> num = string . atoi ( num ) <EOL> port = string . atoi ( port ) <EOL> t = timer ( ) <EOL> clients = map ( lambda x : http_client ( host , port , uri , hits - <NUM_LIT:1> ) , range ( num ) ) <EOL> loop ( ) <EOL> total_time = t . end ( ) <EOL> print ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> num , <EOL> hits , <EOL> total_sessions , <EOL> total_time , <EOL> total_sessions / total_time <EOL> ) <EOL> ) <EOL> print '<STR_LIT>' % ( MAX ) </s>
