[BNE-PM] cgi architecture

Andrew Wild andrew at intervations.com.au
Thu Sep 26 07:53:32 CDT 2002


I have used mod_perl quite a bit. I wrote the search engine I run,
Search66.com in it (http://search66.com) and a currency conversion
service we now sell called JAZConvert (http://jazconvert.com).

There are many, many advantages to using mod_perl. One of them is
persistant database connections. To do this is very simple if you are
using DBI for the connections. When running under mod_perl, you simply
have to replace your use DBI; statement with use Apache::DBI; and bingo
- you have persistant connections. (I use this in both of the above we apps)

What Apache::DBI does is intercepts your connect and disconnect calls.
It overides this methods in DBI with its own - this is how it achieves
the persistance. When a connect call is made, it has a look at its
existing open database connections and compares the db name, username
and password. If they all match, it then returns the database handle
instead of opening a new one.

But persistant DB connections are only one advantage of mod_perl. The
other major benefit is speed. A major performance issue in CGI is that
each time a Perl CGI script is called it has to first load up the Perl
intrepreter and then intrepret the perl script. This takes time.

However, mod_perl loads up the script in memory and wraps your entire
script around a function call. Hence, when a call comes in to your
script it doesn't load the Perl interpreter and intrepret the script,
rather it simply executes the function call - hence, it is MUCH faster.
HOWEVER, this causes your script to be called in a different namespace
then what you may be used to. Hence, it is *very* important that you my
all variables. use strict; is a MUST otherwise you will have lots of
problems and memory leaks everywhere. Also, you should not use global
variables unless you know what you are doing!

Anyway, that is my 2c worth on mod_perl. :)

 From my experience, mod_perl has been invaluable in writing high
performance web based scripts.

However, saying this, PHP also has persistant DB connections now and it
is also very good - but I'll leave that for another email. ;)

Cheers, Andrew.

David Bussenschutt wrote:
> Well, for the moment, I'm doing OK, so we'll use the "suck-it-and-see"
> approach...if it's too slow, I'll re-engineer some of the communications.
> I must say that adding a local "daemon" (even if just to keep the sockets
> open the whole time) seems to me like a reasonably simple thing to do...I
> just relocate the functionality from my cgi into a daemon, wrap it into a
> while (1) loop, and wait for requests..... Hmmm I think I may consider
> this further...... but isn't that sort-of what mod_perl is supposed to
> allow me to do? anyway.... I wonder.....   does anyone out there use
> mod_perl , and can give me some tips etc. (I think I need to read some
> more man pages too!)
>
> David.
> --------------------------------------------------------------------
> David Bussenschutt        Email: D.Bussenschutt at mailbox.gu.edu.au
> Senior Computing Support Officer & Systems Administrator/Programmer
> RedHat Certified Engineer.
> Member of Systems Administrators Guild of Australia.
> Location: Griffith University. Information Technology Services
>            Brisbane Qld. Aust.  (TEN bldg. rm 1.33) Ph: (07)38757079
> --------------------------------------------------------------------
>
>
>
>
> Don.Simonetta at mincom.com
> 26/09/2002 02:44 PM
>
>
>         To:     derek at wedgetail.com, d.bussenschutt at mailbox.gu.edu.au
>         cc:
>         Subject:        RE: [BNE-PM] cgi architecture
>
>
> Sorry for the late response on this one - I somehow missed it when it
> arrived.
>
> Just wanted to add that we have a situation where we use a similar
> architecture to that described by Derek below - only for completely
> different reasons. In our case its so that Internet access can run a
> process behind our firewall (to access an internal database via intranet
> CGI).
>
>
> -----Original Message-----
> From: owner-brisbane-pm-list at pm.org
> [mailto:owner-brisbane-pm-list at pm.org] On Behalf Of derek at wedgetail.com
> Sent: Friday, 20 September 2002 16:20
> To: d.bussenschutt at mailbox.gu.edu.au
> Cc: brisbane-pm-list at happyfunball.pm.org
> Subject: Re: [BNE-PM] The Perl one-liner
>
> David Bussenschutt wrote:
>  > I expect that I will eventually run in
>
>>mod_perl, but I haven't needed that yet (or figured it out either)
>
> ;-)
>
>
> I think you're going to have to look at mod_perl before too long. I've
> never done any CGI/Web app stuff whatsoever, so I can't really say how
> easy that will be.
>
> Another approach would be to get all that work out of the CGI program,
> and into a server that sits on your machine permanently, and does all
> the "grunt work".
>
> So, your setup looks like this (set your fonts to "fixed width"!):
>
> +----------+                             +--------------+
> | CGI      |  CORBA/SOAP/adhoc protocol  |  Perl server |
> | "script" |---------------------------->|  process     |
> +----------+                             +--------------+
>
> So, your CGI script just connects to the server, passing the arguments,
> like say a cookie and some form fields, and gets back shiny new HTML to
> display. The server never dies, so not only is it "warmed up", but it
> can also cache database connections, keep those 6-12 sockets open for
> reuse, cache data from other sources, and so on ad infinitum. You can
> also move the server to a different, more powerful machine, or even
> replicate it across many machines!
>
> You can use any protocol you like, ranging from standard, like CORBA or
> SOAP (which has the advantage that you can switch the server to
> Java/Python/C++/C at will without writing a bunch of code), or just make
>
> up your own little ASCII protocol and use that.
>
> Anyway, even if you do use mod_perl, I think this design still has many
> benefits.
>
> --
> D.
>
>
>


--
Managing Director
e-JAZ Pty Ltd
JAZConvert Currency Conversion
Ph:  +61 7 3201 0146
http://jazconvert.com
andrew at e-jaz.com.au


Search66 ~ Find it first time - every time!
http://Search66.com


"The only impossibility is that of believing there is none."






More information about the Brisbane-pm mailing list