I am managing a Django site on Apache, and am going through very slow intial page loads over time of lack of exercise (about one hour). I'm able to replicate by departing to have an hour, or bouncing the server. Following the initial load, pages load consistently in < 1 sec.

I am presuming (speculating) the problem may be the Python interpreter + Python modules are now being loaded into memory again after these periods of lack of exercise?

I have adopted http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usage.html and am running mod_wsgi in daemon mode.

Server config:

Timeout 20
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 15
ServerLimit 10

<IfModule mpm_prefork_module>
    StartServers          2
    MinSpareServers       2
    MaxSpareServers       2
    MaxClients            4
    MaxRequestsPerChild   0


WSGIDaemonProcess django display-name=%{GROUP}
WSGIScriptAlias / /path/to/osqa.wsgi process-group=django application-group=%{GLOBAL}

Is one thing clearly wrong using the config above, or it is possible to method to keep your Python interpreter in memory?

Possibly mtss is a different problem altogether?


A couple of ideas:

  • Make certain you've enough memory which there's some free along with a healthy disk cache available. You ought to have a minimum of 1gb to 4+gb total based on your work. Top was pointed out, and that i recommend htop: http://htop.sourceforge.internet/
  • Increase disk caching, if for instance, you're utilizing an IO poor VM for example EC2/EBS.
  • Tune your db to appropriate values in relation to memory.
  • If caching check timeouts as pointed out above. If nobody going to within the hour caches will expire.
  • Configure Linux (?) to swap less strongly:
    • echo 20 > /proc/sys/vm/swappiness
    • Permanently: add vm.swappiness in /etc/sysctl.conf