Install run, and benchmark mod_wsgi in < 10 minutes

svn checkout http://modwsgi.googlecode.com/svn/trunk/ modwsgi
cd mod_wsgi
./configure
make
sudo make install
# note where mod_wsgi.so went on your system
echo "LoadModule wsgi_module /path/to/mod_wsgi.so" >> /path/to/apache2.conf

mkdir /var/www/wsgitest/
cd /var/www/wsgitest/

vi .htaccess
# [in .htaccess]
Options +ExecCGI
< Files hi.py >
SetHandler wsgi-script
</Files>
# [ end .htaccess]

vi hi.py
# [in hi.py]

#!/usr/bin/python

import web

class hi(object):
def GET(self,who='world'):
web.header('Content-type','text/html')
print "hello %s" % who

class bye(object):
def GET(self,who='world'):
web.header('Content-type','text/html')
print "bye %s" % who

urls = ( '/bye/?(.*)', 'bye'
,'/hi/?(.*)' , 'hi' )

application = web.wsgifunc(web.webpyfunc(urls, globals()))

#[end hi.py ]


you can then browse to
http://localhost/wsgitest/hi.py/hi/there
# see "hello there"
http://localhost/wsgitest/hi.py/bye/bye%20bye
# see "bye bye bye"



(meaningless) Benchmarking:
change last line in hi.py to:
if __name__ == "__main__": web.run(urls,globals())
and save as cgi.py

cgi
$ ab -n 1000 -c 30 http://localhost/wsgitest/cgi.py/hi/there | grep 'Requests per second'

Requests per second: 4.08 [#/sec] (mean)

wsgi
$ ab -n 1000 -c 30 http://localhost/wsgitest/hi.py/hi/there | grep 'Requests per second'

Requests per second: 351.05 [#/sec] (mean)

Comments

Popular posts from this blog

filtering paired end reads (high throughput sequencing)

python interval tree

needleman-wunsch global sequence alignment -- updates and optimizations to nwalign