You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Daniel B. Hemmerich" <da...@webclients.net> on 2006/08/29 02:26:16 UTC

Best Practices Question

What is a better route to go?

 

1.	Have a handler in Apache call a package directly using a handler() -
having the module itself parse out arguments passed in and loading
configuration files based on argument values.
2.	Build a script in /cgi-bin/ that uses mod_perl2, parses passed in
arguments, loads configuration files, and then creates a new instance of the
module mentioned in option 1, and then calls a "run()" in the module that
performs all the real work.

 

Is using new() under mod_perl2 inefficient at all that it would be best to
not use it when not necessary?

 

Thanks!

 


RE: Best Practices Question

Posted by "Daniel B. Hemmerich" <da...@webclients.net>.
Thanks Michael for your time!

I am currently using just CGI which as I have found out is loaded with a lot
more than I need.

Our application services over 250,000 unique users a day - so efficiency is
definitely what I have in mind. We've thrown hardware at it so far, but it
is time for us to improve our application.

Is there a good cookbook url for mod_perl2? We have found some routines
helpful, such as reread():

use vars qw(%MODIFIED);

sub reread_file {
    my $file = shift;

    return unless $file;
    return unless -e $file and -r _;

    unless ( $MODIFIED{$file} and $MODIFIED{$file} == -M _ ) {
        my $return;

        unless ( $return = do $file ) {
            warn "couldn't parse $file: $@" if $@;
            warn "couldn't do $file: $!" unless defined $return;
            warn "couldn't run $file"    unless $return;
        }

        $MODIFIED{$file} = -M _;    # Update the MODIFICATION times
    }
}

-----Original Message-----
From: Michael Peters [mailto:mpeters@plusthree.com] 
Sent: Tuesday, August 29, 2006 12:39 PM
To: daniel@webclients.net
Cc: modperl@perl.apache.org
Subject: Re: Best Practices Question



Daniel B. Hemmerich wrote:
> What is a better route to go?
> 
>  
> 
>    1. Have a handler in Apache call a package directly using a handler()
>       - having the module itself parse out arguments passed in and
>       loading configuration files based on argument values.
>    2. Build a script in /cgi-bin/ that uses mod_perl2, parses passed in
>       arguments, loads configuration files, and then creates a new
>       instance of the module mentioned in option 1, and then calls a
>       "run()" in the module that performs all the real work.

Either way works fine. Using a script uses a little more overhead since it
uses
Apache::Registry (or Apache::PerlRun), but if your script is small then the
difference is almost non-existent. You should pick the approach based on
structure since speed/efficiency is not really an issue.

> Is using new() under mod_perl2 inefficient at all that it would be best
> to not use it when not necessary?

new() in Perl is just a method. It's no more or less efficient than any
other
method. In general, using OO programming is less efficient than straight
procedural as far as speed and memory go. People write OO code not for it's
efficiency, but for the organizational benefits for the developers.

I know run() and new() are pretty generic names, but out of curiosity, are
you
using CGI::Application?

-- 
Michael Peters
Developer
Plus Three, LP


Re: Best Practices Question

Posted by Michael Peters <mp...@plusthree.com>.

Daniel B. Hemmerich wrote:
> What is a better route to go?
> 
>  
> 
>    1. Have a handler in Apache call a package directly using a handler()
>       – having the module itself parse out arguments passed in and
>       loading configuration files based on argument values.
>    2. Build a script in /cgi-bin/ that uses mod_perl2, parses passed in
>       arguments, loads configuration files, and then creates a new
>       instance of the module mentioned in option 1, and then calls a
>       “run()” in the module that performs all the real work.

Either way works fine. Using a script uses a little more overhead since it uses
Apache::Registry (or Apache::PerlRun), but if your script is small then the
difference is almost non-existent. You should pick the approach based on
structure since speed/efficiency is not really an issue.

> Is using new() under mod_perl2 inefficient at all that it would be best
> to not use it when not necessary?

new() in Perl is just a method. It's no more or less efficient than any other
method. In general, using OO programming is less efficient than straight
procedural as far as speed and memory go. People write OO code not for it's
efficiency, but for the organizational benefits for the developers.

I know run() and new() are pretty generic names, but out of curiosity, are you
using CGI::Application?

-- 
Michael Peters
Developer
Plus Three, LP