[mod_python] mpm-worker and mod_python

Graham Dumpleton graham.dumpleton at gmail.com
Sun Apr 8 22:40:34 EDT 2007


On 09/04/07, Andres Morey <amorey at octopart.com> wrote:
> Hi Graham,
>
> Thanks for your reply. I looked into it again and mod_python is
> actually caching modules with prefork. Page load times were taking a
> while and originally it looked like it was a module caching problem.
> Part of the problem is that apache was running 6 processes so it was
> difficult to determine when slow load times were caused by mod_python
> importing modules on a new process or other problems in the code.
>
> I've narrowed down the trouble spots that are unrelated to mod_python
> but I still have one question about caching. Does mod_python reimport
> modules when it encounters modules of the same name in different
> directories? I have index.py as the name for handlers in different
> directories and I'm wondering if mod_python is reimporting them every
> time it encounters one.

Prior to mod_python 3.2.8 it had that problem for any handler modules
or modules imported using apache.import_module(). In mod_python 3.2.X
it only had the problem for handler modules and mod_python.publisher
worked okay. In mod_python 3.3.1 it shouldn't be a problem at all as
modules imported by mod_python module loader are distinguished by full
path. For more details see import_module() documentation in:

  http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html

and also read:

  http://www.dscpl.com.au/wiki/ModPython/Articles/ModuleImportingIsBroken

Note, make sure you are not setting PythonPath to contain locations in
document tree if using mod_python 3.3.1. Documentation above should
from memory explain why not.

> Finally, is there a way to force mod_python to cache modules before a
> request is made to apache?

Use the PythonImport directive:

  http://www.modpython.org/live/current/doc-html/dir-other-pimp.html

Graham

> On Apr 8, 2007, at 6:44 PM, Graham Dumpleton wrote:
>
> > On 08/04/07, Andres Morey <amorey at octopart.com> wrote:
> >> Hi,
> >>
> >> I had mod_python 3.3.1 running on Apache 2.2.4 with mpm-prefork (on
> >> Ubuntu 6.10 x86_64). mod_python wasn't caching modules so I
> >> recompiled apache with mpm-worker instead.
> >
> > mod_python should be caching modules with prefork. On what basis do
> > you believe it isn't? Are you possibly not reading the Apache error
> > log messages properly where it clearly gives the process ID for which
> > process is currently loading mod_python modules. For prefork there can
> > be many Apache child processes so you will see for each distinct
> > module a loading message for each distinct process.
> >
> >> Now mod_python is caching
> >> modules but apache is taking up 100% of system resources.
> >
> > What did you do to trigger the condition? Does it do that as soon as
> > Apache starts, or only after the first request that triggers some
> > mod_python code?
> >
> >> Is it
> >> possible to cache modules with Apache using mpm-prefork?
> >
> > It should work fine now.
> >
> > BTW, what modules are you talking about? Are you talking about modules
> > installed as part of Python, or those in your document tree and
> > containing a handler or which are being loaded by
> > mod_python.publisher?
> >
> > Is your mod_python code otherwise working? There is a rare case where
> > an issue with md5 hash library in PHP may cause a lot of problems with
> > the new module loaded in mod_python 3.3.1.
> >
> > Graham
>
>


More information about the Mod_python mailing list