On Monday, March 21, 2011, Graham Dumpleton <[email protected]> wrote:
> Read:
>
>   http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading
>
> Embedded mode on UNIX is always going to be multiprocess, thus these
> are likely the script being loaded in different processes.
> Specifically, one will be the original page and the other a request
> for static resources via the application or a request for favicon.ico
> by the browser.


Yes I figured that out a couple hours after I wrote to the list.


> Print out the value of os.getpid() so you can see which process.
>
> Further comments below.
>
> On 22 March 2011 01:53, Eric Lemoine <[email protected]> wrote:
>> Hi
>>
>> I'm using mod_wsgi 2.3 in embedded mode with a Pylons app,
>
> Unless you have a good reason to use embedded mode, it is always
> better to use daemon mode.


Yes. See the bottom of this email for the modwsgi config I'm now considering.


>
> You mod_wsgi is also way out of date and has a known issue with
> wsgi.file_wrapper. You should really upgrade.


Ok I'll need to work with my sysadmins on that :-)


>> and
>> observing that mod_wsgi executes my wsgi script twice on the first
>> request.
>>
>> Here's my wsgi script:
>>
>> ---
>> import site
>> import os, sys
>>
>> site.addsitedir('/home/elemoine/.virtualenvs/mf-perf-test/lib/python2.6/site-packages')
>>
>> sys.path.append('/home/elemoine/public_html/mapfish/PerfTestProject')
>> os.environ['PYTHON_EGG_CACHE'] = '/tmp/python-eggs'
>>
>> from paste.script.util.logging_config import fileConfig
>> fileConfig('/home/elemoine/public_html/mapfish/PerfTestProject/development.ini')
>>
>> from paste.deploy import loadapp
>> print 'XXX loadapp XXXX'
>> application = 
>> loadapp('config:/home/elemoine/public_html/mapfish/PerfTestProject/development.ini')
>> ---
>>
>> The first produces this output in the Apache logs:
>>
>> [Mon Mar 21 15:41:12 2011] [error] XXX loadapp XXXX
>> [Mon Mar 21 15:41:13 2011] [error] XXX loadapp XXXX
>>
>>
>> Is it expected? Are there specific conditions that make this happen?
>>
>> Here's my Apache config:
>>
>> ---
>> WSGIScriptReloading Off
>
> If you use daemon mode and leave this directive out, then you get easy
> source code reloading. See:
>
> http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
>
>> WSGIScriptAlias /perftestproject
>> /home/elemoine/public_html/mapfish/PerfTestProject/wsgi
>
> Which indicates at least that not favicon.ico as you would need to be
> mounting at '/' to be that.
>
> BTW, is your WSGI script file really called just 'wsgi'?


Yes, for the purposes of my tests.


>> (I also have WSGIRestrictStdout Off in the global Apache config, for
>> my print statement to work)
>
> If you use mod_wsgi 3.X you do not need to set that directive as
> blocking it is no longer the default.
>
> You still shouldn't be using 'print ...' though and instead should use
> 'print >> sys.stderr, ...'. See:
>
> http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Apache_Error_Log_Files
> http://blog.dscpl.com.au/2009/04/wsgi-and-printing-to-standard-output.html


Nice!


>> Thanks for any insight on this.
>
> Also check the Apache access log as it will show what requests arrive.
> You can also use:
>
> http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Tracking_Request_and_Response
>
> to wrap WSGI application entry point and record what requests are coming in.



Below Is the modwsgi config I'm now considering (untested yet). In my
case I want to have multiple instances of the same WSGI app in the
same virtual host, and I want to isolate these instances as much as
possible.

---
#
# Use mod_wsgi's daemon mode.
# The WSGI app instance is assigned a specific process group.
#
#

# define a process group
WSGIProcessDaemon ${instanceid} processes=1 threads=15

# define the path to the WSGI app
WSGIScriptAlias /${instanceid}/wsgi /path/to/script.wsgi

# assign the WSGI app instance the process group defined above
# we put the WSGI app instance in the global application group so it
is always executed within in the main interpreter
<Location /${instanceid}/wsgi>
    WSGIProcessGroup ${instanceid}
    WSGIApplicationGroup %{GLOBAL}
</Location>
---


I'd be happy to have your opinion on this approach.

Thanks a lot for your support!

-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : [email protected]
http://www.camptocamp.com

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

Reply via email to