Django内存使用量随着每个请求而上升 [英] Django memory usage going up with every request
问题描述
当我在浏览器中刷新Django的管理界面时,我可以清楚地看到这一点(尽管这与每一个页面,不仅与管理界面 - 我虽然管理界面将是一个很好的测试用例,因为没有我的代码直接在那里)。使用每个浏览器重新加载内存使用率上升几千字节。
我使用Webfaction建议的命令来测试内存:
ps -u publica -o rss,etime,pid,命令
更多关于我的设置
- Django 1.1(stable)
- 默认Webfaction使用Apache和mod_wsgi的Django设置
-
DEBUG
设置为False
- 来自Webfaction的MySQLdb 1.2.2,但听到有一些问题后,我尝试了1.2.3c版本。没有帮助。
编辑:我创建了一个空的Django项目 - 默认的Django配置加code> django.contrib.admin 和新鲜的空数据库(同时使用mysql和postgresql)。我开始在浏览器中重新加载Django管理员,并观看了内存使用情况。起初我看到问题发生 - 每次重新加载后内存使用量增长。但是,它稳定下来并停止增长。这与我的原始项目在Django Europe上的表现一致。不幸的是,Webfaction从来没有似乎稳定(或至少不在我的帐户内存限制之内)。任何建议?
我恐怕没有确定的答案。 Graham Dumpleton的提示最有帮助,但不幸的是他没有答复(只是评论),所以没有办法接受他的回复。
虽然我还是天堂不完全解决这个问题,下面是其他有类似问题的基本技巧:
- 阅读Webfaction的文档:
- 确保
DEBUG
设置设置为False
- 不要使用
mod_pyt hon
,使用mod_wsgi
- 确保使用最新版本od
mod_wsgi
(Webfaction倾向于安装旧版本) - 不要使用Django来提供静态内容
- 尝试运行
mod_wsgi
在守护进程模式下(Webfaction默认情况下会以嵌入式模式安装)[谢谢Graham Dumpleton的提示] - 如果您以嵌入模式运行,可以指定inactiveivity-timeout = [seconds ] 选项。它会在不活动的[秒]之后重新启动该过程,有助于增加内存使用。 阅读此论坛帖子以获取详细说明。
- 此脚本将帮助您更轻松地监控内存使用情况,更确切地说[感谢ClaudioA的提示]
I moved my first Django project from DjangoEurope to Webfaction, and that started an issue looking like a memory leak. With every single request memory usage of the server process goes up about 500kb. It never goes down. This goes on until Webfaction kills it for using too much memory.
I can clearly see this when I refresh the Django's admin interface in my browser (although this happens with every single page, not only with admin interface - I though admin interface would be a nice test case, because there is no my code directly there). With every browser reload the memory usage goes up couple hundreds kilobytes.
I test the memory using a command suggested by Webfaction:
ps -u publica -o rss,etime,pid,command
More about my setup:
- Django 1.1 (stable)
- Default Webfaction Django setup using Apache and mod_wsgi
DEBUG
set toFalse
- MySQLdb 1.2.2 from Webfaction, but after hearing it had some problems I tried version 1.2.3c. Didn't help.
Edit: I created an empty Django project - default Django configuration plus django.contrib.admin
and fresh empty database (tried both with mysql and postgresql). I started reloading Django admin in my browser and watched memory usage. At first I saw the problem occurring - memory usage grew after every reload. But then it stabilized and stopped growing. That's consistant with how my original project behaved on Django Europe. Unfortunately on Webfaction it never seems to stabilize (or at least not within limits of memory available to my account). Any advice?
I'm afraid I haven't got any definite answers. Graham Dumpleton's tips were most helpfull, but unfortunately he didn't make an answer (just comments), so there is no way to accept his response.
Although I still haven't fully resolved the issue, here are some basic tips for other people having similar problems:
- Read Webfaction's documentation:
- Make sure the
DEBUG
setting is set toFalse
- Don't use
mod_python
, usemod_wsgi
- Make sure you use the most recent version od
mod_wsgi
(Webfaction tends to install older versions) - Don't use Django to serve static content
- Try running
mod_wsgi
in a daemon mode (Webfaction installs it in embedded mode by default) [thanks Graham Dumpleton for the tip] - If you run in embeded mode, you can specify "inactivity-timeout=[seconds]" option. It will restart the process after [seconds] of inactivity, helping with increased memory usage. Read this forum post for detailed instructions.
- This script will help you monitor your memory usage easier, and more precisely [thanks ClaudioA for the tip]
这篇关于Django内存使用量随着每个请求而上升的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!