$ 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.
|