CGI vs twisted vs mod_python

Steven Armstrong <[email protected]>
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
I've run a few tests with a neat idea I found on Bill's blog (timeurl.py).

Here a few numbers comparing cgi, twisted and mod_python:
Between the 2 test runs apache and twisted were restarted
and all *.pyc file's were removed.


---------- With 5 blog entries ----------

1 request: -----------------
first run:
CGI         : 0.627060890198
WSGI-CGI    : 0.57884311676
twisted     : 0.722832918167
mod_python  : 0.524918079376

second run:
CGI         : 0.489893913269
WSGI-CGI    : 0.534939050674
twisted     : 0.77103304863
mod_python  : 0.0480790138245


100 requests: --------------
first run:
CGI         : 48.792345047
WSGI-CGI    : 48.2621901035
twisted     : 99.5655610561
mod_python  : 7.2256770134

second run:
CGI         : 49.7383179665
WSGI-CGI    : 50.3378739357
twisted     : 100.032269955
mod_python  : 4.65755105019



---------- With 2795 blog entries ----------

1 request: -----------------
first run:
CGI         : 2.38962101936
WSGI-CGI    : 2.3695230484
twisted     : 2.65319085121
mod_python  : 2.41627717018

second run:
CGI         : 2.24685406685
WSGI-CGI    : 2.31155514717
twisted     : 1.37736415863
mod_python  : 1.12132692337


100 requests: --------------
first run:
CGI         : 235.439440966
WSGI-CGI    : 236.187808037
twisted     : 199.473860025
mod_python  : 117.538961172

second run:
CGI         : 229.891646862
WSGI-CGI    : 227.116400003
twisted     : 199.379323006
mod_python  : 106.703619957


Interesting was that with CGI and mod_python the CPU was at 99% while
with twisted it was at +-50%.

cheers
Steven


here's the script:

#!/usr/bin/env python
import urllib
import timeit

url = urllib.URLopener()

test_cases = [
    {'label': 'CGI         :', 'page': "http://www.c-area.lan/blog/"},
    {'label': 'WSGI-CGI    :', 'page': "http://www.c-area.lan/weblog-cgi/"},
    {'label': 'twisted     :', 'page': "http://localhost:8080/"},
    {'label': 'mod_python  :', 'page': "http://www.c-area.lan/weblog/"}
]

def run_test_cases(cases, num_of_tests):
    for case in cases:
        t = timeit.Timer('url.open("%s").read()' % case['page'], \
            'from __main__ import url')
        print case['label'],
        print t.timeit(num_of_tests)

print "1 request: -----------------"
print "first run:"
run_test_cases(test_cases, 1)
print
print "second run:"
run_test_cases(test_cases, 1)
print "\n"

print "100 requests: --------------"
print "first run:"
run_test_cases(test_cases, 100)
print
print "second run:"
run_test_cases(test_cases, 100)



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.