in reply to Mod_Perl and Autoloader - anything special I should know?

Correct me if I'm wrong, but the purpose of those modules is to avoid compiling functions that aren't used. That's made moot by mod_perl, where the modules are just loaded once.
  • Comment on Re: Mod_Perl and Autoloader - anything special I should know?

Replies are listed 'Best First'.
Re^2: Mod_Perl and Autoloader - anything special I should know?
by MashMashy (Sexton) on Apr 19, 2009 at 05:30 UTC
    But, lets say I have 100 functions in a common functions file. doesn't it 'load each one one' for EACH mod_perl 'preloaded .pl'?

    example:
    Common Function File:
    Fcn A
    Fcn B
    Fcn C


    First .pl File uses A and B.
    Second .pl File uses A and C.
    Third .pl file uses C.


    wouldn't it 'cache' the first file as the first file with all three ABC Fcns (since they are 'required' in), and do the same with the second and the third, so it is as if 9 functions are cached - possibly using up most of the memory (assume the common file has 100's of functions)?

    Thanks again!

      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.