Django site very slow to load after restart or period of inactivity
I'm running a Django site on Apache, and am experiencing very slow intial page loads after a period of inactivity (about 1 hour). I can replicate by leaving for an hour, or bouncing the server. After the initial load, pages load consistently in < 1 sec.
I'm assuming (guessing) the issue is the Python interpreter + Python modules are being loaded into memory again after these periods of inactivity?
I've followed 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
MaxKeepAlive开发者_StackOverflow社区Requests 100
KeepAliveTimeout 15
ServerLimit 10
<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 2
MaxSpareServers 2
MaxClients 4
MaxRequestsPerChild 0
</IfModule>
...
WSGIDaemonProcess django display-name=%{GROUP}
WSGIScriptAlias / /path/to/osqa.wsgi process-group=django application-group=%{GLOBAL}
Is something obviously wrong with the config above, or is there a way to keep the Python interpreter in memory?
Perhaps this a different issue altogether?
Thanks
A few ideas:
- Make sure you have enough memory and that there is some free and a healthy disk cache available. You should have at least 1gb to 4+gb total depending on what you are doing. Top was mentioned, and I recommend htop: http://htop.sourceforge.net/
- Increase disk caching, if for example, you are using an IO poor VM such as EC2/EBS.
- Tune your db to appropriate values with regards to memory.
- If caching check timeouts as mentioned above. If no one visiting in the hour caches will expire.
- Configure Linux (?) to swap less aggressively:
- echo 20 > /proc/sys/vm/swappiness
- Permanently: add vm.swappiness in /etc/sysctl.conf
精彩评论