2008/12/20 Frédéric Sidler <[email protected]>:
> You will find below my WSGI script. But how can I fix the number of
> processes/thread wsgi is handling.
Since you are using daemon mode, using the 'processes' and 'threads'
options to the WSGIDaemonProcess directive.
because you haven't specified them, a single daemon process is used
with a thread pool containing 15 threads.
> As mentionned earlier, when I stress test
> the application, the parser we are using is preloading again and again.
With a singe daemon mode process, even if information is only being
loaded lazily on first request, so long as you haven't set daemon
process to be reloaded somehow, you should only see information loaded
once and not many times.
The only things that could result in it being loaded multiple times are:
1. Where you are doing the loading you haven't thread protected the
initialisation if necessary. Thus, if hitting application with
multiple requests straight after process starts, each thread may be
initialising same data. If all the reloading occurs in a batch at
startup, it could be this. If reloading keeps going on and on, then
something else.
2. You are initialising data and storing it in thread local data
objects. This would see it being loaded by each thread, but worse is
that because of how mod_wsgi works, would see it being loaded on ever
request over time. This is because exception for
application-group=%{GLOBAL}, thread local data doesn't persist beyond
life of a request. This is a known issue that needs to be addressed at
some point.
3. The daemon processes are actually crashing at some point, causing a
replacement to be spawned and information reloaded when it starts.
4. You still aren't running your application in daemon mode properly
but embedded mode and you are being caught by fact that Apache can
spawn additional processes to handle request in embedded mode and then
later kill them when no longer required. This would be compounded if
you had set MaxRequestsPerChild for embedded processes.
> This
> is what we would like to preload. And we also would like to avoid new
> processes/thread to start. Is this a wrong approach?
>From where is the information being preloaded? If you are doing it as
a side effect of Django settings module file, then this will not work
as you expect. This is because the Django settings file is lazily
loaded by Django only when first required, which will be when first
request arrives.
To force preloading of stuff in that case, you cannot use late setting
of DJANGO_SETTINGS_MODULE like you are and must do it in the WSGI
script file. You would also need to explicitly import the settings
file yourself to trigger the preloading of the information.
The only thing that is going to be preloaded in the script below is
the Apache Python code modules required to satisfy the import:
from django.core.handlers.wsgi import WSGIHandler
Thus, how from in your Django site code are you triggering the loading
of your information? Is that in global data or thread local data? Are
you thread protecting the initialisation of this data so only one
thread will initialise it?
Graham
> import os, sys
>
> # django site WSGI handler
>
> # project root dir
> project_root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),
> '../../..'))
> project_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),
> '../..'))
> #site_packages_dir = os.path.abspath(os.path.join(project_root_dir,
> 'site-packages'))
>
> os.environ['PYTHON_EGG_CACHE'] = os.path.join(project_root_dir, 'tmp')
>
> # This is because portable WSGI applications should not write to sys.stdout
> or
> # use the 'print' statement without specifying an alternate file object
> # besides sys.stdout as the target.
> sys.stdout = sys.stderr
>
> sys.path.append(project_root_dir)
> sys.path.append(project_dir)
> sys.path.append("%s/_vendors" % project_dir)
> sys.path.append("%s/_lib" % project_dir)
>
> import logging
> from drlog import RequestLogger
> logging.setLoggerClass(RequestLogger)
>
> from django.core.handlers.wsgi import WSGIHandler
>
> _application = WSGIHandler()
>
> def application(environ, start_response):
> os.environ['USER'] = environ['USER']
> os.environ['DJANGO_SETTINGS_MODULE'] = environ['DJANGO_SETTINGS_MODULE']
>
> return _application(environ, start_response)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/modwsgi?hl=en
-~----------~----~----~----~------~----~------~--~---