9

I have Apache with 2 virtual hosts, each having a Django site attached using mod_wsgi, daemon mode, like this:

<VirtualHost 123.123.123.123:80>
    WSGIDaemonProcess a.com user=x group=x processes=5 threads=1
    WSGIProcessGroup a.com
    WSGIApplicationGroup %{GLOBAL}
</VirtualHost>

<VirtualHost 123.123.123.123:80>
    WSGIDaemonProcess b.com user=x group=x processes=5 threads=1
    WSGIProcessGroup b.com
    WSGIApplicationGroup %{GLOBAL}
</VirtualHost>

I use WSGIApplicationGroup %{GLOBAL} because of a known problem with Xapian.

Now, if I understand what's going on behind the scenes, mod_wsgi launches 5 daemon processes for each of my sites. I can see this in Apache log:

[info] mod_wsgi (pid=8106): Attach interpreter ''.
[info] mod_wsgi (pid=8106): Adding '.../lib/python2.5/site-packages' to path.
[info] mod_wsgi (pid=8106): Enable monitor thread in process 'a.com'.
[info] mod_wsgi (pid=8106): Enable deadlock thread in process 'a.com'.

[info] mod_wsgi (pid=8107): Attach interpreter ''.
[info] mod_wsgi (pid=8107): Adding '.../lib/python2.5/site-packages' to path.
[info] mod_wsgi (pid=8107): Enable monitor thread in process 'a.com'.
[info] mod_wsgi (pid=8107): Enable deadlock thread in process 'a.com'.

...

What I don't understand is if those "Attach interpreter ''" lines indicate that all of those processes share the same Python interpreter, or if there is one interpreter per process. (BTW I realize that the empty interpreter name '' is caused by passing %{GLOBAL} to WSGIApplicationGroup).

I tried checking if maybe sys.path entries cumulated in subsequent processes, but they didn't - which could indicate that there's a separate Python interpreter for each of the 5 daemon processes... but I don't quite understand all these things so I'm asking here.

Tomasz Zieliński
  • 16,136
  • 7
  • 59
  • 83

1 Answers1

7

The 'pid' value is different. They are in different processes.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • In such case does WSGIApplicationGroup influence anything in daemon mode? – Tomasz Zieliński Feb 17 '11 at 00:21
  • In each process of a daemon process group, there is an interpreter of the same name. The %{GLOBAL} one is the main interpreter, just like if run on the command line, which means in effect you can ignore the whole concept of sub interpreters and just see it as a multi process application where requests are doled out across all processes. – Graham Dumpleton Feb 17 '11 at 01:31
  • My head is too small for this so let me ask for clarification - for 5 processes in daemon process group, there are 5 %{GLOBAL} (i.e. main) interpreters, one for each process ? If I'm right, then what would be the effect of: `WSGIApplicationGroup MyOwnInterpreter` - there would be two interpreters per process, %{GLOBAL} and MyOwnInterpreter, or still only one but with a name instead of ''? – Tomasz Zieliński Feb 17 '11 at 18:58
  • 2
    There would be two, because the main interpreter, ie., %{GLOBAL}, is created as a side effect of initialising Python itself within that process. Ie., it always exists. So, if using daemon mode and only have one application, forcing use of main interpreter actually also saves on a little bit of memory as you don't have the overhead from creating an extra sub interpreter within the process. – Graham Dumpleton Feb 17 '11 at 22:27
  • Ah, now I think I understand it - WSGIApplicationGroup allows multiple wsgi applications to use the same daemon process group, still being isolated (well, almost isolated: http://stackoverflow.com/questions/755070/what-is-the-purpose-of-the-sub-interpreter-api-in-cpython) from each other by using separate Python sub-interpreters within daemon processes. It also allows to map multiple applications to one shared interpreter, if someone need this. And for users of Xapian and other libraries with similar issue, it allows to use the main Python interpreter. Great, thank you for patience! – Tomasz Zieliński Feb 17 '11 at 23:34
  • Yep, you understand it all quite well now. – Graham Dumpleton Feb 18 '11 at 02:34
  • How do I know if it is using my virtual environment interpreter if it has the ' ' in the log? – johnny Apr 15 '15 at 16:06
  • Depends on what mechanism you are using to tell mod_wsgi about the virtual environment. Start a new question properly explaining what your problem is rather than trying to tag on to an existing one. – Graham Dumpleton Apr 15 '15 at 23:24