so it is as if 9 functions are cached

Once a process loads a module, it's loaded. Subsequent requests to load it are no-ops. This is the same in mod_perl as outside of mod_perl. There is no cache.

$ cat > Foo.pm package Foo; print("Loading ", __PACKAGE__, "\n"); sleep(3); 1; $ time perl -e'use Foo; use Foo; use Foo;' Loading Foo real 0m3.007s # 3s, not 9s user 0m0.004s sys 0m0.000s

The only difference is that mod_perl uses one process for many requests, and CGI uses a new process for each request.

possibly using up most of the memory

The memory's gonna get used up whether you load all the functions up front or one at a time. Since (practically) all of the functions are going to end up loaded anyway, you're not saving anything by loading them one at a time.


So,

Load the module with your collection of functions in mod_perl's startup script, and it'll be loaded forever more. It won't even need to be reloaded when Apache restarts one of its children.

Even if you don't load the module from mod_perl's startup script, once a child loads the module it will stay loaded. If the child handles 10,000 requests before being restarted, you saved your module from being loaded 9,999 over a CGI script.

Loading the functions one at a time just adds overhead since the functions are going to end up loaded anyway.


In reply to Re^3: Mod_Perl and Autoloader - anything special I should know? by ikegami
in thread Mod_Perl and Autoloader - anything special I should know? by MashMashy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.