in reply to modularization, memory usage and performance
Not being an expert, I'd like to kick off this segment of our CGI-mangling program with one observation. Some people may disagree with my use of require. That's fine - we can just agree to disagree about that.
However, I would like you to be aware of both sides of the coin as it's not clear to me that you should be using require in these circumstances. Specifically, it sounds like you're switching to something similar to mod_perl. If that is the case, require is actually the wrong thing to use. It is actually better to use "use My::Module qw()" than "require My::Module". This will cause My::Module to be loaded and compiled with the starting of the webserver, rather than in each child process that the server kicks off via fork().
However, if you want your scripts to work both with mod_perl and regular CGI, you may have some trade-offs to make. Since not every CGI call may need all of your modules, using require makes sense - you only load/compile them if you need them. At hundreds or thousands of requests per minute (or second!), this can be significant.
Make your choice wisely - each choice affects the other's performance negatively. A possible third choice is to filter your code during the build, and have your Makefile.PL or Build.PL take a parameter that says whether to build for mod_perl or mod_cgi. With mod_perl, you would just filter all of your code as it is being copied to blib with something like s/require/use/ - of course, you'll want a bit more smarts than that (since that will kill something in quotes - comments don't matter much). Maybe you have a keyword __REQUIRE which gets filtered to require for mod_cgi, and use for mod_perl.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: modularization, memory usage and performance
by jmagiera (Novice) on Feb 09, 2005 at 01:14 UTC | |
by Tanktalus (Canon) on Feb 09, 2005 at 01:31 UTC | |
by jmagiera (Novice) on Feb 09, 2005 at 02:39 UTC | |
by tye (Sage) on Feb 09, 2005 at 03:35 UTC | |
by jmagiera (Novice) on Feb 09, 2005 at 08:03 UTC |