Once Django application starts to be accessed, it is normal for
process memory footprint to go up. This is because with Python web
applications any Python modules, application code and application data
are cached in memory between requests. This is in contrast to PHP
which tries to throw away everything between requests. How much memory
is used depends on complexity of the application.
> My virtual host setup is below.
>
> KeepAlive Off
>
> <VirtualHost *>
>
> ServerName www.findatenant.com
> ServerAlias *findatenant.com
>
> WSGIDaemonProcess findatenant user=bob group=bob processes=1
> threads=10 maximum-requests=100
> WSGIProcessGroup findatenant
>
> WSGIScriptAlias / /home/bob/findatenant.com/findatenantfast.wsgi
>
> </VirtualHost>
>
> If I try to add the inactivity-timeout argument to the daemonprocess,
> apache tells me "Invalid option to WSGI daemon process definition"
> upon startup.
Then you aren't using mod_wsgi 2.X, but must be using older mod_wsgi
1.X. Ensure you are using latest mod_wsgi 2.3.
> I guess I have a few questions here.
>
> 1. Why does it not free up the memory?
>
> 2. What am I doing wrong that my daemon process line cannot look like
> this?
> WSGIDaemonProcess findatenant user=bob group=bob processes=1
> threads=10 maximum-requests=100 inactivity-timeout=300
These answered above.
> 3. If the inactivity-timeout did work for me or it reached the 100
> maximum requests and a user is logged in, do they loose their session?
Most Python web applications store session information in a separate
database, not in memory. This is actually necessary to support
multiprocess web servers. So, no they shouldn't loose their active
session in this situation.
Graham
If running WSGI application in daemon mode, this option has no effect
on WSGI application. This is because it only affects normal Apache
worker processes which are serving static files and proxying requests
to WSGI application in daemon process.
> ServerLimit 2
This limits number of Apache worker processes serving static files or
proxying requests through to WSGI application in daemon process. For
Apache worker MPM with default 25 threads per worker process, a server
limit of 2 may be reasonable for small to medium size sites or on a
memory constrained VPS.
Graham
If you have a site which will be infrequently accessed, then using
inactivity-timeout will help in dropping memory usage back down when
application not being used.
The maximum-request option will help where you have a problem with
memory usage increasing for some reason, or if for some reason you had
to run Django with Debug enable for some reason. Will make sure that
your process doesn't keep growing and growing in size.
So yes, both a good idea if you are concerned about keeping memory
usage in check.
Graham
What you have is one Apache parent process. This is effectively the
process monitor for Apache and is what spawns of Apache child worker
process. The mod_wsgi code in the Apache parent is also responsible
for spawning off the mod_wsgi daemon process. You would then have 2
Apache child worker processes with ServerLimit of 2 and with that
number of processes being started initially as well. Finally you have
the mod_wsgi daemon process. Under 'top' or 'ps', the mod_wsgi daemon
process will still show as a apache/httpd process. If you use the
display-name option (mod_wsgi 2.X) with WSGIDaemonProcess, you can
override what the name of the mod_wsgi daemon process appears as when
using the 'ps' command (but not 'top').
As to whether 2 Apache worker processes is sufficient as you add
sites. If they are running default 25 threads per process, that is 50
concurrent requests you can handle. You configuration for mod_wsgi
daemon has 10 threads, so 10 concurrent requests. Thus, as is those 2
Apache worker processes are more than sufficient in the sense that it
has more capacity than the daemon process does. Must remember though
that the Apache worker processes also handle static requests as well
though.
As you add more sites or sites become more used, you just need to keep
an eye on the amount of traffic they receive and how many concurrent
requests they receive. It is that that will dictate whether you need
to add more Apache worker processes, or start running with multiple
processes in a daemon process guide.
Overall, if you aren't expecting to handle more than 5-10 concurrent
requests for each application at the same time, what you have would be
okay, just scale things up if traffic requirements become more than
that.
Graham