0

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() 
2
  • 1
    Possible duplicate of Threading in Python Commented Dec 16, 2015 at 17:42
  • Why do you want to write a multi threaded server? I guess reusing is better than reinventing. Multiple threads and not processes? Commented Dec 16, 2015 at 18:23

1 Answer 1

1

Actually Apache is a single threaded benchmark tool and Time taken for tests: is the time taken by the 'ab' to start test ..

Concurrency versus Threads

Note that ApacheBench will only use one operating system thread regardless of the concurrency level (specified by the -c parameter). In some cases, especially when benchmarking high-capacity servers, a single instance of ApacheBench can itself be a bottleneck. When using ApacheBench on hardware with multiple processor cores, additional instances of ApacheBench may be used in parallel to more fully saturate the target URL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.