I’m developing webapplications running under mod_python for a long time. I’m not very satisfied with the mod_python performance particularly the first load time so I’m looking for something like an application server – loaded modules will stay “longer” in the memory – application doesn’t need to be completely initialized very often. The FastCGI approach is very close. I ran benchmarks to measure overhead of the FastCGI (mod_fastcgi, mod_fcgid) compared to the mod_python.
configuration: Mobile AMD Sempron 3100+, Ubuntu Hardy, Ubuntu’s version of fcgid is segfaulting so I borrowed the module from Debian Lenny, mods are in the default configuration, no tweaking
Benchmarking methodics:
- many keep-alive requests
# ab -k -c 1 -n 10000 http://lo/...
- startup time
# /etc/init.d/apache2 restart # sleep 1 # ab -c 1 -n 1 http://lo/...
- concurrent access
# ab -c 30 -n 5000 http://lo/...
Simple “hello world”
mod_python:
from mod_python import apache def handler(req): req.content_type = 'text/plain' req.write("Hello World!") return apache.OK |
FastCGI:
from fcgi import WSGIServer def myapp(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) yield 'Hello World!\n' WSGIServer(myapp).run() |
results:
mod_python | mod_fastcgi | mod_fcgid | |
overhead (ms/req) | 1.27 | 2.71 | 1.85 |
startup time (ms/req) | 82 | 500 | 39 |
concurrent (ms/req) | 1.21 | 2.61 | 2 |
Summary
Result is that the overhead difference is almost insignificant. mod_fcgid seems to be a good adept.
Next time I will focus more on tuning the FastCGI implementations and solutions for larger applications (longer load time).