Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Fastcgi and persistence in sub modules

by Anonymous Monk
on Nov 28, 2012 at 14:34 UTC ( #1006040=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

In the context of web scripting, say I've a main fastcgi-enabled script that imports Module A (before the "while" loop). Module A in turn imports Module B and Module C.

Since Module A is loaded before the "while" loop in the main script, it's saved in memory. But what about Module B and Module C? Do these also become persistent as a result of loading Module A at the start of the script?

If not, is it a good practice to load them in the main script at the same time Module A is loaded i.e. before the "while" loop?

Looking forward to your replies and many thanks in anticipation.

Comment on Fastcgi and persistence in sub modules
Re: Fastcgi and persistence in sub modules
by MidLifeXis (Prior) on Nov 28, 2012 at 15:17 UTC

    IMO, if your script only depends on the functionality provided by module A, then only load module A. If your script peeks behind the covers of Module A and loads Module B and Module C from within the script, you have now made your script dependent on modules A, B, and C, and not just A. If you change the implementation of module A to use modules D and E instead, you now have to maintain the script as well.

    Only load what you explicitly depend on.

    From a persistence standpoint, fastcgi will have the dependencies also loaded.

    --MidLifeXis

Re: Fastcgi and persistence in sub modules
by zwon (Monsignor) on Nov 28, 2012 at 15:29 UTC
    If you have package A that looks like:
    package A; use B; use C; ...
    and the script
    use A; while(1) {...}
    Then modules A, B, and C will be loaded during script compilation time. Even if you place use A inside the while loop or after it (see use). If it is a good practice or not depends on your particular conditions. If you have pre-forking server running on some sort of Unix it is advisable to preload modules as it will reduce total memory usage due to COW.

      Exactly as you have shown. Thank you so much.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1006040]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2014-10-21 05:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (96 votes), past polls