views:

235

answers:

6

I am leasing a dedicated web server.

I have a Python web-application.

Which configuration option (CGI, FCGI, mod_python, Passenger, etc) would result in Python being served the fastest on my web server and how do I set it up that way?

UPDATE:

Note, I'm not using a Python framework such as Django or Pylons.

A: 

You don't usually just serve Python, you serve a specific web server or framework based on Python. eg. Zope, TurboGears, Django, Pylons, etc. Although they tend to be able to operate on different web server back-ends (and some provide an internal web server themselves), the best solution will depend on which one you use.

Kylotan
I'm not using a framework. My Python web-application is "old school"
Niki
@Kylotan - not everyone uses a framework...
Yuval A
I agree that a framework should be used--even a microframework like web.py or Werkzeug. "Old school" web apps are notoriously vulnerable if made by unexperienced programmers.
alecwh
I know not everyone uses a framework. But Python by itself is not something you can intrinsically deploy for the web like PHP is. If it's a CGI application, then that's fine, but it wasn't specified in the question, and it has a bearing on the answer.
Kylotan
+8  A: 

I usually go the Apache + mod_wsgi route. It is pretty easy to set up.

To answer your question about speed, I pulled this from the provided link:

The mod_wsgi module is written in C code directly against the internal Apache and Python application programming interfaces. As such, for hosting WSGI applications in conjunction with Apache it has a lower memory overhead and performs better than existing WSGI adapters for mod_python or alternative FASTCGI/SCGI/CGI or proxy based solutions.

t3k76
So mod_wgsi is faster (request/sec) than CGI or Passenger, etc?
Niki
mod_wsgi in daemon mode allows Apache to be faster by interleaving the static content requests (which your code should **not** handle) with requests for HTML that go to your code.
S.Lott
And CGI is painfully slow since Apache must (technically) fork a separate process for each CGI request. mod_wsgi avoids this overhead by (a) daemon mode or (b) initiating Python within Apache (a memory hog and not a big improvement over daemon mode).
S.Lott
A: 

Use Apache + mod_python. It's usually the easiest way and it performs very well.

Edit: additionally, as it turns out, it is also considered a dead project. So that might factor into your decision. That said, mod_wsgi is the preferred alternative.

Yuval A
So mod_python is faster (request/sec) than CGI or Passenger?
Niki
[`mod_python` is dead](http://blog.dscpl.com.au/2010/06/modpython-project-is-now-officially.html)
SilentGhost
@Niki - no clear cut answer, highly dependent on your app.
Yuval A
mod_python has been officially moved to the Apache Attic, see - http://blog.dscpl.com.au/2010/06/modpython-project-is-now-officially.html ... mod_wsgi is its replacement
pycruft
This is a bad idea... mod_python is ancient and (as stated) dead.
alecwh
A: 

Tornado is an impressive high performance Python web server. It has it's own framework, but the speed/page load statistics are all the buzz right now.

Apache2 and WSGI is my other suggestion.

alecwh
Just be aware that their initial published benchmarks were highly misleading. They compared a Tornado hello world program to full Django stack. So, of course Tornado is going to look better. People who have down equal comparisons have not found such a significant difference.
Graham Dumpleton
Graham: Thanks a lot for informing me of that. Can you link me to some accurate comparisons?
alecwh
+1  A: 

Don't get carried away with trying to work out what is the fastest web server. All you will do in doing that is waste your time. This is because the web server is nearly never the bottleneck if you set them up properly. The real bottleneck is your web application, database access etc.

As such, choose whatever web hosting system you think meets your general requirements and which you find easy to setup and manage. Using something you understand and which doesn't require lots of time devoted to it, means you can then focus your valuable time on making your application perform better, thus reducing the real bottleneck.

Graham Dumpleton
A: 

You may use pure python wsgi server (see benchmark) with microframework (like Bottle, Flask)

nazca