Django内存使用量随着每个请求而上升 [英] Django memory usage going up with every request

查看:310
本文介绍了Django内存使用量随着每个请求而上升的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将我的第一个Django项目从DjangoEurope移动到Webfaction,并且开始出现像内存泄漏一样的问题。随着每一个请求,服务器进程的内存使用量上升了大约500kb。它永远不会下降。直到Webfaction使用太多的内存才能杀死它。



当我在浏览器中刷新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的提示最有帮助,但不幸的是他没有答复(只是评论),所以没有办法接受他的回复。



虽然我还是天堂不完全解决这个问题,下面是其他有类似问题的基本技巧:




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 to False
  • 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:

这篇关于Django内存使用量随着每个请求而上升的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆