[mod_python] Fw: slow child init problems

Gregory (Grisha) Trubetskoy grisha at modpython.org
Mon Jul 29 21:36:14 EST 2002


On Mon, 29 Jul 2002, Jack Diederich wrote:

> The problem seems to be that the imports, even with the PythonImport
> directive listing all of them aren't done until ChildInitHanlder(),
> which is called the first time a child process gets its first hit,
> apparently.  I say apparently because the difference between using
> PythonImport or not is zero time-wise.

[snip]

> Why can't the work (whatever it is) be done _before_ the fork of the
> children?

[snip]

First, you should look at making sure that everything runs under one
sub-interpreter. The information such as the name of the virtual host is
undefined until the actual request comes in, so PythonImport imports
everything under the interpreter named after the directory in the
surrounding <Directory> tag or the main interpreter. Your other code
probably runs in the subinterpreter for that virtual server, so it ends up
reimporting everything again. You can force everything to run under the
main interpreter by specifying "PythonInterpreter main_interpreter".

It's possible that you're right that ChildInit gets executed on the first
hit, I can't answer this off the top of my head without digging in apache
source code or experimenting. The reason PythonImport stuff does not get
executed at Apache startup before it forks is because at that point Apache
is run as root.

IMHO PythonImport is bad and shouldn't be there. I understand the issue,
but PythonImport isn't the cleanest solution to it because of the way it
ends up having be implemented, and I can't think of anything clever that
would address this.

One simple hack to tackle this problem is to add something into your
Apache startup script that initiates the first hit using wget or fetch or
lynx or whatever. I've used this technique very successfuly before.

Grisha




More information about the Mod_python mailing list