I am newbie for implementing multithread web server in python. I searched the internet and found some resources to make it.After that I tested in apachebench via this command :
ab -n 1000 -c 5 localhost:8888/
Results for this command :
Concurrency Level: 5
Time taken for tests: 1.692 seconds
Complete requests: 1000
Failed requests: 0
Requests per second: 591.16 [#/sec] (mean)
Time per request: 8.458 [ms] (mean)
Time per request: 1.692 [ms] (mean, across all concurrent requests)
ab -n 1000 -c 100 localhost:8888/
Results :
Concurrency Level: 100
Time taken for tests: 1.699 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 12078000 bytes
HTML transferred: 12000000 bytes
Requests per second: 588.50 [#/sec] (mean)
Time per request: 169.923 [ms] (mean)
Time per request: 1.699 [ms] (mean, across all concurrent requests)
Transfer rate: 6941.33 [Kbytes/sec] received
Now , My question is that Why these values(time taken for tests and request per second ..) is not change noticeable ? Can anyone interpret this test results ?
Code:
import thread
import socket
import sys
def threadFunction(client_connection,client_address):
print 'Client thread created..'
request = client_connection.recv(1024)
print request
if request=="":
sys.exit()
client_connection.send("HTTP/1.1 400 bad request\nContent-Type: text/html; charset=UTF-8\nContent-Lenght: "+b)
client_connection.close()
HOST, PORT = '', 8888
listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_socket.bind((HOST, PORT))
listen_socket.listen(100)
while True:
print 'Serving HTTP on port %s ...' % PORT
client_connection, client_address = listen_socket.accept()
print 'client_connection: %s , client_address : %s' % (client_connection,client_address)
try:
thread.start_new_thread( threadFunction, (client_connection,client_address) )
except IOError:
print "Failed in initialize thread.."
listen_socket.close()