django mod_wsgi 内存问题

django mod_wsgi 内存问题

我的 django 应用程序位于 VPS 服务器(128mb 内存)上。当我使用 python manage.py runserver 启动它时,它运行良好,但如果我尝试通过 apache/mod_wsgi 使用它,它很快就会导致速度严重减慢(在我点击网页上的几个随机链接后),并且似乎内存耗尽。这甚至发生在“hello world”应用程序中。但这有点奇怪,因为它使用 manage.py runserver 运行良好,有什么想法吗?

/var/log/apache2/error.log
-----------------------------
[Wed Feb 10 00:00:40 2010] [error] [client 65.55.37.202] File does not exist: /var/www/robots.txt
[Wed Feb 10 00:01:22 2010] [error] [client 65.55.37.202] File does not exist: /var/www/file
[Wed Feb 10 00:02:32 2010] [warn] child process 2023 still did not exit, sending a SIGTERM
[Wed Feb 10 00:02:32 2010] [warn] child process 1961 still did not exit, sending a SIGTERM
[Wed Feb 10 00:02:32 2010] [warn] child process 1994 still did not exit, sending a SIGTERM
[Wed Feb 10 00:02:32 2010] [warn] child process 1995 still did not exit, sending a SIGTERM
[Wed Feb 10 00:02:32 2010] [warn] child process 1996 still did not exit, sending a SIGTERM
[Wed Feb 10 00:02:33 2010] [warn] child process 2023 still did not exit, sending a SIGTERM
[Wed Feb 10 00:02:33 2010] [warn] child process 1961 still did not exit, sending a SIGTERM
[Wed Feb 10 00:02:33 2010] [warn] child process 1994 still did not exit, sending a SIGTERM
[Wed Feb 10 00:02:33 2010] [warn] child process 1995 still did not exit, sending a SIGTERM
[Wed Feb 10 00:02:33 2010] [warn] child process 1996 still did not exit, sending a SIGTERM
[Wed Feb 10 00:02:34 2010] [notice] caught SIGTERM, shutting down
[Wed Feb 10 00:15:31 2010] [notice] mod_python: Creating 8 session mutexes based on 150 max processes and 0 max threads.
[Wed Feb 10 00:15:31 2010] [notice] mod_python: using mutex_directory /tmp 
[Wed Feb 10 00:15:32 2010] [notice] Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4 with Suhosin-Patch mod_python/3.3.1 Python/2.5.2 mod_wsgi/2.3 configured -- resuming normal operations
[Wed Feb 10 00:17:24 2010] [error] [client 202.152.243.143] File does not exist: /var/www/file, referer: http://www.webmaster-tutorial.com/view/919
[Wed Feb 10 00:19:56 2010] [error] [client 202.152.243.143] File does not exist: /var/www/favicon.ico
[Wed Feb 10 00:20:09 2010] [error] [client 202.152.243.143] File does not exist: /var/www/favicon.ico
[Wed Feb 10 00:23:25 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 10 00:23:41 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 10 00:23:52 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 10 00:24:03 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 10 00:24:16 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 10 00:24:29 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 10 00:24:39 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 10 00:24:51 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 10 00:25:01 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 10 00:25:11 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 10 00:25:21 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 10 00:25:31 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 10 00:25:41 2010] [error] (12)Cannot allocate memory: fork: Unable to fork new process
----------------------------------

答案1

确保您没有使用嵌入模式。请改用守护进程模式。请参阅:

http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usage.html

解释为什么嵌入模式不适合受限内存环境。

顺便说一句,也放弃 mod_python 并使用更新的 mod_wsgi,特别是 mod_wsgi 3.X 并设置:

WSGIRestrictEmbedded On

除了使用守护进程模式来节省更多的内存。

相关内容