Website using Python--what's best architecture? CGI?
andy at reportlab.com
Thu Mar 20 22:42:54 CET 2003
>So, don't CGI ! Programming a CGI highly dynamic site is a hassle, even with
>the help of a templating or HTML generator package (like HTMLGen and
I disagree. Several years of making reporting 'add-ons' to other
people's app servers, which are usually CGI scripts, has taught
me something very interesting. Our apps consistently respond
several times faster than the big Websphere or ASP systems that
talk to them. The other systems have usually been written by
large numbers of smart programmers over time and tend to get
big and slow as they add more features, or maybe just because
they have a heck of a lot of code to execute in their main loops..
I also think that how the process is initiated (which is what CGI is
about) has absolutely nothing to do with the framework you use or
don't use. You can make a simple, clean dispatch mechanism
and a few utilities to preserve state with tokens in very few lines
of code. And if your web frame work is <1000 lines of Python
code, which is plenty, there won't be a big startup overhead.
Please measure for yourself the actual time taken to execute a
'hello world' type page which does one query and formats
the output on the different frameworks you are considering.
I usually find the startup overhead is < 0.1 seconds. Then
consider the benefits of never having to worry about
a memory leak, contend with bugs in large frameworks,
restart an app server or whatever.
Web architectures are like all other optimisation issues in
programming: don't guess what the results will be without
measuring, and don't optimize if the simple solution is
already fast enough.
>In addition, playing with CGI means creating a new DB connector for each
>request when (most) Web application servers handle open DB connections pools
True, but...please measure the connection overhead. I constantly hear
this old thing about database connections taking time and resources,
but on the environments I have worked with most (Sybase and MySQL,
with the database in the same server rack as the app server), the
connect-query-disconnect time is almost identical to the straight
OTOH I was told once that Oracle could take seconds and allocate
megabytes of RAM for each connection.
This would be a really fun topic for a Python conference:
set a simple task and actually test and benchmark all those
web frameworks. ;-)
More information about the Python-list